#include<bits/stdc++.h>
using namespace std;
vector<int> haha(200001);
vector<int> p(200001,1e7);
vector<pair<int,int>> idk[200001];
vector<pair<int,int>> bruh[200001];
vector<int> pos(200001);
int n;
int calc(int a, int t) {
int l = 0,r = idk[a].size()-1;
while(l < r) {
int mid = (l+r+1)/2;
if(idk[a][mid].second <= t) {
l = mid;
}
else {
r = mid-1;
}
}
return idk[a][l].first;
}
void upd(int a, int x, int t) {
while(a < 200001) {
idk[a].push_back({idk[a][idk[a].size()-1].first+x,t});
a+=((a)&(-a));
}
}
bool dude(int t) {
int c = 0,sb = 0;
for(int i = 18; i >= 0; i--) {
if(c+(1 << i) <= n && sb+calc(c+(1 << i),t) < n/2) {
c+=(1 << i);
sb+=calc(c,t);
}
}
c++;
int w = n/2-sb;
sb+=bruh[c][bruh[c].size()-1].first;
if(sb == n/2) {
return false;
}
int y = pos[c]+bruh[c][bruh[c].size()-1].first-(sb-n/2);
int z = bruh[c][bruh[c].size()-1].first;
while(true) {
if(p[y] < pos[c]+z) {
bruh[haha[y]].push_back({p[y]-y,t});
upd(haha[y],bruh[haha[y]][bruh[haha[y]].size()-1].first,t);
}
else {
bruh[haha[y]].push_back({pos[c]+z-y,t});
upd(haha[y],bruh[haha[y]][bruh[haha[y]].size()-1].first,t);
break;
}
y = p[y];
}
upd(c,n/2-sb,t);
bruh[c].push_back({w,t});
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int q;
cin >> n >> q;
for(int i = 0; i < 200001; i++) {
idk[i].push_back({0,0});
bruh[i].push_back({0,0});
}
for(int i = 1; i <= n; i++) {
cin >> haha[i];
pos[haha[i]] = i;
}
stack<pair<int,int>> troll;
for(int i = 1; i <= n; i++) {
while(!troll.empty() && haha[i] > troll.top().first) {
p[troll.top().second] = i;
troll.pop();
}
troll.push({haha[i],i});
}
int y = 1,big = haha[1];
for(int i = 2; i <= n/2; i++) {
if(haha[i] > big) {
bruh[haha[y]].push_back({i-y,0});
y = i;
big = haha[i];
}
}
bruh[haha[y]].push_back({n/2-y+1,0});
big = haha[n/2+1],y = n/2+1;
for(int i = n/2+1; i <= n; i++) {
if(haha[i] > big) {
bruh[haha[y]].push_back({i-y,0});
y = i;
big = haha[i];
}
}
bruh[haha[y]].push_back({n-y+1,0});
for(int i = 1; i <= n; i++) {
upd(i,bruh[i][bruh[i].size()-1].first,0);
}
for(int i = 1; i <= n; i++) {
dude(i);
}
for(int i = 0; i < q; i++) {
int t,a;
cin >> t >> a;
if(t == 0) {
cout << haha[a] << "\n";
}
else {
t--;
int c = 0,sb = 0;
for(int j = 18; j >= 0; j--) {
if(c+(1 << j) <= n && sb+calc(c+(1 << j),t) < a) {
c+=(1 << j);
sb+=calc(c,t);
}
}
c++;
cout << haha[pos[c]-1-(sb-a)] << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
435 ms |
29008 KB |
Output is correct |
2 |
Correct |
400 ms |
36176 KB |
Output is correct |
3 |
Correct |
340 ms |
35840 KB |
Output is correct |
4 |
Correct |
300 ms |
34640 KB |
Output is correct |
5 |
Correct |
340 ms |
35920 KB |
Output is correct |
6 |
Correct |
324 ms |
34900 KB |
Output is correct |
7 |
Correct |
349 ms |
35920 KB |
Output is correct |
8 |
Correct |
313 ms |
34900 KB |
Output is correct |
9 |
Correct |
298 ms |
34896 KB |
Output is correct |
10 |
Correct |
307 ms |
35060 KB |
Output is correct |
11 |
Correct |
309 ms |
34968 KB |
Output is correct |
12 |
Correct |
256 ms |
34132 KB |
Output is correct |
13 |
Correct |
299 ms |
34656 KB |
Output is correct |
14 |
Correct |
332 ms |
35408 KB |
Output is correct |
15 |
Correct |
313 ms |
35084 KB |
Output is correct |
16 |
Correct |
20 ms |
24924 KB |
Output is correct |
17 |
Correct |
142 ms |
34100 KB |
Output is correct |
18 |
Correct |
213 ms |
34132 KB |
Output is correct |
19 |
Correct |
18 ms |
24668 KB |
Output is correct |
20 |
Correct |
17 ms |
24668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
993 ms |
94796 KB |
Output is correct |
2 |
Correct |
904 ms |
64688 KB |
Output is correct |
3 |
Correct |
716 ms |
66808 KB |
Output is correct |
4 |
Correct |
625 ms |
59568 KB |
Output is correct |
5 |
Correct |
603 ms |
58632 KB |
Output is correct |
6 |
Correct |
593 ms |
58544 KB |
Output is correct |
7 |
Correct |
548 ms |
57336 KB |
Output is correct |
8 |
Correct |
590 ms |
57516 KB |
Output is correct |
9 |
Correct |
528 ms |
57452 KB |
Output is correct |
10 |
Correct |
600 ms |
54188 KB |
Output is correct |
11 |
Correct |
453 ms |
53164 KB |
Output is correct |
12 |
Correct |
506 ms |
53408 KB |
Output is correct |
13 |
Correct |
554 ms |
53508 KB |
Output is correct |
14 |
Correct |
431 ms |
53556 KB |
Output is correct |
15 |
Correct |
617 ms |
54444 KB |
Output is correct |
16 |
Correct |
115 ms |
48044 KB |
Output is correct |
17 |
Correct |
273 ms |
53224 KB |
Output is correct |
18 |
Correct |
551 ms |
53680 KB |
Output is correct |
19 |
Correct |
171 ms |
49324 KB |
Output is correct |
20 |
Correct |
234 ms |
48560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
283 ms |
59296 KB |
Output is correct |
2 |
Correct |
245 ms |
44144 KB |
Output is correct |
3 |
Correct |
215 ms |
46140 KB |
Output is correct |
4 |
Correct |
161 ms |
39864 KB |
Output is correct |
5 |
Correct |
215 ms |
45740 KB |
Output is correct |
6 |
Correct |
165 ms |
40288 KB |
Output is correct |
7 |
Correct |
176 ms |
44652 KB |
Output is correct |
8 |
Correct |
182 ms |
41392 KB |
Output is correct |
9 |
Correct |
187 ms |
44460 KB |
Output is correct |
10 |
Correct |
137 ms |
38328 KB |
Output is correct |
11 |
Correct |
128 ms |
39092 KB |
Output is correct |
12 |
Correct |
135 ms |
38276 KB |
Output is correct |
13 |
Correct |
138 ms |
38832 KB |
Output is correct |
14 |
Correct |
122 ms |
39088 KB |
Output is correct |
15 |
Correct |
129 ms |
38324 KB |
Output is correct |
16 |
Correct |
65 ms |
37296 KB |
Output is correct |
17 |
Correct |
99 ms |
38068 KB |
Output is correct |
18 |
Correct |
114 ms |
38832 KB |
Output is correct |
19 |
Correct |
18 ms |
24668 KB |
Output is correct |
20 |
Correct |
16 ms |
24712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
435 ms |
29008 KB |
Output is correct |
2 |
Correct |
400 ms |
36176 KB |
Output is correct |
3 |
Correct |
340 ms |
35840 KB |
Output is correct |
4 |
Correct |
300 ms |
34640 KB |
Output is correct |
5 |
Correct |
340 ms |
35920 KB |
Output is correct |
6 |
Correct |
324 ms |
34900 KB |
Output is correct |
7 |
Correct |
349 ms |
35920 KB |
Output is correct |
8 |
Correct |
313 ms |
34900 KB |
Output is correct |
9 |
Correct |
298 ms |
34896 KB |
Output is correct |
10 |
Correct |
307 ms |
35060 KB |
Output is correct |
11 |
Correct |
309 ms |
34968 KB |
Output is correct |
12 |
Correct |
256 ms |
34132 KB |
Output is correct |
13 |
Correct |
299 ms |
34656 KB |
Output is correct |
14 |
Correct |
332 ms |
35408 KB |
Output is correct |
15 |
Correct |
313 ms |
35084 KB |
Output is correct |
16 |
Correct |
20 ms |
24924 KB |
Output is correct |
17 |
Correct |
142 ms |
34100 KB |
Output is correct |
18 |
Correct |
213 ms |
34132 KB |
Output is correct |
19 |
Correct |
18 ms |
24668 KB |
Output is correct |
20 |
Correct |
17 ms |
24668 KB |
Output is correct |
21 |
Correct |
993 ms |
94796 KB |
Output is correct |
22 |
Correct |
904 ms |
64688 KB |
Output is correct |
23 |
Correct |
716 ms |
66808 KB |
Output is correct |
24 |
Correct |
625 ms |
59568 KB |
Output is correct |
25 |
Correct |
603 ms |
58632 KB |
Output is correct |
26 |
Correct |
593 ms |
58544 KB |
Output is correct |
27 |
Correct |
548 ms |
57336 KB |
Output is correct |
28 |
Correct |
590 ms |
57516 KB |
Output is correct |
29 |
Correct |
528 ms |
57452 KB |
Output is correct |
30 |
Correct |
600 ms |
54188 KB |
Output is correct |
31 |
Correct |
453 ms |
53164 KB |
Output is correct |
32 |
Correct |
506 ms |
53408 KB |
Output is correct |
33 |
Correct |
554 ms |
53508 KB |
Output is correct |
34 |
Correct |
431 ms |
53556 KB |
Output is correct |
35 |
Correct |
617 ms |
54444 KB |
Output is correct |
36 |
Correct |
115 ms |
48044 KB |
Output is correct |
37 |
Correct |
273 ms |
53224 KB |
Output is correct |
38 |
Correct |
551 ms |
53680 KB |
Output is correct |
39 |
Correct |
171 ms |
49324 KB |
Output is correct |
40 |
Correct |
234 ms |
48560 KB |
Output is correct |
41 |
Correct |
283 ms |
59296 KB |
Output is correct |
42 |
Correct |
245 ms |
44144 KB |
Output is correct |
43 |
Correct |
215 ms |
46140 KB |
Output is correct |
44 |
Correct |
161 ms |
39864 KB |
Output is correct |
45 |
Correct |
215 ms |
45740 KB |
Output is correct |
46 |
Correct |
165 ms |
40288 KB |
Output is correct |
47 |
Correct |
176 ms |
44652 KB |
Output is correct |
48 |
Correct |
182 ms |
41392 KB |
Output is correct |
49 |
Correct |
187 ms |
44460 KB |
Output is correct |
50 |
Correct |
137 ms |
38328 KB |
Output is correct |
51 |
Correct |
128 ms |
39092 KB |
Output is correct |
52 |
Correct |
135 ms |
38276 KB |
Output is correct |
53 |
Correct |
138 ms |
38832 KB |
Output is correct |
54 |
Correct |
122 ms |
39088 KB |
Output is correct |
55 |
Correct |
129 ms |
38324 KB |
Output is correct |
56 |
Correct |
65 ms |
37296 KB |
Output is correct |
57 |
Correct |
99 ms |
38068 KB |
Output is correct |
58 |
Correct |
114 ms |
38832 KB |
Output is correct |
59 |
Correct |
18 ms |
24668 KB |
Output is correct |
60 |
Correct |
16 ms |
24712 KB |
Output is correct |
61 |
Correct |
2272 ms |
108968 KB |
Output is correct |
62 |
Correct |
1981 ms |
77916 KB |
Output is correct |
63 |
Correct |
1715 ms |
80872 KB |
Output is correct |
64 |
Correct |
1497 ms |
73312 KB |
Output is correct |
65 |
Correct |
1266 ms |
73068 KB |
Output is correct |
66 |
Correct |
1422 ms |
72368 KB |
Output is correct |
67 |
Correct |
1004 ms |
70320 KB |
Output is correct |
68 |
Correct |
1393 ms |
70056 KB |
Output is correct |
69 |
Correct |
1183 ms |
70832 KB |
Output is correct |
70 |
Correct |
1031 ms |
66172 KB |
Output is correct |
71 |
Correct |
689 ms |
65196 KB |
Output is correct |
72 |
Correct |
1002 ms |
66220 KB |
Output is correct |
73 |
Correct |
923 ms |
65016 KB |
Output is correct |
74 |
Correct |
824 ms |
66732 KB |
Output is correct |
75 |
Correct |
1083 ms |
66428 KB |
Output is correct |
76 |
Correct |
120 ms |
49328 KB |
Output is correct |
77 |
Correct |
319 ms |
62696 KB |
Output is correct |
78 |
Correct |
487 ms |
64156 KB |
Output is correct |
79 |
Correct |
18 ms |
24664 KB |
Output is correct |
80 |
Correct |
17 ms |
24668 KB |
Output is correct |