# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
857538 |
2023-10-06T11:18:27 Z |
8pete8 |
Index (COCI21_index) |
C++17 |
|
1412 ms |
193208 KB |
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
//#include "combo.h"
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define int long long
const int mod=1e9+7,mxn=2*1e5,inf=mxn+5,lg=25;
int n,m;
bitset<mxn+10>yes;
struct node{
node *l,*r;
int val;
node():val(0),l(0),r(0){}
};
node* root[mxn+10];
vector<int>g[mxn+10];
void build(node*&a,int l,int r){
a=new node();
int mid=l+(r-l)/2;
if(l==r)return;
build(a->l,l,mid);
build(a->r,mid+1,r);
}
void update(node *&ncur,node *lcur,int val,int pos,int l,int r){
ncur=new node(*lcur);
if(l==r){
ncur->val+=val;
return;
}
int mid=l+(r-l)/2;
if(pos<=mid) update(ncur->l,lcur->l,val,pos,l,mid);
else update(ncur->r,lcur->r,val,pos,mid+1,r);
ncur->val=ncur->l->val+ncur->r->val;
}
int qry(int l,int r,int ql,int qr,node *cur){
if(ql>r||qr<l)return 0;
if(ql<=l&&r<=qr)return cur->val;
int mid=l+(r-l)/2;
return qry(l,mid,ql,qr,cur->l)+qry(mid+1,r,ql,qr,cur->r);
}
int32_t main(){
fastio
cin>>n>>m;
int mx=0;
vector<pii>v;
for(int i=1;i<=n;i++){
int a;cin>>a;
v.pb({a,i});
g[a].pb(i);
mx=max(mx,a);
}
build(root[mx+1],1,n);
v.pb({mx+1,0});
for(int i=mx;i>=1;i--){
bool again=true;
if(g[i].size()==0)update(root[i],root[i+1],0,1,1,n);
else for(auto j:g[i]){
if(again)update(root[i],root[i+1],1,j,1,n);
else update(root[i],root[i],1,j,1,n);
again=false;
}
}
for(int i=0;i<m;i++){
int ql,qr;cin>>ql>>qr;
int ans=0;
int l=0,r=mx;
while(l<=r){
int mid=l+(r-l)/2;
int cnt=qry(1,n,ql,qr,root[mid]);
if(cnt>=mid){
l=mid+1;
ans=max(ans,mid);
}
else r=mid-1;
}
cout<<ans<<'\n';
}
}
Compilation message
index.cpp: In constructor 'node::node()':
index.cpp:38:9: warning: 'node::val' will be initialized after [-Wreorder]
38 | int val;
| ^~~
index.cpp:37:11: warning: 'node* node::l' [-Wreorder]
37 | node *l,*r;
| ^
index.cpp:39:5: warning: when initialized here [-Wreorder]
39 | node():val(0),l(0),r(0){}
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5724 KB |
Output is correct |
2 |
Correct |
3 ms |
5672 KB |
Output is correct |
3 |
Correct |
4 ms |
5724 KB |
Output is correct |
4 |
Correct |
3 ms |
5724 KB |
Output is correct |
5 |
Correct |
3 ms |
5724 KB |
Output is correct |
6 |
Correct |
3 ms |
5724 KB |
Output is correct |
7 |
Correct |
3 ms |
5724 KB |
Output is correct |
8 |
Correct |
3 ms |
5720 KB |
Output is correct |
9 |
Correct |
3 ms |
5724 KB |
Output is correct |
10 |
Correct |
4 ms |
5752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5724 KB |
Output is correct |
2 |
Correct |
3 ms |
5672 KB |
Output is correct |
3 |
Correct |
4 ms |
5724 KB |
Output is correct |
4 |
Correct |
3 ms |
5724 KB |
Output is correct |
5 |
Correct |
3 ms |
5724 KB |
Output is correct |
6 |
Correct |
3 ms |
5724 KB |
Output is correct |
7 |
Correct |
3 ms |
5724 KB |
Output is correct |
8 |
Correct |
3 ms |
5720 KB |
Output is correct |
9 |
Correct |
3 ms |
5724 KB |
Output is correct |
10 |
Correct |
4 ms |
5752 KB |
Output is correct |
11 |
Correct |
221 ms |
47556 KB |
Output is correct |
12 |
Correct |
210 ms |
47436 KB |
Output is correct |
13 |
Correct |
209 ms |
47444 KB |
Output is correct |
14 |
Correct |
211 ms |
47376 KB |
Output is correct |
15 |
Correct |
206 ms |
47300 KB |
Output is correct |
16 |
Correct |
211 ms |
47388 KB |
Output is correct |
17 |
Correct |
215 ms |
47712 KB |
Output is correct |
18 |
Correct |
210 ms |
47464 KB |
Output is correct |
19 |
Correct |
207 ms |
47556 KB |
Output is correct |
20 |
Correct |
219 ms |
47508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5724 KB |
Output is correct |
2 |
Correct |
3 ms |
5672 KB |
Output is correct |
3 |
Correct |
4 ms |
5724 KB |
Output is correct |
4 |
Correct |
3 ms |
5724 KB |
Output is correct |
5 |
Correct |
3 ms |
5724 KB |
Output is correct |
6 |
Correct |
3 ms |
5724 KB |
Output is correct |
7 |
Correct |
3 ms |
5724 KB |
Output is correct |
8 |
Correct |
3 ms |
5720 KB |
Output is correct |
9 |
Correct |
3 ms |
5724 KB |
Output is correct |
10 |
Correct |
4 ms |
5752 KB |
Output is correct |
11 |
Correct |
221 ms |
47556 KB |
Output is correct |
12 |
Correct |
210 ms |
47436 KB |
Output is correct |
13 |
Correct |
209 ms |
47444 KB |
Output is correct |
14 |
Correct |
211 ms |
47376 KB |
Output is correct |
15 |
Correct |
206 ms |
47300 KB |
Output is correct |
16 |
Correct |
211 ms |
47388 KB |
Output is correct |
17 |
Correct |
215 ms |
47712 KB |
Output is correct |
18 |
Correct |
210 ms |
47464 KB |
Output is correct |
19 |
Correct |
207 ms |
47556 KB |
Output is correct |
20 |
Correct |
219 ms |
47508 KB |
Output is correct |
21 |
Correct |
1412 ms |
193024 KB |
Output is correct |
22 |
Correct |
1355 ms |
192264 KB |
Output is correct |
23 |
Correct |
1329 ms |
192796 KB |
Output is correct |
24 |
Correct |
1341 ms |
192372 KB |
Output is correct |
25 |
Correct |
1318 ms |
192436 KB |
Output is correct |
26 |
Correct |
1350 ms |
193208 KB |
Output is correct |
27 |
Correct |
1335 ms |
193208 KB |
Output is correct |
28 |
Correct |
1302 ms |
192940 KB |
Output is correct |
29 |
Correct |
1367 ms |
192648 KB |
Output is correct |
30 |
Correct |
1345 ms |
192328 KB |
Output is correct |