# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1046918 |
2024-08-07T06:18:10 Z |
vjudge1 |
Index (COCI21_index) |
C++17 |
|
515 ms |
134328 KB |
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N=200000;
struct Node{
int val=0;
Node *l=NULL,*r=NULL;
};
void build(Node *node,int l,int r){
if(l==r)return;
int mid=(l+r)/2;
node->l=new Node;
node->r=new Node;
build(node->l,l,mid);
build(node->r,mid+1,r);
return;
}
void update(Node *node,Node *pre,int l,int r,int x,int y){
if(l==r){
node->val=y;
return;
}
int mid=(l+r)/2;
if(x<=mid){
node->r=pre->r;
node->l=new Node;
update(node->l,pre->l,l,mid,x,y);
}
else{
node->l=pre->l;
node->r=new Node;
update(node->r,pre->r,mid+1,r,x,y);
}
node->val=node->l->val+node->r->val;
return;
}
int query(Node *node,Node *pre,int l,int r,int k){
if(l==r){
return l;
}
int mid=(l+r)/2;
if(node->r->val-pre->r->val+k>=mid+1){
return query(node->r,pre->r,mid+1,r,k);
}
return query(node->l,pre->l,l,mid,k+node->r->val-pre->r->val);
}
int32_t main(){
fast;
int n,q;
cin>>n>>q;
vector<int>arr(n+1);
for(int i=1;i<=n;i++){
cin>>arr[i];
}
vector<Node*>pre(n+1);
pre[0]=new Node;
build(pre[0],1,N);
vector<int>cnt(N+1);
for(int i=1;i<=n;i++){
cnt[arr[i]]++;
pre[i]=new Node;
update(pre[i],pre[i-1],1,N,arr[i],cnt[arr[i]]);
}
while(q--){
int l,r;
cin>>l>>r;
cout<<query(pre[r],pre[l-1],1,N,0)<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
14172 KB |
Output is correct |
2 |
Correct |
14 ms |
14304 KB |
Output is correct |
3 |
Correct |
11 ms |
14168 KB |
Output is correct |
4 |
Correct |
18 ms |
14340 KB |
Output is correct |
5 |
Correct |
11 ms |
14276 KB |
Output is correct |
6 |
Correct |
11 ms |
14168 KB |
Output is correct |
7 |
Correct |
11 ms |
14236 KB |
Output is correct |
8 |
Correct |
11 ms |
14172 KB |
Output is correct |
9 |
Correct |
13 ms |
14172 KB |
Output is correct |
10 |
Correct |
11 ms |
14424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
14172 KB |
Output is correct |
2 |
Correct |
14 ms |
14304 KB |
Output is correct |
3 |
Correct |
11 ms |
14168 KB |
Output is correct |
4 |
Correct |
18 ms |
14340 KB |
Output is correct |
5 |
Correct |
11 ms |
14276 KB |
Output is correct |
6 |
Correct |
11 ms |
14168 KB |
Output is correct |
7 |
Correct |
11 ms |
14236 KB |
Output is correct |
8 |
Correct |
11 ms |
14172 KB |
Output is correct |
9 |
Correct |
13 ms |
14172 KB |
Output is correct |
10 |
Correct |
11 ms |
14424 KB |
Output is correct |
11 |
Correct |
130 ms |
44116 KB |
Output is correct |
12 |
Correct |
102 ms |
43796 KB |
Output is correct |
13 |
Correct |
104 ms |
43860 KB |
Output is correct |
14 |
Correct |
110 ms |
43724 KB |
Output is correct |
15 |
Correct |
105 ms |
43860 KB |
Output is correct |
16 |
Correct |
113 ms |
43740 KB |
Output is correct |
17 |
Correct |
109 ms |
43780 KB |
Output is correct |
18 |
Correct |
102 ms |
43704 KB |
Output is correct |
19 |
Correct |
102 ms |
43856 KB |
Output is correct |
20 |
Correct |
102 ms |
43868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
14172 KB |
Output is correct |
2 |
Correct |
14 ms |
14304 KB |
Output is correct |
3 |
Correct |
11 ms |
14168 KB |
Output is correct |
4 |
Correct |
18 ms |
14340 KB |
Output is correct |
5 |
Correct |
11 ms |
14276 KB |
Output is correct |
6 |
Correct |
11 ms |
14168 KB |
Output is correct |
7 |
Correct |
11 ms |
14236 KB |
Output is correct |
8 |
Correct |
11 ms |
14172 KB |
Output is correct |
9 |
Correct |
13 ms |
14172 KB |
Output is correct |
10 |
Correct |
11 ms |
14424 KB |
Output is correct |
11 |
Correct |
130 ms |
44116 KB |
Output is correct |
12 |
Correct |
102 ms |
43796 KB |
Output is correct |
13 |
Correct |
104 ms |
43860 KB |
Output is correct |
14 |
Correct |
110 ms |
43724 KB |
Output is correct |
15 |
Correct |
105 ms |
43860 KB |
Output is correct |
16 |
Correct |
113 ms |
43740 KB |
Output is correct |
17 |
Correct |
109 ms |
43780 KB |
Output is correct |
18 |
Correct |
102 ms |
43704 KB |
Output is correct |
19 |
Correct |
102 ms |
43856 KB |
Output is correct |
20 |
Correct |
102 ms |
43868 KB |
Output is correct |
21 |
Correct |
455 ms |
134228 KB |
Output is correct |
22 |
Correct |
497 ms |
134224 KB |
Output is correct |
23 |
Correct |
458 ms |
134300 KB |
Output is correct |
24 |
Correct |
453 ms |
134228 KB |
Output is correct |
25 |
Correct |
501 ms |
134224 KB |
Output is correct |
26 |
Correct |
496 ms |
134180 KB |
Output is correct |
27 |
Correct |
515 ms |
134204 KB |
Output is correct |
28 |
Correct |
473 ms |
134328 KB |
Output is correct |
29 |
Correct |
456 ms |
134224 KB |
Output is correct |
30 |
Correct |
452 ms |
134224 KB |
Output is correct |