#include<bits/stdc++.h>
#include "bubblesort2.h"
#define ll long long
using namespace std;
int val[1000005],aint[4000005],lazy[4000005];
vector<pair<int,int>>aux;
int n,q,l;
void push(int nod,int st,int dr)
{
if (lazy[nod]){
aint[nod]+=lazy[nod];
if (st!=dr){
lazy[nod*2]+=lazy[nod];
lazy[nod*2+1]+=lazy[nod];
}
lazy[nod]=0;
}
}
void update(int nod,int st,int dr,int l,int r,int add)
{
if (l>r)
return ;
if (l<=st && dr<=r){
aint[nod]+=add;
if (st!=dr){
lazy[nod*2]+=add;
lazy[nod*2+1]+=add;
}
return ;
}
push(nod,st,dr);
int mij=(st+dr)/2;
if (l<=mij)
update(nod*2,st,mij,l,r,add);
if (mij+1<=r)
update(nod*2+1,mij+1,dr,l,r,add);
push(nod*2,st,mij);
push(nod*2+1,mij+1,dr);
aint[nod]=max(aint[nod*2],aint[nod*2+1]);
}
void update2(int nod,int st,int dr,int poz,int val)
{
if (st==dr){
aint[nod]+=val;
return ;
}
push(nod,st,dr);
int mij=(st+dr)/2;
if (poz<=mij)
update2(nod*2,st,mij,poz,val);
else
update2(nod*2+1,mij+1,dr,poz,val);
push(nod*2,st,mij);
push(nod*2+1,mij+1,dr);
aint[nod]=max(aint[nod*2],aint[nod*2+1]);
}
int calcpoz(pair<int,int>auxi)
{
return lower_bound(aux.begin(),aux.end(),auxi)-aux.begin();
}
vector<int> countScans(vector<int>a,vector<int>x,vector<int>v)
{
n=a.size();
q=x.size();
int i;
for(i=0;i<n;i++)
aux.push_back(make_pair(a[i],i));
for(i=0;i<q;i++)
aux.push_back(make_pair(v[i],x[i]));
sort(aux.begin(),aux.end());
aux.resize(unique(aux.begin(),aux.end())-aux.begin());
for(i=0;i<n;i++){
int ind1=calcpoz(make_pair(a[i],i));
update(1,0,aux.size()-1,ind1,ind1,(i+1));
int ind2=calcpoz(make_pair(a[i],-1));
update(1,0,aux.size()-1,ind2,aux.size()-1,-1);
}
vector<int>ans;
for(i=0;i<q;i++){
int ind1=calcpoz(make_pair(a[x[i]],x[i]));
update(1,0,aux.size()-1,ind1,ind1,-(x[i]+1));
int ind2=calcpoz(make_pair(a[x[i]],-1));
update(1,0,aux.size()-1,ind2,aux.size()-1,1);
a[x[i]]=v[i];
ind1=calcpoz(make_pair(a[x[i]],x[i]));
update(1,0,aux.size()-1,ind1,ind1,(x[i]+1));
ind2=calcpoz(make_pair(a[x[i]],-1));
update(1,0,aux.size()-1,ind2,aux.size()-1,-1);
ans.push_back(aint[1]);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
6 ms |
620 KB |
Output is correct |
4 |
Correct |
6 ms |
620 KB |
Output is correct |
5 |
Correct |
6 ms |
620 KB |
Output is correct |
6 |
Correct |
5 ms |
620 KB |
Output is correct |
7 |
Correct |
5 ms |
492 KB |
Output is correct |
8 |
Correct |
6 ms |
620 KB |
Output is correct |
9 |
Correct |
7 ms |
620 KB |
Output is correct |
10 |
Correct |
5 ms |
620 KB |
Output is correct |
11 |
Correct |
5 ms |
620 KB |
Output is correct |
12 |
Correct |
5 ms |
620 KB |
Output is correct |
13 |
Correct |
5 ms |
620 KB |
Output is correct |
14 |
Correct |
5 ms |
620 KB |
Output is correct |
15 |
Correct |
5 ms |
620 KB |
Output is correct |
16 |
Correct |
5 ms |
620 KB |
Output is correct |
17 |
Correct |
5 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
6 ms |
620 KB |
Output is correct |
4 |
Correct |
6 ms |
620 KB |
Output is correct |
5 |
Correct |
6 ms |
620 KB |
Output is correct |
6 |
Correct |
5 ms |
620 KB |
Output is correct |
7 |
Correct |
5 ms |
492 KB |
Output is correct |
8 |
Correct |
6 ms |
620 KB |
Output is correct |
9 |
Correct |
7 ms |
620 KB |
Output is correct |
10 |
Correct |
5 ms |
620 KB |
Output is correct |
11 |
Correct |
5 ms |
620 KB |
Output is correct |
12 |
Correct |
5 ms |
620 KB |
Output is correct |
13 |
Correct |
5 ms |
620 KB |
Output is correct |
14 |
Correct |
5 ms |
620 KB |
Output is correct |
15 |
Correct |
5 ms |
620 KB |
Output is correct |
16 |
Correct |
5 ms |
620 KB |
Output is correct |
17 |
Correct |
5 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
620 KB |
Output is correct |
19 |
Correct |
21 ms |
1280 KB |
Output is correct |
20 |
Correct |
25 ms |
1276 KB |
Output is correct |
21 |
Correct |
23 ms |
1260 KB |
Output is correct |
22 |
Correct |
24 ms |
1260 KB |
Output is correct |
23 |
Correct |
23 ms |
1260 KB |
Output is correct |
24 |
Correct |
22 ms |
1260 KB |
Output is correct |
25 |
Correct |
22 ms |
1260 KB |
Output is correct |
26 |
Correct |
22 ms |
1388 KB |
Output is correct |
27 |
Correct |
22 ms |
1260 KB |
Output is correct |
28 |
Correct |
21 ms |
1260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
1512 KB |
Output is correct |
2 |
Correct |
106 ms |
3144 KB |
Output is correct |
3 |
Correct |
199 ms |
5432 KB |
Output is correct |
4 |
Correct |
198 ms |
5472 KB |
Output is correct |
5 |
Correct |
198 ms |
5344 KB |
Output is correct |
6 |
Correct |
194 ms |
5600 KB |
Output is correct |
7 |
Correct |
188 ms |
5472 KB |
Output is correct |
8 |
Correct |
190 ms |
5344 KB |
Output is correct |
9 |
Correct |
192 ms |
5448 KB |
Output is correct |
10 |
Correct |
156 ms |
4448 KB |
Output is correct |
11 |
Correct |
150 ms |
4448 KB |
Output is correct |
12 |
Correct |
145 ms |
4448 KB |
Output is correct |
13 |
Correct |
145 ms |
4448 KB |
Output is correct |
14 |
Correct |
143 ms |
4448 KB |
Output is correct |
15 |
Correct |
143 ms |
4576 KB |
Output is correct |
16 |
Correct |
139 ms |
4448 KB |
Output is correct |
17 |
Correct |
147 ms |
4448 KB |
Output is correct |
18 |
Correct |
145 ms |
4448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
6 ms |
620 KB |
Output is correct |
4 |
Correct |
6 ms |
620 KB |
Output is correct |
5 |
Correct |
6 ms |
620 KB |
Output is correct |
6 |
Correct |
5 ms |
620 KB |
Output is correct |
7 |
Correct |
5 ms |
492 KB |
Output is correct |
8 |
Correct |
6 ms |
620 KB |
Output is correct |
9 |
Correct |
7 ms |
620 KB |
Output is correct |
10 |
Correct |
5 ms |
620 KB |
Output is correct |
11 |
Correct |
5 ms |
620 KB |
Output is correct |
12 |
Correct |
5 ms |
620 KB |
Output is correct |
13 |
Correct |
5 ms |
620 KB |
Output is correct |
14 |
Correct |
5 ms |
620 KB |
Output is correct |
15 |
Correct |
5 ms |
620 KB |
Output is correct |
16 |
Correct |
5 ms |
620 KB |
Output is correct |
17 |
Correct |
5 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
620 KB |
Output is correct |
19 |
Correct |
21 ms |
1280 KB |
Output is correct |
20 |
Correct |
25 ms |
1276 KB |
Output is correct |
21 |
Correct |
23 ms |
1260 KB |
Output is correct |
22 |
Correct |
24 ms |
1260 KB |
Output is correct |
23 |
Correct |
23 ms |
1260 KB |
Output is correct |
24 |
Correct |
22 ms |
1260 KB |
Output is correct |
25 |
Correct |
22 ms |
1260 KB |
Output is correct |
26 |
Correct |
22 ms |
1388 KB |
Output is correct |
27 |
Correct |
22 ms |
1260 KB |
Output is correct |
28 |
Correct |
21 ms |
1260 KB |
Output is correct |
29 |
Correct |
36 ms |
1512 KB |
Output is correct |
30 |
Correct |
106 ms |
3144 KB |
Output is correct |
31 |
Correct |
199 ms |
5432 KB |
Output is correct |
32 |
Correct |
198 ms |
5472 KB |
Output is correct |
33 |
Correct |
198 ms |
5344 KB |
Output is correct |
34 |
Correct |
194 ms |
5600 KB |
Output is correct |
35 |
Correct |
188 ms |
5472 KB |
Output is correct |
36 |
Correct |
190 ms |
5344 KB |
Output is correct |
37 |
Correct |
192 ms |
5448 KB |
Output is correct |
38 |
Correct |
156 ms |
4448 KB |
Output is correct |
39 |
Correct |
150 ms |
4448 KB |
Output is correct |
40 |
Correct |
145 ms |
4448 KB |
Output is correct |
41 |
Correct |
145 ms |
4448 KB |
Output is correct |
42 |
Correct |
143 ms |
4448 KB |
Output is correct |
43 |
Correct |
143 ms |
4576 KB |
Output is correct |
44 |
Correct |
139 ms |
4448 KB |
Output is correct |
45 |
Correct |
147 ms |
4448 KB |
Output is correct |
46 |
Correct |
145 ms |
4448 KB |
Output is correct |
47 |
Correct |
734 ms |
19672 KB |
Output is correct |
48 |
Correct |
2782 ms |
50632 KB |
Output is correct |
49 |
Correct |
3036 ms |
53476 KB |
Output is correct |
50 |
Correct |
3022 ms |
53192 KB |
Output is correct |
51 |
Correct |
3062 ms |
53192 KB |
Output is correct |
52 |
Correct |
3136 ms |
53576 KB |
Output is correct |
53 |
Correct |
3061 ms |
53192 KB |
Output is correct |
54 |
Correct |
2775 ms |
53576 KB |
Output is correct |
55 |
Correct |
2957 ms |
53444 KB |
Output is correct |
56 |
Correct |
2769 ms |
53496 KB |
Output is correct |
57 |
Correct |
3040 ms |
53552 KB |
Output is correct |
58 |
Correct |
2760 ms |
53572 KB |
Output is correct |
59 |
Correct |
2507 ms |
52296 KB |
Output is correct |
60 |
Correct |
2601 ms |
52244 KB |
Output is correct |
61 |
Correct |
2523 ms |
52084 KB |
Output is correct |
62 |
Correct |
2389 ms |
52092 KB |
Output is correct |
63 |
Correct |
2390 ms |
52044 KB |
Output is correct |
64 |
Correct |
2408 ms |
51924 KB |
Output is correct |
65 |
Correct |
2208 ms |
51916 KB |
Output is correct |
66 |
Correct |
2195 ms |
51820 KB |
Output is correct |
67 |
Correct |
2213 ms |
51980 KB |
Output is correct |