#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx,avx2,sse3,ssse3,sse4.1,sse4.2,tune=native")
#pragma GCC optimize(3)
#pragma GCC optimize("O3")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
using ld = long double;
using ll = long long;
#define int ll
#define sz(x) (int)x.size()
const int N = 2e5+5;
int n, q;
int p[N];
vector<int> T[4*N];
void init(int i, int tl, int tr){
if(tl == tr){
T[i].push_back(p[tl]);
return;
}
int m = (tl + tr) / 2;
init(2*i+1, tl, m);
init(2*i+2, m+1, tr);
merge(T[2*i+1].begin(), T[2*i+1].end(), T[2*i+2].begin(), T[2*i+2].end(), back_inserter(T[i]));
}
int query(int l, int r, int k, int i, int tl, int tr){
if(r < tl or l > tr){
return 0;
}
if(l <= tl && tr <= r){
return lower_bound(T[i].begin(), T[i].end(), k) - T[i].begin();
}
int m = (tl + tr) / 2;
return query(l, r, k, 2*i+1, tl, m) + query(l, r, k, 2*i+2, m+1, tr);
}
int query(int l, int r, int k){
return query(l, r, k, 0, 0, n-1);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
for(int i=0; i<n; ++i){
cin >> p[i];
}
init(0, 0, n-1);
while(q--){
int l, r;
cin >> l >> r;
l--, r--;
int low = 1, high = r - l + 1;
int res = 1;
while(low <= high){
int mid = (low + high) / 2;
int tmp = r - l + 1 - query(l, r, mid);
if(tmp >= mid){
res = mid;
low = mid+1;
} else {
high = mid-1;
}
}
cout << res << endl;
}
}
Compilation message
index.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization ("O3")
|
index.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
4 | #pragma GCC optimization ("unroll-loops")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19292 KB |
Output is correct |
2 |
Correct |
10 ms |
19292 KB |
Output is correct |
3 |
Correct |
9 ms |
19312 KB |
Output is correct |
4 |
Correct |
9 ms |
19288 KB |
Output is correct |
5 |
Correct |
10 ms |
19292 KB |
Output is correct |
6 |
Correct |
8 ms |
19292 KB |
Output is correct |
7 |
Correct |
9 ms |
19292 KB |
Output is correct |
8 |
Correct |
10 ms |
19288 KB |
Output is correct |
9 |
Correct |
9 ms |
19448 KB |
Output is correct |
10 |
Correct |
9 ms |
19288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19292 KB |
Output is correct |
2 |
Correct |
10 ms |
19292 KB |
Output is correct |
3 |
Correct |
9 ms |
19312 KB |
Output is correct |
4 |
Correct |
9 ms |
19288 KB |
Output is correct |
5 |
Correct |
10 ms |
19292 KB |
Output is correct |
6 |
Correct |
8 ms |
19292 KB |
Output is correct |
7 |
Correct |
9 ms |
19292 KB |
Output is correct |
8 |
Correct |
10 ms |
19288 KB |
Output is correct |
9 |
Correct |
9 ms |
19448 KB |
Output is correct |
10 |
Correct |
9 ms |
19288 KB |
Output is correct |
11 |
Correct |
691 ms |
30740 KB |
Output is correct |
12 |
Correct |
656 ms |
30736 KB |
Output is correct |
13 |
Correct |
663 ms |
30664 KB |
Output is correct |
14 |
Correct |
684 ms |
30932 KB |
Output is correct |
15 |
Correct |
698 ms |
30552 KB |
Output is correct |
16 |
Correct |
666 ms |
30864 KB |
Output is correct |
17 |
Correct |
675 ms |
30708 KB |
Output is correct |
18 |
Correct |
659 ms |
30892 KB |
Output is correct |
19 |
Correct |
672 ms |
30580 KB |
Output is correct |
20 |
Correct |
652 ms |
30692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19292 KB |
Output is correct |
2 |
Correct |
10 ms |
19292 KB |
Output is correct |
3 |
Correct |
9 ms |
19312 KB |
Output is correct |
4 |
Correct |
9 ms |
19288 KB |
Output is correct |
5 |
Correct |
10 ms |
19292 KB |
Output is correct |
6 |
Correct |
8 ms |
19292 KB |
Output is correct |
7 |
Correct |
9 ms |
19292 KB |
Output is correct |
8 |
Correct |
10 ms |
19288 KB |
Output is correct |
9 |
Correct |
9 ms |
19448 KB |
Output is correct |
10 |
Correct |
9 ms |
19288 KB |
Output is correct |
11 |
Correct |
691 ms |
30740 KB |
Output is correct |
12 |
Correct |
656 ms |
30736 KB |
Output is correct |
13 |
Correct |
663 ms |
30664 KB |
Output is correct |
14 |
Correct |
684 ms |
30932 KB |
Output is correct |
15 |
Correct |
698 ms |
30552 KB |
Output is correct |
16 |
Correct |
666 ms |
30864 KB |
Output is correct |
17 |
Correct |
675 ms |
30708 KB |
Output is correct |
18 |
Correct |
659 ms |
30892 KB |
Output is correct |
19 |
Correct |
672 ms |
30580 KB |
Output is correct |
20 |
Correct |
652 ms |
30692 KB |
Output is correct |
21 |
Execution timed out |
2537 ms |
66736 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |