Submission #6490416


Source Code Expand

Copy
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 400400;
int n, m;
int a[N];
int nxt[N];
int lst[N];
int b[N];
int used[N];
bool hv[N];
ll k;

void solveFrom(int v) {
	m = 0;
	for (int i = v; i < n; i++) {
		int x = a[i];
		if (hv[x]) {
			while(b[m - 1] != x) {
				m--;
				hv[b[m]] = 0;
			}
			m--;
			hv[b[m]] = 0;
		} else {
			b[m++] = x;
			hv[x] = 1;
		}
	}
	for (int i = 0; i < m; i++)
		printf("%d ", b[i]);
	printf("\n");
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%lld", &n, &k);
	k--;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		a[n + i] = a[i];
	}
	for (int i = 2 * n - 1; i >= 0; i--) {
		if (i < n) {
			nxt[i] = lst[a[i]] + 1;
		}
		lst[a[i]] = i;
	}
	/*
	for (int i = 0; i < n; i++)
		eprintf("%d ", nxt[i]);
	eprintf("\n");
	*/
	for (int i = 0; i < n; i++)
		used[i] = -1;
	int cur = 0;
	int v = 0;
	while(cur < k && used[v] == -1) {
		used[v] = cur;
		v = nxt[v];
		while (v >= n) {
			v -= n;
			cur++;
		}
	}
	if (cur > k) {
		printf("\n");
		return 0;
	}
	if (cur == k) {
		solveFrom(v);
		return 0;
	}
	ll z = (k - cur) / (cur - used[v]);
	k -= z * (cur - used[v]);
	while(cur < k) {
		used[v] = cur;
		v = nxt[v];
		while (v >= n) {
			v -= n;
			cur++;
		}
	}
	if (cur > k) {
		printf("\n");
		return 0;
	}
	if (cur == k) {
		solveFrom(v);
		return 0;
	}
	throw;
	return 0;
}

Submission Info

Submission Time
Task B - Do Not Duplicate
User Um_nik
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2185 Byte
Status AC
Exec Time 41 ms
Memory 8704 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:73:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%lld", &n, &k);
                         ^
./Main.cpp:76:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
                     ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 4
AC × 34
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
All 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Case Name Status Exec Time Memory
01-01.txt AC 2 ms 6400 KB
01-02.txt AC 7 ms 6528 KB
01-03.txt AC 8 ms 6656 KB
01-04.txt AC 19 ms 7040 KB
01-05.txt AC 6 ms 6528 KB
01-06.txt AC 21 ms 7168 KB
01-07.txt AC 21 ms 7040 KB
01-08.txt AC 14 ms 7040 KB
01-09.txt AC 20 ms 7296 KB
01-10.txt AC 22 ms 7296 KB
01-11.txt AC 20 ms 7552 KB
01-12.txt AC 11 ms 6912 KB
01-13.txt AC 15 ms 7040 KB
01-14.txt AC 13 ms 6912 KB
01-15.txt AC 20 ms 7168 KB
01-16.txt AC 23 ms 7168 KB
01-17.txt AC 21 ms 7168 KB
01-18.txt AC 23 ms 7168 KB
01-19.txt AC 25 ms 7296 KB
01-20.txt AC 24 ms 7296 KB
01-21.txt AC 23 ms 7296 KB
01-22.txt AC 25 ms 7424 KB
01-23.txt AC 26 ms 7424 KB
01-24.txt AC 26 ms 7424 KB
01-25.txt AC 37 ms 8448 KB
01-26.txt AC 37 ms 8320 KB
01-27.txt AC 32 ms 8064 KB
01-28.txt AC 22 ms 7296 KB
01-29.txt AC 21 ms 7296 KB
01-30.txt AC 41 ms 8704 KB
sample-01.txt AC 2 ms 6400 KB
sample-02.txt AC 2 ms 6400 KB
sample-03.txt AC 2 ms 6400 KB
sample-04.txt AC 2 ms 6400 KB