#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
int n,nn=0,ma=1e9,inf=1e9;
multiset<int> ms[1000069];
struct segtree
{
int l,r,mx,lz,pst;
segtree *p[2];
void bd(int lh,int rh)
{
int ii;
l=lh;
r=rh;
mx=-inf;
lz=0;
if(l==r)
{
nn++;
pst=nn;
}
for(ii=0;ii<2;ii++)
{
p[ii]=0;
}
}
void blc()
{
int ii,md=(l+r)/2;
for(ii=0;ii<2;ii++)
{
if(!p[ii])
{
p[ii]=new segtree;
p[ii]->bd(!ii?l:md+1,!ii?md:r);
}
p[ii]->mx+=lz;
p[ii]->lz+=lz;
}
lz=0;
}
void ud(int lh,int rh,int w)
{
if(l>rh||r<lh);
else if(l>=lh&&r<=rh)
{
mx+=w;
lz+=w;
}
else
{
int ii;
blc();
for(ii=0;ii<2;ii++)
{
p[ii]->ud(lh,rh,w);
}
mx=max(p[0]->mx,p[1]->mx);
}
}
void ins(int x,int w)
{
if(l>x||r<x);
else if(l>=x&&r<=x)
{
ms[pst].insert(w);
mx=*prev(ms[pst].end())+lz;
}
else
{
int ii;
blc();
for(ii=0;ii<2;ii++)
{
p[ii]->ins(x,w);
}
mx=max(p[0]->mx,p[1]->mx);
}
}
void ers(int x,int w)
{
if(l>x||r<x);
else if(l>=x&&r<=x)
{
ms[pst].erase(ms[pst].find(w));
if(!ms[pst].empty())
{
mx=*prev(ms[pst].end())+lz;
}
else
{
mx=-inf;
}
}
else
{
int ii;
blc();
for(ii=0;ii<2;ii++)
{
p[ii]->ers(x,w);
}
mx=max(p[0]->mx,p[1]->mx);
}
}
}
sg;
vector<int> countScans(vector<int> a,vector<int> qp,vector<int> qw)
{
int t=qp.size(),rr,i,k,w;
vector<int> sq;
n=a.size();
sg.bd(1,ma);
for(i=0;i<n;i++)
{
sg.ins(a[i],i+1-n);
sg.ud(1,a[i]-1,1);
}
for(rr=0;rr<t;rr++)
{
k=qp[rr];
w=qw[rr];
sg.ers(a[k],k+1-n);
sg.ud(1,a[k]-1,-1);
a[k]=w;
sg.ins(w,k+1-n);
sg.ud(1,w-1,1);
sq.push_back(sg.mx);
}
return sq;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
49272 KB |
Output is correct |
2 |
Correct |
40 ms |
50304 KB |
Output is correct |
3 |
Correct |
50 ms |
53880 KB |
Output is correct |
4 |
Correct |
50 ms |
53880 KB |
Output is correct |
5 |
Correct |
49 ms |
53624 KB |
Output is correct |
6 |
Correct |
50 ms |
53784 KB |
Output is correct |
7 |
Correct |
49 ms |
53752 KB |
Output is correct |
8 |
Correct |
51 ms |
53752 KB |
Output is correct |
9 |
Correct |
50 ms |
53624 KB |
Output is correct |
10 |
Correct |
46 ms |
51704 KB |
Output is correct |
11 |
Correct |
46 ms |
51832 KB |
Output is correct |
12 |
Correct |
46 ms |
51712 KB |
Output is correct |
13 |
Correct |
46 ms |
51320 KB |
Output is correct |
14 |
Correct |
46 ms |
51328 KB |
Output is correct |
15 |
Correct |
46 ms |
51320 KB |
Output is correct |
16 |
Correct |
47 ms |
50936 KB |
Output is correct |
17 |
Correct |
45 ms |
50936 KB |
Output is correct |
18 |
Correct |
45 ms |
51072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
49272 KB |
Output is correct |
2 |
Correct |
40 ms |
50304 KB |
Output is correct |
3 |
Correct |
50 ms |
53880 KB |
Output is correct |
4 |
Correct |
50 ms |
53880 KB |
Output is correct |
5 |
Correct |
49 ms |
53624 KB |
Output is correct |
6 |
Correct |
50 ms |
53784 KB |
Output is correct |
7 |
Correct |
49 ms |
53752 KB |
Output is correct |
8 |
Correct |
51 ms |
53752 KB |
Output is correct |
9 |
Correct |
50 ms |
53624 KB |
Output is correct |
10 |
Correct |
46 ms |
51704 KB |
Output is correct |
11 |
Correct |
46 ms |
51832 KB |
Output is correct |
12 |
Correct |
46 ms |
51712 KB |
Output is correct |
13 |
Correct |
46 ms |
51320 KB |
Output is correct |
14 |
Correct |
46 ms |
51328 KB |
Output is correct |
15 |
Correct |
46 ms |
51320 KB |
Output is correct |
16 |
Correct |
47 ms |
50936 KB |
Output is correct |
17 |
Correct |
45 ms |
50936 KB |
Output is correct |
18 |
Correct |
45 ms |
51072 KB |
Output is correct |
19 |
Correct |
99 ms |
68092 KB |
Output is correct |
20 |
Correct |
111 ms |
70648 KB |
Output is correct |
21 |
Correct |
108 ms |
70264 KB |
Output is correct |
22 |
Correct |
104 ms |
69752 KB |
Output is correct |
23 |
Correct |
91 ms |
63224 KB |
Output is correct |
24 |
Correct |
93 ms |
63224 KB |
Output is correct |
25 |
Correct |
90 ms |
61816 KB |
Output is correct |
26 |
Correct |
88 ms |
61792 KB |
Output is correct |
27 |
Correct |
95 ms |
60408 KB |
Output is correct |
28 |
Correct |
87 ms |
60536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
48888 KB |
Output is correct |
2 |
Correct |
163 ms |
50168 KB |
Output is correct |
3 |
Correct |
265 ms |
51448 KB |
Output is correct |
4 |
Correct |
251 ms |
51448 KB |
Output is correct |
5 |
Correct |
246 ms |
51448 KB |
Output is correct |
6 |
Correct |
280 ms |
51576 KB |
Output is correct |
7 |
Correct |
253 ms |
51448 KB |
Output is correct |
8 |
Correct |
249 ms |
51560 KB |
Output is correct |
9 |
Correct |
248 ms |
51436 KB |
Output is correct |
10 |
Correct |
224 ms |
51448 KB |
Output is correct |
11 |
Correct |
229 ms |
51448 KB |
Output is correct |
12 |
Correct |
228 ms |
51448 KB |
Output is correct |
13 |
Correct |
221 ms |
51448 KB |
Output is correct |
14 |
Correct |
219 ms |
51448 KB |
Output is correct |
15 |
Correct |
220 ms |
51448 KB |
Output is correct |
16 |
Correct |
237 ms |
51448 KB |
Output is correct |
17 |
Correct |
216 ms |
51448 KB |
Output is correct |
18 |
Correct |
212 ms |
51576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
49272 KB |
Output is correct |
2 |
Correct |
40 ms |
50304 KB |
Output is correct |
3 |
Correct |
50 ms |
53880 KB |
Output is correct |
4 |
Correct |
50 ms |
53880 KB |
Output is correct |
5 |
Correct |
49 ms |
53624 KB |
Output is correct |
6 |
Correct |
50 ms |
53784 KB |
Output is correct |
7 |
Correct |
49 ms |
53752 KB |
Output is correct |
8 |
Correct |
51 ms |
53752 KB |
Output is correct |
9 |
Correct |
50 ms |
53624 KB |
Output is correct |
10 |
Correct |
46 ms |
51704 KB |
Output is correct |
11 |
Correct |
46 ms |
51832 KB |
Output is correct |
12 |
Correct |
46 ms |
51712 KB |
Output is correct |
13 |
Correct |
46 ms |
51320 KB |
Output is correct |
14 |
Correct |
46 ms |
51328 KB |
Output is correct |
15 |
Correct |
46 ms |
51320 KB |
Output is correct |
16 |
Correct |
47 ms |
50936 KB |
Output is correct |
17 |
Correct |
45 ms |
50936 KB |
Output is correct |
18 |
Correct |
45 ms |
51072 KB |
Output is correct |
19 |
Correct |
99 ms |
68092 KB |
Output is correct |
20 |
Correct |
111 ms |
70648 KB |
Output is correct |
21 |
Correct |
108 ms |
70264 KB |
Output is correct |
22 |
Correct |
104 ms |
69752 KB |
Output is correct |
23 |
Correct |
91 ms |
63224 KB |
Output is correct |
24 |
Correct |
93 ms |
63224 KB |
Output is correct |
25 |
Correct |
90 ms |
61816 KB |
Output is correct |
26 |
Correct |
88 ms |
61792 KB |
Output is correct |
27 |
Correct |
95 ms |
60408 KB |
Output is correct |
28 |
Correct |
87 ms |
60536 KB |
Output is correct |
29 |
Correct |
75 ms |
48888 KB |
Output is correct |
30 |
Correct |
163 ms |
50168 KB |
Output is correct |
31 |
Correct |
265 ms |
51448 KB |
Output is correct |
32 |
Correct |
251 ms |
51448 KB |
Output is correct |
33 |
Correct |
246 ms |
51448 KB |
Output is correct |
34 |
Correct |
280 ms |
51576 KB |
Output is correct |
35 |
Correct |
253 ms |
51448 KB |
Output is correct |
36 |
Correct |
249 ms |
51560 KB |
Output is correct |
37 |
Correct |
248 ms |
51436 KB |
Output is correct |
38 |
Correct |
224 ms |
51448 KB |
Output is correct |
39 |
Correct |
229 ms |
51448 KB |
Output is correct |
40 |
Correct |
228 ms |
51448 KB |
Output is correct |
41 |
Correct |
221 ms |
51448 KB |
Output is correct |
42 |
Correct |
219 ms |
51448 KB |
Output is correct |
43 |
Correct |
220 ms |
51448 KB |
Output is correct |
44 |
Correct |
237 ms |
51448 KB |
Output is correct |
45 |
Correct |
216 ms |
51448 KB |
Output is correct |
46 |
Correct |
212 ms |
51576 KB |
Output is correct |
47 |
Correct |
1494 ms |
362136 KB |
Output is correct |
48 |
Runtime error |
1902 ms |
524292 KB |
Execution killed with signal 9 |
49 |
Halted |
0 ms |
0 KB |
- |