# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
712120 |
2023-03-18T07:27:43 Z |
Thienu |
Index (COCI21_index) |
C++17 |
|
2132 ms |
260280 KB |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int a,n,t,x,y,st,md,ed;
vector<int> v[200005];
struct node
{
int val;
node *l,*r;
};
typedef node* pnode;
void build(pnode tree,int st,int ed)
{
int md=(st+ed)/2;
if(st==ed)
{
tree->val=1;
return;
}
tree->l=new node(),tree->r=new node();
build(tree->l,st,md);
build(tree->r,md+1,ed);
tree->val=tree->l->val+tree->r->val;
}
void update(pnode tree,pnode pre,int st,int ed,int idx,int val)
{
int md=(st+ed)/2;
if(st==ed)
{
tree->val=pre->val+val;
return;
}
if(idx<=md)
{
// if(!tree->l)
// {
tree->l=new node();
// }else
// {
// tree->l=pre->l;
// }
tree->r=pre->r;
update(tree->l,pre->l,st,md,idx,val);
}else
{
tree->l=pre->l;
// if(!tree->r)
// {
tree->r=new node();
// }else
// {
// tree->r=pre->r;
// }
update(tree->r,pre->r,md+1,ed,idx,val);
}
tree->val=tree->l->val+tree->r->val;
}
int query(pnode tree,int st,int ed,int l,int r)
{
int md=(st+ed)/2;
if(st>r||ed<l)return 0;
if(st>=l&&ed<=r)return tree->val;
return query(tree->l,st,md,l,r)+query(tree->r,md+1,ed,l,r);
}
void debug(pnode tree,int st,int ed)
{
int md=(st+ed)/2;
if(st==ed)
{
printf("%d %d %d\n",st,ed,tree->val);
return;
}
debug(tree->l,st,md);
debug(tree->r,md+1,ed);
printf("%d %d %d\n",st,ed,tree->val);
}
node root[400005];
int checkpt[200005];
int main()
{
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> n >> t;
build(&root[1],1,n);
/*debug(&root[1],1,n);
printf("query\n");
for(int i=1;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
printf("%d %d %d\n",i,j,query(&root[1],1,n,i,j));
}
}*/
checkpt[1] = 1;
for(int i=1;i<=n;i++)
{
cin >> a;
v[a].pb(i);
}
int upd_num = 1;
for(int i=2;i<=200000;i++)
{
update(&root[upd_num+1],&root[upd_num],1,n,1,0); upd_num++;
for(int j=0;j<(int)v[i-1].size();j++)
{
int num=v[i-1][j];
update(&root[upd_num+1],&root[upd_num],1,n,num,-1); upd_num++;
// if(i==2)
// {
// printf("%d\n",j);
// debug(&root[1],1,n);
// }
}
checkpt[i] = upd_num;
}
/*for(int i=1;i<=8;i++)
{
printf("%d\n",i);
for(int j=1;j<=n;j++)
{
for(int k=j;k<=n;k++)
{
printf("%d %d %d\n",j,k,query(&root[i],1,n,j,k));
}
}
}*/
while(t--)
{
cin >> x >> y;
st=1,ed=200000;
while(ed>=st)
{
md=(st+ed)/2;
if(query(&root[checkpt[md]],1,n,x,y)>=md)
{
st=md+1;
}else
{
ed=md-1;
}
}
printf("%d\n", st-1);
/*for(int i=1;i<=8;i++)
{
printf("%d ",query(&root[i],1,n,x,y));
}
printf("\n");*/
//printf("%d %d %d\n",st,md,ed);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
73476 KB |
Output is correct |
2 |
Correct |
80 ms |
73420 KB |
Output is correct |
3 |
Correct |
83 ms |
73516 KB |
Output is correct |
4 |
Correct |
79 ms |
73548 KB |
Output is correct |
5 |
Correct |
76 ms |
73428 KB |
Output is correct |
6 |
Correct |
76 ms |
73488 KB |
Output is correct |
7 |
Correct |
73 ms |
73440 KB |
Output is correct |
8 |
Correct |
73 ms |
73532 KB |
Output is correct |
9 |
Correct |
102 ms |
73516 KB |
Output is correct |
10 |
Correct |
87 ms |
73476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
73476 KB |
Output is correct |
2 |
Correct |
80 ms |
73420 KB |
Output is correct |
3 |
Correct |
83 ms |
73516 KB |
Output is correct |
4 |
Correct |
79 ms |
73548 KB |
Output is correct |
5 |
Correct |
76 ms |
73428 KB |
Output is correct |
6 |
Correct |
76 ms |
73488 KB |
Output is correct |
7 |
Correct |
73 ms |
73440 KB |
Output is correct |
8 |
Correct |
73 ms |
73532 KB |
Output is correct |
9 |
Correct |
102 ms |
73516 KB |
Output is correct |
10 |
Correct |
87 ms |
73476 KB |
Output is correct |
11 |
Correct |
404 ms |
141652 KB |
Output is correct |
12 |
Correct |
439 ms |
141764 KB |
Output is correct |
13 |
Correct |
429 ms |
141648 KB |
Output is correct |
14 |
Correct |
393 ms |
141736 KB |
Output is correct |
15 |
Correct |
443 ms |
141652 KB |
Output is correct |
16 |
Correct |
423 ms |
141652 KB |
Output is correct |
17 |
Correct |
475 ms |
141624 KB |
Output is correct |
18 |
Correct |
478 ms |
141648 KB |
Output is correct |
19 |
Correct |
427 ms |
141864 KB |
Output is correct |
20 |
Correct |
590 ms |
141588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
73476 KB |
Output is correct |
2 |
Correct |
80 ms |
73420 KB |
Output is correct |
3 |
Correct |
83 ms |
73516 KB |
Output is correct |
4 |
Correct |
79 ms |
73548 KB |
Output is correct |
5 |
Correct |
76 ms |
73428 KB |
Output is correct |
6 |
Correct |
76 ms |
73488 KB |
Output is correct |
7 |
Correct |
73 ms |
73440 KB |
Output is correct |
8 |
Correct |
73 ms |
73532 KB |
Output is correct |
9 |
Correct |
102 ms |
73516 KB |
Output is correct |
10 |
Correct |
87 ms |
73476 KB |
Output is correct |
11 |
Correct |
404 ms |
141652 KB |
Output is correct |
12 |
Correct |
439 ms |
141764 KB |
Output is correct |
13 |
Correct |
429 ms |
141648 KB |
Output is correct |
14 |
Correct |
393 ms |
141736 KB |
Output is correct |
15 |
Correct |
443 ms |
141652 KB |
Output is correct |
16 |
Correct |
423 ms |
141652 KB |
Output is correct |
17 |
Correct |
475 ms |
141624 KB |
Output is correct |
18 |
Correct |
478 ms |
141648 KB |
Output is correct |
19 |
Correct |
427 ms |
141864 KB |
Output is correct |
20 |
Correct |
590 ms |
141588 KB |
Output is correct |
21 |
Correct |
1948 ms |
260064 KB |
Output is correct |
22 |
Correct |
1996 ms |
260108 KB |
Output is correct |
23 |
Correct |
1992 ms |
259988 KB |
Output is correct |
24 |
Correct |
2132 ms |
260276 KB |
Output is correct |
25 |
Correct |
1917 ms |
260140 KB |
Output is correct |
26 |
Correct |
1984 ms |
260112 KB |
Output is correct |
27 |
Correct |
1881 ms |
260200 KB |
Output is correct |
28 |
Correct |
1903 ms |
260280 KB |
Output is correct |
29 |
Correct |
1947 ms |
260188 KB |
Output is correct |
30 |
Correct |
1957 ms |
260036 KB |
Output is correct |