/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
typedef tree<
array<int, 3>,
null_type,
less<array<int, 3>>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int n, q, ans[N];
vector<array<int, 3>> Q;
void solve(){
cin >> n >> q;
vector<int> a(n);
for(int i = 0; i < n; ++i) cin >> a[i];
for(int i = 0; i < q; ++i){
int t, x; cin >> t >> x;
Q.pb({t, x - 1, i});
}
sort(all(Q));
bool ok = 1;
int t = 0;
int qp = 0;
while(qp < Q.size() && Q[qp][0] == t){
ans[Q[qp][2]] = a[Q[qp][1]];
++qp;
}
ordered_set oset;
int last = a[0], lastpos = 0;
for(int i = 0; i < n; ++i){
if(last < a[i])
last = a[i], lastpos = i;
oset.insert({last, i - lastpos, a[i]});
}
// for(auto k: oset) cout << k[0] << ' ' << k[1] << ' ' << k[2] << '\n';
// en;
int done = n;
while(ok){
ok = 0;
int last = 0, lastpos = 0;
for(int i = n/2; i < done; ++i){
auto it = oset.find_by_order(i);
if((*it)[2] > last){
last = (*it)[2];
lastpos = i;
}
array<int, 3> vv = {last, i - lastpos, (*it)[2]};
if(last == (*it)[0]){
done = i;
break;
}
ok = 1;
oset.erase(it);
oset.insert(vv);
}
++t;
while(qp < Q.size() && (Q[qp][0] == t || !ok)){
ans[Q[qp][2]] = (*oset.find_by_order(Q[qp][1]))[2];
++qp;
}
// for(auto k: oset) cout << k[0] << ' ' << k[1] << ' ' << k[2] << '\n';
// en;
}
for(int i = 0; i < q; ++i) cout << ans[i] << '\n';
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:37:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | while(qp < Q.size() && Q[qp][0] == t){
| ~~~^~~~~~~~~~
Main.cpp:71:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | while(qp < Q.size() && (Q[qp][0] == t || !ok)){
| ~~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:85:15: warning: unused variable 'aa' [-Wunused-variable]
85 | int tt = 1, aa;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
344 ms |
20140 KB |
Output is correct |
2 |
Correct |
317 ms |
20132 KB |
Output is correct |
3 |
Correct |
324 ms |
19120 KB |
Output is correct |
4 |
Correct |
297 ms |
19120 KB |
Output is correct |
5 |
Correct |
313 ms |
20016 KB |
Output is correct |
6 |
Correct |
298 ms |
19084 KB |
Output is correct |
7 |
Correct |
319 ms |
19888 KB |
Output is correct |
8 |
Correct |
303 ms |
20400 KB |
Output is correct |
9 |
Correct |
295 ms |
19120 KB |
Output is correct |
10 |
Correct |
307 ms |
20144 KB |
Output is correct |
11 |
Correct |
295 ms |
19340 KB |
Output is correct |
12 |
Correct |
285 ms |
19232 KB |
Output is correct |
13 |
Correct |
299 ms |
20188 KB |
Output is correct |
14 |
Correct |
303 ms |
20400 KB |
Output is correct |
15 |
Correct |
316 ms |
19924 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
270 ms |
19828 KB |
Output is correct |
18 |
Correct |
287 ms |
19116 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3090 ms |
25660 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3052 ms |
10632 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
344 ms |
20140 KB |
Output is correct |
2 |
Correct |
317 ms |
20132 KB |
Output is correct |
3 |
Correct |
324 ms |
19120 KB |
Output is correct |
4 |
Correct |
297 ms |
19120 KB |
Output is correct |
5 |
Correct |
313 ms |
20016 KB |
Output is correct |
6 |
Correct |
298 ms |
19084 KB |
Output is correct |
7 |
Correct |
319 ms |
19888 KB |
Output is correct |
8 |
Correct |
303 ms |
20400 KB |
Output is correct |
9 |
Correct |
295 ms |
19120 KB |
Output is correct |
10 |
Correct |
307 ms |
20144 KB |
Output is correct |
11 |
Correct |
295 ms |
19340 KB |
Output is correct |
12 |
Correct |
285 ms |
19232 KB |
Output is correct |
13 |
Correct |
299 ms |
20188 KB |
Output is correct |
14 |
Correct |
303 ms |
20400 KB |
Output is correct |
15 |
Correct |
316 ms |
19924 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
270 ms |
19828 KB |
Output is correct |
18 |
Correct |
287 ms |
19116 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Execution timed out |
3090 ms |
25660 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |