This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
#define int ll
#define sz(x) (int)x.size()
signed main(){
int n, q;
cin >> n >> q;
vector<int> p(n);
for(auto &i : p){
cin >> i;
}
while(q--){
int l, r;
cin >> l >> r;
l--, r--;
vector<int> tmp;
for(int i=l; i<=r; ++i){
tmp.push_back(p[i]);
}
sort(tmp.rbegin(), tmp.rend());
assert(sz(tmp) == r-l+1);
int low = 1, high = r - l + 1;
int res = 1;
while(low <= high){
int mid = (low + high) / 2;
if(tmp[mid-1] >= mid){
res = mid;
low = mid+1;
} else {
high = mid-1;
}
}
cout << res << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |