# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1046937 |
2024-08-07T06:35:55 Z |
vjudge1 |
Index (COCI21_index) |
C++17 |
|
1247 ms |
132000 KB |
#include <bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define int long long int
#define endl '\n'
#define N 200105
#define MM 200000
#define mod 1000000007
#define pb push_back
#define p push
#define ins insert
#define f first
#define s second
//persistent segment tree kodu ///////////////////////////////////////////////////////////////////////////////////////////////////
int n;
struct node{
node *left, *right;
int val;
node(node* a,node* b){
val=0;
left=a;
right=b;
if(a) val+=a->val;
if(b) val+=b->val;
}
node(){
val=0;
left=NULL;right=NULL;
}
};
vector<node*> baslar;
node* update(node* x,int l,int r,int hed){
if(l==r){
node* yeni=new node;
yeni->val=x->val+1;
return yeni;
}
if(x->left==NULL)x->left=new node;
if(x->right==NULL)x->right=new node;
int mid=(l+r)/2;
if(hed<=mid){
return new node(update(x->left,l,mid,hed),x->right);
}
return new node(x->left,update(x->right,mid+1,r,hed));
}
inline int qua(node* x,int l,int r,int s,int e){
if(l>r||s>r||e<l||x==NULL) return 0;
if(s<=l&&r<=e)return x->val;
int mid=(l+r)/2;
return qua(x->left, l,mid,s,e)+qua(x->right,mid+1,r,s,e);
}
int cev(int x,int y){
int l=1,r=n;
int yes=-1;
while(l<=r){
int mid=(l+r)/2;
int a=qua(baslar[x-1],1,MM,1,MM-mid+1);
int b=qua(baslar[y],1,MM,1,MM-mid+1);
//cout<<l<<" "<<r<<" "<<mid<<" "<<a<<" "<<b<<endl;
if(b-a>=mid){
yes=mid;
l=mid+1;
}
else r=mid-1;
}
return yes;
}
signed main(){
lalala;
node* bas=new node;
baslar.pb(bas);
int q;cin>>n>>q;
for(int i=1;i<=n;i++){
int x;cin>>x;
int y=MM-x+1;
node* yeni=update(baslar[baslar.size()-1],1,MM,y);
baslar.pb(yeni);
}
while(q--){
int x,y;cin>>x>>y;
cout<<cev(x,y)<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
2 ms |
1116 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
2 ms |
1112 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
1116 KB |
Output is correct |
8 |
Correct |
2 ms |
1112 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
2 ms |
1116 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
2 ms |
1112 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
1116 KB |
Output is correct |
8 |
Correct |
2 ms |
1112 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
169 ms |
33336 KB |
Output is correct |
12 |
Correct |
176 ms |
33224 KB |
Output is correct |
13 |
Correct |
168 ms |
33228 KB |
Output is correct |
14 |
Correct |
170 ms |
33272 KB |
Output is correct |
15 |
Correct |
173 ms |
33224 KB |
Output is correct |
16 |
Correct |
187 ms |
33324 KB |
Output is correct |
17 |
Correct |
205 ms |
33292 KB |
Output is correct |
18 |
Correct |
176 ms |
33100 KB |
Output is correct |
19 |
Correct |
175 ms |
33308 KB |
Output is correct |
20 |
Correct |
176 ms |
33292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
2 ms |
1116 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
2 ms |
1112 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
1116 KB |
Output is correct |
8 |
Correct |
2 ms |
1112 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
169 ms |
33336 KB |
Output is correct |
12 |
Correct |
176 ms |
33224 KB |
Output is correct |
13 |
Correct |
168 ms |
33228 KB |
Output is correct |
14 |
Correct |
170 ms |
33272 KB |
Output is correct |
15 |
Correct |
173 ms |
33224 KB |
Output is correct |
16 |
Correct |
187 ms |
33324 KB |
Output is correct |
17 |
Correct |
205 ms |
33292 KB |
Output is correct |
18 |
Correct |
176 ms |
33100 KB |
Output is correct |
19 |
Correct |
175 ms |
33308 KB |
Output is correct |
20 |
Correct |
176 ms |
33292 KB |
Output is correct |
21 |
Correct |
1075 ms |
131776 KB |
Output is correct |
22 |
Correct |
1086 ms |
131772 KB |
Output is correct |
23 |
Correct |
1079 ms |
131776 KB |
Output is correct |
24 |
Correct |
1077 ms |
131772 KB |
Output is correct |
25 |
Correct |
1167 ms |
131876 KB |
Output is correct |
26 |
Correct |
1247 ms |
131884 KB |
Output is correct |
27 |
Correct |
1109 ms |
132000 KB |
Output is correct |
28 |
Correct |
1077 ms |
131784 KB |
Output is correct |
29 |
Correct |
1097 ms |
131768 KB |
Output is correct |
30 |
Correct |
1101 ms |
131776 KB |
Output is correct |