Submission #1046985

#TimeUsernameProblemLanguageResultExecution timeMemory
1046985vjudge1Index (COCI21_index)C++17
110 / 110
2201 ms64952 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fr first #define sc second #define pb push_back #define endl "\n" #define all(x) x.begin(),x.end() #define sp << " " << #define MAX 1000000007 #define LLMAX 1000000000000000000 #define N 200005 #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed<<setprecision(1) int n,q,a[N]; vector<int> st[4*N]; int bs(int x,int val){ int l=0,r=st[x].size(); while(l<r){ int mid=(l+r)/2; if(st[x][mid]>=val) r=mid; else l=mid+1; } return st[x].size()-l; } void build(){ int l=n+1,r=2*n; for(int i=l;i<=r;i++) st[i].pb(a[i-n]); l/=2; r/=2; while(r>0){ for(int i=max(l,(int)1);i<=r;i++){ for(auto j:st[2*i]) st[i].pb(j); for(auto j:st[2*i+1]) st[i].pb(j); sort(all(st[i])); } l/=2; r/=2; } } int query(int l,int r,int val){ l+=n; r+=n; int ans=0; while(l<=r){ if(l&1){ ans+=bs(l,val); l++; } if(!(r&1)){ ans+=bs(r,val); r--; } l/=2; r/=2; } return ans; } int32_t main(){ fast; cin >> n >> q; for(int i=1;i<=n;i++) cin >> a[i]; build(); while(q--){ int x,y; cin >> x >> y; int l=1,r=y-x+1; while(l<r){ int mid=(l+r+1)/2; if(query(x,y,mid)>=mid) l=mid; else r=mid-1; } cout << l << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...