#include "bubblesort2.h"
#define INF 10000000000000
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int nr,n,i,v[500005];
map <pair <int,int> ,int> m;
long long arb[2000005],lazy[2000005];
void propaga(int st,int dr,int nod)
{
if (st==dr)
{
return;
}
if (lazy[nod]==0)
{
return;
}
lazy[2*nod]+=lazy[nod];
lazy[2*nod+1]+=lazy[nod];
arb[2*nod]+=lazy[nod];
arb[2*nod+1]+=lazy[nod];
lazy[nod]=0;
return;
}
void update(int st,int dr,int nod,int ua,int ub,long long val)
{
if (ua<=st&&dr<=ub)
{
arb[nod]+=val;
lazy[nod]+=val;
return ;
}
propaga(st,dr,nod);
int mij=(st+dr)/2;
if (ua<=mij)
{
update(st,mij,2*nod,ua,ub,val);
}
if (mij<ub)
{
update(mij+1,dr,2*nod+1,ua,ub,val);
}
arb[nod]=max(arb[2*nod],arb[2*nod+1]);
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> val){
int q=X.size();
n=A.size();
for (i=0;i<n;i++)
{
v[i+1]=A[i];
}
for (i=1;i<=n;i++)
{
m[{v[i],i}]=1;
}
for (i=0;i<q;i++)
{
m[{val[i],X[i]+1}]=1;
}
nr=0;
for (auto ind: m)
{
nr++;
m[ind.first]=nr;
}
update(1,nr,1,1,nr,-INF);
for (i=1;i<=n;i++)
{
v[i]=m[{v[i],i}];
update(1,nr,1,v[i],v[i],INF+i);
update(1,nr,1,v[i]+1,nr,-1);
}
int j;
vector <int> sol;
for (i=0;i<q;i++)
{
int poz=X[i]+1;
update(1,nr,1,v[poz],v[poz],-INF-poz);
update(1,nr,1,v[poz]+1,nr,1);
v[poz]=m[{val[i],poz}];
update(1,nr,1,v[poz],v[poz],INF+poz);
update(1,nr,1,v[poz]+1,nr,-1);
sol.push_back(arb[1]-1);
}
return sol;
}
/*int readInt(){
int i;
if(scanf("%d",&i)!=1){
fprintf(stderr,"Error while reading input\n");
exit(1);
}
return i;
}
int main(){
int N,Q;
N=readInt();
Q=readInt();
std::vector<int> A(N);
for(int i=0;i<N;i++)
A[i]=readInt();
std::vector<int> X(Q),V(Q);
for(int j=0;j<Q;j++){
X[j]=readInt();
V[j]=readInt();
}
std::vector<int> res=countScans(A,X,V);
for(int j=0;j<int(res.size());j++)
printf("%d\n",res[j]);
}*/
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:77:9: warning: unused variable 'j' [-Wunused-variable]
77 | int j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
6 ms |
716 KB |
Output is correct |
4 |
Correct |
6 ms |
716 KB |
Output is correct |
5 |
Correct |
6 ms |
716 KB |
Output is correct |
6 |
Correct |
5 ms |
764 KB |
Output is correct |
7 |
Correct |
5 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
752 KB |
Output is correct |
9 |
Correct |
6 ms |
716 KB |
Output is correct |
10 |
Correct |
5 ms |
716 KB |
Output is correct |
11 |
Correct |
6 ms |
716 KB |
Output is correct |
12 |
Correct |
7 ms |
716 KB |
Output is correct |
13 |
Correct |
5 ms |
716 KB |
Output is correct |
14 |
Correct |
5 ms |
716 KB |
Output is correct |
15 |
Correct |
5 ms |
716 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
5 ms |
588 KB |
Output is correct |
18 |
Correct |
5 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
6 ms |
716 KB |
Output is correct |
4 |
Correct |
6 ms |
716 KB |
Output is correct |
5 |
Correct |
6 ms |
716 KB |
Output is correct |
6 |
Correct |
5 ms |
764 KB |
Output is correct |
7 |
Correct |
5 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
752 KB |
Output is correct |
9 |
Correct |
6 ms |
716 KB |
Output is correct |
10 |
Correct |
5 ms |
716 KB |
Output is correct |
11 |
Correct |
6 ms |
716 KB |
Output is correct |
12 |
Correct |
7 ms |
716 KB |
Output is correct |
13 |
Correct |
5 ms |
716 KB |
Output is correct |
14 |
Correct |
5 ms |
716 KB |
Output is correct |
15 |
Correct |
5 ms |
716 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
5 ms |
588 KB |
Output is correct |
18 |
Correct |
5 ms |
596 KB |
Output is correct |
19 |
Correct |
23 ms |
1868 KB |
Output is correct |
20 |
Correct |
26 ms |
2116 KB |
Output is correct |
21 |
Correct |
25 ms |
2080 KB |
Output is correct |
22 |
Correct |
25 ms |
2100 KB |
Output is correct |
23 |
Correct |
24 ms |
1996 KB |
Output is correct |
24 |
Correct |
24 ms |
1916 KB |
Output is correct |
25 |
Correct |
27 ms |
1920 KB |
Output is correct |
26 |
Correct |
23 ms |
1920 KB |
Output is correct |
27 |
Correct |
23 ms |
1804 KB |
Output is correct |
28 |
Correct |
27 ms |
1828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
3536 KB |
Output is correct |
2 |
Correct |
122 ms |
7332 KB |
Output is correct |
3 |
Correct |
252 ms |
12468 KB |
Output is correct |
4 |
Correct |
234 ms |
12500 KB |
Output is correct |
5 |
Correct |
212 ms |
12328 KB |
Output is correct |
6 |
Correct |
265 ms |
12200 KB |
Output is correct |
7 |
Correct |
230 ms |
12168 KB |
Output is correct |
8 |
Correct |
215 ms |
12232 KB |
Output is correct |
9 |
Correct |
278 ms |
12228 KB |
Output is correct |
10 |
Correct |
157 ms |
7492 KB |
Output is correct |
11 |
Correct |
157 ms |
7428 KB |
Output is correct |
12 |
Correct |
169 ms |
7528 KB |
Output is correct |
13 |
Correct |
148 ms |
7416 KB |
Output is correct |
14 |
Correct |
142 ms |
7444 KB |
Output is correct |
15 |
Correct |
147 ms |
7480 KB |
Output is correct |
16 |
Correct |
169 ms |
7492 KB |
Output is correct |
17 |
Correct |
138 ms |
7492 KB |
Output is correct |
18 |
Correct |
137 ms |
7464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
6 ms |
716 KB |
Output is correct |
4 |
Correct |
6 ms |
716 KB |
Output is correct |
5 |
Correct |
6 ms |
716 KB |
Output is correct |
6 |
Correct |
5 ms |
764 KB |
Output is correct |
7 |
Correct |
5 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
752 KB |
Output is correct |
9 |
Correct |
6 ms |
716 KB |
Output is correct |
10 |
Correct |
5 ms |
716 KB |
Output is correct |
11 |
Correct |
6 ms |
716 KB |
Output is correct |
12 |
Correct |
7 ms |
716 KB |
Output is correct |
13 |
Correct |
5 ms |
716 KB |
Output is correct |
14 |
Correct |
5 ms |
716 KB |
Output is correct |
15 |
Correct |
5 ms |
716 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
5 ms |
588 KB |
Output is correct |
18 |
Correct |
5 ms |
596 KB |
Output is correct |
19 |
Correct |
23 ms |
1868 KB |
Output is correct |
20 |
Correct |
26 ms |
2116 KB |
Output is correct |
21 |
Correct |
25 ms |
2080 KB |
Output is correct |
22 |
Correct |
25 ms |
2100 KB |
Output is correct |
23 |
Correct |
24 ms |
1996 KB |
Output is correct |
24 |
Correct |
24 ms |
1916 KB |
Output is correct |
25 |
Correct |
27 ms |
1920 KB |
Output is correct |
26 |
Correct |
23 ms |
1920 KB |
Output is correct |
27 |
Correct |
23 ms |
1804 KB |
Output is correct |
28 |
Correct |
27 ms |
1828 KB |
Output is correct |
29 |
Correct |
42 ms |
3536 KB |
Output is correct |
30 |
Correct |
122 ms |
7332 KB |
Output is correct |
31 |
Correct |
252 ms |
12468 KB |
Output is correct |
32 |
Correct |
234 ms |
12500 KB |
Output is correct |
33 |
Correct |
212 ms |
12328 KB |
Output is correct |
34 |
Correct |
265 ms |
12200 KB |
Output is correct |
35 |
Correct |
230 ms |
12168 KB |
Output is correct |
36 |
Correct |
215 ms |
12232 KB |
Output is correct |
37 |
Correct |
278 ms |
12228 KB |
Output is correct |
38 |
Correct |
157 ms |
7492 KB |
Output is correct |
39 |
Correct |
157 ms |
7428 KB |
Output is correct |
40 |
Correct |
169 ms |
7528 KB |
Output is correct |
41 |
Correct |
148 ms |
7416 KB |
Output is correct |
42 |
Correct |
142 ms |
7444 KB |
Output is correct |
43 |
Correct |
147 ms |
7480 KB |
Output is correct |
44 |
Correct |
169 ms |
7492 KB |
Output is correct |
45 |
Correct |
138 ms |
7492 KB |
Output is correct |
46 |
Correct |
137 ms |
7464 KB |
Output is correct |
47 |
Correct |
996 ms |
40532 KB |
Output is correct |
48 |
Runtime error |
1416 ms |
524292 KB |
Execution killed with signal 9 |
49 |
Halted |
0 ms |
0 KB |
- |