#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,bmi,bmi2,lzcnt,popcnt")
int32_t main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> v(n+1);
for(int i=1; i<=n; i++) cin >> v[i];
vector<pii> qus(q);
for(pii &x : qus) cin >> x.first >> x.second;
vector<int> L(q, 1), R(q, 2e5), ANS(q, 1);
bool changed = 1;
while(changed) {
changed = 0;
map<int, stack<int> > to_change;
for(int i=0; i<q; i++)
if(L[i] <= R[i]) to_change[(L[i] + R[i]) / 2].push(i);
for(auto &[mid, st] : to_change) {
vector<int> pref(n+1);
for(int i=1; i<=n; i++) pref[i] = pref[i-1] + (v[i] >= mid);
while(!st.empty()) {
changed = 1;
int id = st.top();
st.pop();
if(pref[qus[id].second] - pref[qus[id].first-1] >= mid) ANS[id] = mid, L[id] = mid + 1;
else R[id] = mid - 1;
}
}
}
for(int &x : ANS) cout << x << '\n';
return 0;
}
Compilation message
index.cpp: In function 'int32_t main()':
index.cpp:32:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
32 | for(auto &[mid, st] : to_change) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
116 ms |
3568 KB |
Output is correct |
12 |
Correct |
114 ms |
3432 KB |
Output is correct |
13 |
Correct |
127 ms |
3576 KB |
Output is correct |
14 |
Correct |
115 ms |
3472 KB |
Output is correct |
15 |
Correct |
118 ms |
3472 KB |
Output is correct |
16 |
Correct |
120 ms |
3608 KB |
Output is correct |
17 |
Correct |
114 ms |
3468 KB |
Output is correct |
18 |
Correct |
116 ms |
3376 KB |
Output is correct |
19 |
Correct |
115 ms |
3472 KB |
Output is correct |
20 |
Correct |
121 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
116 ms |
3568 KB |
Output is correct |
12 |
Correct |
114 ms |
3432 KB |
Output is correct |
13 |
Correct |
127 ms |
3576 KB |
Output is correct |
14 |
Correct |
115 ms |
3472 KB |
Output is correct |
15 |
Correct |
118 ms |
3472 KB |
Output is correct |
16 |
Correct |
120 ms |
3608 KB |
Output is correct |
17 |
Correct |
114 ms |
3468 KB |
Output is correct |
18 |
Correct |
116 ms |
3376 KB |
Output is correct |
19 |
Correct |
115 ms |
3472 KB |
Output is correct |
20 |
Correct |
121 ms |
3420 KB |
Output is correct |
21 |
Correct |
1501 ms |
13380 KB |
Output is correct |
22 |
Correct |
1510 ms |
13380 KB |
Output is correct |
23 |
Correct |
1601 ms |
13400 KB |
Output is correct |
24 |
Correct |
1572 ms |
13400 KB |
Output is correct |
25 |
Correct |
1526 ms |
13432 KB |
Output is correct |
26 |
Correct |
1505 ms |
13504 KB |
Output is correct |
27 |
Correct |
1502 ms |
13356 KB |
Output is correct |
28 |
Correct |
1539 ms |
13324 KB |
Output is correct |
29 |
Correct |
1516 ms |
13612 KB |
Output is correct |
30 |
Correct |
1529 ms |
13592 KB |
Output is correct |