Task: | Mex value |
Sender: | egor.lifar |
Submission time: | 2017-01-21 20:32:59 +0200 |
Language: | C++ |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 28 |
#2 | ACCEPTED | 72 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.04 s | 1 | details |
#2 | ACCEPTED | 0.03 s | 1 | details |
#3 | ACCEPTED | 0.04 s | 1 | details |
#4 | ACCEPTED | 0.04 s | 1 | details |
#5 | ACCEPTED | 0.04 s | 1 | details |
#6 | ACCEPTED | 0.04 s | 1 | details |
#7 | ACCEPTED | 0.04 s | 1 | details |
#8 | ACCEPTED | 0.04 s | 1 | details |
#9 | ACCEPTED | 0.05 s | 1 | details |
#10 | ACCEPTED | 0.04 s | 1 | details |
#11 | ACCEPTED | 0.06 s | 2 | details |
#12 | ACCEPTED | 0.07 s | 2 | details |
#13 | ACCEPTED | 0.06 s | 2 | details |
#14 | ACCEPTED | 0.06 s | 2 | details |
#15 | ACCEPTED | 0.08 s | 2 | details |
#16 | ACCEPTED | 0.07 s | 2 | details |
#17 | ACCEPTED | 0.08 s | 2 | details |
#18 | ACCEPTED | 0.08 s | 2 | details |
#19 | ACCEPTED | 0.07 s | 2 | details |
#20 | ACCEPTED | 0.08 s | 2 | details |
Code
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <numeric> #include <cstring> #include <ctime> #include <cstdlib> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <list> #include <cmath> #include <bitset> #include <cassert> #include <queue> #include <stack> #include <deque> #include <cassert> using namespace std; template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } /** Interface */ inline int readChar(); template <class T = int> inline T readInt(); template <class T> inline void writeInt( T x, char end = 0 ); inline void writeChar( int x ); inline void writeWord( const char *s ); /** Read */ static const int buf_size = 4096; inline int getChar() { static char buf[buf_size]; static int len = 0, pos = 0; if (pos == len) pos = 0, len = fread(buf, 1, buf_size, stdin); if (pos == len) return -1; return buf[pos++]; } inline int readChar() { int c = getChar(); while (c <= 32) c = getChar(); return c; } template <class T> inline T readInt() { int s = 1, c = readChar(); T x = 0; if (c == '-') s = -1, c = getChar(); while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getChar(); return s == 1 ? x : -x; } /** Write */ static int write_pos = 0; static char write_buf[buf_size]; inline void writeChar( int x ) { if (write_pos == buf_size) fwrite(write_buf, 1, buf_size, stdout), write_pos = 0; write_buf[write_pos++] = x; } template <class T> inline void writeInt( T x, char end ) { if (x < 0) writeChar('-'), x = -x; char s[24]; int n = 0; while (x || !n) s[n++] = '0' + x % 10, x /= 10; while (n--) writeChar(s[n]); if (end) writeChar(end); } inline void writeWord( const char *s ) { while (*s) writeChar(*s++); } struct Flusher { ~Flusher() { if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0; } } flusher; #define left left228 #define right right228 #define sz(c) (int)(c).size() #define all(c) (c).begin(), (c).end() const int MAXN = 100201; int n, k; int x[MAXN]; int d[4 * MAXN]; void change(int i, int x) { d[i] += x; while (i >> 1 > 0) { i >>= 1; d[i] = min(d[(i << 1) + 1], d[i << 1]); } } int get(int v, int vl, int vr) { if (vl == vr) { return vl - 1; } int vm = (vl + vr) >> 1; if (!d[v << 1]) { return get(v << 1, vl, vm); } return get((v << 1) + 1, vm + 1, vr); } int main() { n = readInt(), k = readInt(); for (int i = 0; i < n; i++) { x[i] = readInt(); } int ss = 1; while (ss <= n + 1) { ss <<= 1; } for (int i = 0; i < k; i++) { if (x[i] <= k) { change(ss + x[i], 1); } } for (int i = k - 1; i < n; i++) { writeInt(get(1, 1, ss), ' '); if (x[i - k + 1] <= k) { change(ss + x[i - k + 1], -1); } if (i < n - 1 && x[i + 1] <= k) { change(ss + x[i + 1], 1); } } writeChar('\n'); return 0; }
Test details
Test 1
Group: 1
Verdict: ACCEPTED
input |
---|
100 10 1000000000 9 1 0 5 7 2 8 6 3 4... |
correct output |
---|
4 10 9 1 1 1 1 1 1 1 1 4 10 3 ... |
user output |
---|
4 10 9 1 1 1 1 1 1 1 1 4 10 3 ... |
Test 2
Group: 1
Verdict: ACCEPTED
input |
---|
100 10 1000000000 4 3 8 1 0 9 5 7 2 6... |
correct output |
---|
6 10 4 3 3 1 1 1 1 1 3 3 10 6 ... |
user output |
---|
6 10 4 3 3 1 1 1 1 1 3 3 10 6 ... |
Test 3
Group: 1
Verdict: ACCEPTED
input |
---|
100 10 1000000000 9 2 3 1 0 8 5 6 4 7... |
correct output |
---|
7 10 9 2 2 1 0 1 1 1 2 9 10 4 ... |
user output |
---|
7 10 9 2 2 1 0 1 1 1 2 9 10 4 ... |
Test 4
Group: 1
Verdict: ACCEPTED
input |
---|
100 10 1000000000 3 0 4 6 5 7 1 2 8 9... |
correct output |
---|
9 10 3 0 0 0 0 0 4 2 2 2 10 6 ... |
user output |
---|
9 10 3 0 0 0 0 0 4 2 2 2 10 6 ... |
Test 5
Group: 1
Verdict: ACCEPTED
input |
---|
100 10 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 ... |
correct output |
---|
10 10 10 10 10 10 10 10 10 10 ... |
user output |
---|
10 10 10 10 10 10 10 10 10 10 ... |
Test 6
Group: 1
Verdict: ACCEPTED
input |
---|
100 10 1000000000 0 5 1 9 3 4 6 7 2 8... |
correct output |
---|
8 10 0 5 1 1 1 1 1 5 2 5 10 0 ... |
user output |
---|
8 10 0 5 1 1 1 1 1 5 2 5 10 0 ... |
Test 7
Group: 1
Verdict: ACCEPTED
input |
---|
100 10 1000000000 1 2 9 3 8 0 4 7 5 6... |
correct output |
---|
6 10 1 1 1 1 2 0 0 2 3 9 10 6 ... |
user output |
---|
6 10 1 1 1 1 2 0 0 2 3 9 10 6 ... |
Test 8
Group: 1
Verdict: ACCEPTED
input |
---|
100 10 1000000000 5 0 6 7 1 4 8 3 9 2... |
correct output |
---|
2 10 5 0 0 0 0 0 0 0 0 1 10 9 ... |
user output |
---|
2 10 5 0 0 0 0 0 0 0 0 1 10 9 ... |
Test 9
Group: 1
Verdict: ACCEPTED
input |
---|
100 10 1000000000 7 3 0 1 4 9 2 5 6 8... |
correct output |
---|
8 10 7 3 0 0 0 0 7 5 5 5 10 8 ... |
user output |
---|
8 10 7 3 0 0 0 0 7 5 5 5 10 8 ... |
Test 10
Group: 1
Verdict: ACCEPTED
input |
---|
100 10 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 ... |
correct output |
---|
10 10 10 10 10 10 10 10 10 10 ... |
user output |
---|
10 10 10 10 10 10 10 10 10 10 ... |
Test 11
Group: 2
Verdict: ACCEPTED
input |
---|
100000 10000 1000000000 4786 3512 3285 1919... |
correct output |
---|
9547 10000 4786 3512 3285 1919... |
user output |
---|
9547 10000 4786 3512 3285 1919... |
Test 12
Group: 2
Verdict: ACCEPTED
input |
---|
100000 10000 1000000000 7981 3955 790 45 34... |
correct output |
---|
7657 10000 7981 3955 790 45 45... |
user output |
---|
7657 10000 7981 3955 790 45 45... |
Test 13
Group: 2
Verdict: ACCEPTED
input |
---|
100000 10000 1000000000 2329 1825 9435 3800... |
correct output |
---|
5701 10000 2329 1825 1825 1825... |
user output |
---|
5701 10000 2329 1825 1825 1825... |
Test 14
Group: 2
Verdict: ACCEPTED
input |
---|
100000 10000 1000000000 2754 6029 8007 6286... |
correct output |
---|
1423 10000 2754 2754 2754 2754... |
user output |
---|
1423 10000 2754 2754 2754 2754... |
Test 15
Group: 2
Verdict: ACCEPTED
input |
---|
100000 10000 0 1 2 3 4 5 6 7 8 9 10 11 12 1... |
correct output |
---|
10000 10000 10000 10000 10000 ... |
user output |
---|
10000 10000 10000 10000 10000 ... |
Test 16
Group: 2
Verdict: ACCEPTED
input |
---|
100000 10000 1000000000 7560 4634 7044 3853... |
correct output |
---|
9855 10000 7560 4634 4634 3853... |
user output |
---|
9855 10000 7560 4634 4634 3853... |
Test 17
Group: 2
Verdict: ACCEPTED
input |
---|
100000 10000 1000000000 7945 6674 3975 3002... |
correct output |
---|
6373 10000 7945 6674 3975 3002... |
user output |
---|
6373 10000 7945 6674 3975 3002... |
Test 18
Group: 2
Verdict: ACCEPTED
input |
---|
100000 10000 1000000000 2506 6827 6871 8593... |
correct output |
---|
2978 10000 2506 2506 2506 2506... |
user output |
---|
2978 10000 2506 2506 2506 2506... |
Test 19
Group: 2
Verdict: ACCEPTED
input |
---|
100000 10000 1000000000 2769 5036 539 4409 ... |
correct output |
---|
2249 10000 2769 2769 539 539 5... |
user output |
---|
2249 10000 2769 2769 539 539 5... |
Test 20
Group: 2
Verdict: ACCEPTED
input |
---|
100000 10000 0 1 2 3 4 5 6 7 8 9 10 11 12 1... |
correct output |
---|
10000 10000 10000 10000 10000 ... |
user output |
---|
10000 10000 10000 10000 10000 ... |