Contest Duration: - (local time) (160 minutes) Back to Home

Submission #6493716

Source Code Expand

Copy
```#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
cin.tie(0); ios::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);

int n; long long k; cin >> n >> k;
vector<int> a(n); REP(i, n) cin >> a[i];
map<int, vector<int> > mp;
REP(i, n) mp[a[i]].emplace_back(i);
vector<int> nx(n);
for (auto p : mp) {
vector<int> vec = p.second;
int sz = vec.size();
REP(i, sz - 1) nx[vec[i]] = vec[i + 1];
nx[vec[sz - 1]] = vec[0];
}
long long loop = 1;
int pos = 0;
while (true) {
int nxt = nx[pos];
if (nxt <= pos) {
if (loop == k) break;
++loop;
}
pos = nxt + 1;
if (pos == n) {
pos = -1;
break;
}
}
if (pos == -1) k %= loop;
if (k == 0) return 0;
loop = 1;
pos = 0;
while (true) {
int nxt = nx[pos];
if (nxt <= pos) {
if (loop == k) break;
++loop;
}
pos = nxt + 1;
}
vector<int> ans;
map<int, bool> mp2;
FOR(i, pos, n) {
if (!mp2.count(a[i])) {
mp2[a[i]] = true;
ans.emplace_back(a[i]);
} else {
while (ans.back() != a[i]) {
mp2.erase(ans.back());
ans.pop_back();
}
ans.pop_back();
mp2.erase(a[i]);
}
}
int len = ans.size();
REP(i, len) cout << ans[i] << (i == len - 1 ? '\n' : ' ');
return 0;
}
```

Submission Info

Submission Time 2019-07-21 22:09:37+0900 B - Do Not Duplicate emthrm C++14 (GCC 5.4.1) 700 2162 Byte AC 255 ms 35188 KB

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 1 ms 256 KB
01-02.txt AC 11 ms 1152 KB
01-03.txt AC 12 ms 1280 KB
01-04.txt AC 33 ms 2944 KB
01-05.txt AC 19 ms 2304 KB
01-06.txt AC 60 ms 4992 KB
01-07.txt AC 58 ms 4608 KB
01-08.txt AC 74 ms 9984 KB
01-09.txt AC 97 ms 13952 KB
01-10.txt AC 114 ms 14976 KB
01-11.txt AC 105 ms 17528 KB
01-12.txt AC 50 ms 10112 KB
01-13.txt AC 76 ms 14080 KB
01-14.txt AC 37 ms 7168 KB
01-15.txt AC 65 ms 11392 KB
01-16.txt AC 39 ms 3200 KB
01-17.txt AC 39 ms 3200 KB
01-18.txt AC 39 ms 3200 KB
01-19.txt AC 73 ms 5376 KB
01-20.txt AC 70 ms 5376 KB
01-21.txt AC 82 ms 5376 KB
01-22.txt AC 132 ms 15744 KB
01-23.txt AC 124 ms 15744 KB
01-24.txt AC 134 ms 15744 KB
01-25.txt AC 226 ms 32372 KB
01-26.txt AC 220 ms 31604 KB
01-27.txt AC 189 ms 28920 KB
01-28.txt AC 75 ms 12800 KB
01-29.txt AC 77 ms 12800 KB
01-30.txt AC 255 ms 35188 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB
sample-03.txt AC 1 ms 256 KB
sample-04.txt AC 1 ms 256 KB