#include "bubblesort2.h"
#include<bits/stdc++.h>
#define ll long long
#define MOD 10000000007
using namespace std;
int N,Q,sz;
int ST[6000009],tag[6000009];
void push(int p,int l,int r)
{
if(r == l+1) return;
tag[p*2] += tag[p];
tag[p*2+1] += tag[p];
ST[p*2] += tag[p];
ST[p*2+1] += tag[p];
tag[p] = 0;
return;
}
void Build(int p,int l,int r)
{
ST[p] = 0;
if(r == l + 1) return;
int mid = (l + r)/2;
Build(p*2,l,mid);
Build(p*2+1,mid,r);
}
void Modify(int p,int l,int r,int ql,int qr,int k)
{
if(l >= ql && r <= qr)
{
tag[p] += k;
ST[p] += k;
return;
}
if(l >= qr || r <= ql) return;
push(p,l,r);
int mid = (l + r)/2;
Modify(p*2,l,mid,ql,qr,k);
Modify(p*2+1,mid,r,ql,qr,k);
ST[p] = max(ST[p*2+1],ST[p*2]);
}
vector<int> countScans(vector<int> A,vector<int> X,vector<int> V)
{
int i;
vector<int> ans;
N = A.size();
Q = X.size();
vector<ll> v;
for(i = 0;i < N;i++) v.push_back((ll)A[i]*(ll)MOD + (ll)i);
for(i = 0;i < Q;i++) v.push_back((ll)V[i]*(ll)MOD + (ll)X[i]);
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
sz = v.size() + 20;
for(i = 0;i < N;i++)
{
A[i] = lower_bound(v.begin(),v.end(),(ll)A[i]*(ll)MOD + (ll)i) - v.begin() + 1;
}
for(i = 0;i < Q;i++)
{
V[i] = lower_bound(v.begin(),v.end(),(ll)V[i]*(ll)MOD + (ll)X[i]) - v.begin() + 1;
}
Build(1,0,sz);
for(i = 0;i < N;i++)
{
Modify(1,0,sz,A[i],A[i]+1,i);
}
for(i = 0;i < N;i++)
{
Modify(1,0,sz,A[i]+1,sz,-1);
}
for(i = 0;i < Q;i++)
{
int x = X[i],v = V[i];
Modify(1,0,sz,A[x]+1,sz,1);
Modify(1,0,sz,v+1,sz,-1);
Modify(1,0,sz,A[x],A[x]+1,-x);
Modify(1,0,sz,v,v+1,x);
A[x] = v;
//cout << ST[1] << endl;
ans.push_back(ST[1]);
assert(ST[1] >= 0);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
9 ms |
512 KB |
Output is correct |
4 |
Correct |
8 ms |
512 KB |
Output is correct |
5 |
Correct |
9 ms |
512 KB |
Output is correct |
6 |
Correct |
9 ms |
640 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
9 ms |
512 KB |
Output is correct |
9 |
Correct |
9 ms |
640 KB |
Output is correct |
10 |
Correct |
9 ms |
512 KB |
Output is correct |
11 |
Correct |
9 ms |
640 KB |
Output is correct |
12 |
Correct |
9 ms |
512 KB |
Output is correct |
13 |
Correct |
12 ms |
512 KB |
Output is correct |
14 |
Correct |
9 ms |
512 KB |
Output is correct |
15 |
Correct |
9 ms |
640 KB |
Output is correct |
16 |
Correct |
9 ms |
512 KB |
Output is correct |
17 |
Correct |
9 ms |
512 KB |
Output is correct |
18 |
Correct |
9 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
9 ms |
512 KB |
Output is correct |
4 |
Correct |
8 ms |
512 KB |
Output is correct |
5 |
Correct |
9 ms |
512 KB |
Output is correct |
6 |
Correct |
9 ms |
640 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
9 ms |
512 KB |
Output is correct |
9 |
Correct |
9 ms |
640 KB |
Output is correct |
10 |
Correct |
9 ms |
512 KB |
Output is correct |
11 |
Correct |
9 ms |
640 KB |
Output is correct |
12 |
Correct |
9 ms |
512 KB |
Output is correct |
13 |
Correct |
12 ms |
512 KB |
Output is correct |
14 |
Correct |
9 ms |
512 KB |
Output is correct |
15 |
Correct |
9 ms |
640 KB |
Output is correct |
16 |
Correct |
9 ms |
512 KB |
Output is correct |
17 |
Correct |
9 ms |
512 KB |
Output is correct |
18 |
Correct |
9 ms |
640 KB |
Output is correct |
19 |
Correct |
21 ms |
1152 KB |
Output is correct |
20 |
Correct |
24 ms |
1280 KB |
Output is correct |
21 |
Correct |
22 ms |
1280 KB |
Output is correct |
22 |
Correct |
23 ms |
1280 KB |
Output is correct |
23 |
Correct |
23 ms |
1152 KB |
Output is correct |
24 |
Correct |
22 ms |
1280 KB |
Output is correct |
25 |
Correct |
21 ms |
1152 KB |
Output is correct |
26 |
Correct |
22 ms |
1152 KB |
Output is correct |
27 |
Correct |
22 ms |
1152 KB |
Output is correct |
28 |
Correct |
21 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
1532 KB |
Output is correct |
2 |
Correct |
80 ms |
3184 KB |
Output is correct |
3 |
Correct |
142 ms |
5356 KB |
Output is correct |
4 |
Correct |
139 ms |
5356 KB |
Output is correct |
5 |
Correct |
132 ms |
5356 KB |
Output is correct |
6 |
Correct |
129 ms |
5356 KB |
Output is correct |
7 |
Correct |
137 ms |
5484 KB |
Output is correct |
8 |
Correct |
130 ms |
5384 KB |
Output is correct |
9 |
Correct |
130 ms |
5228 KB |
Output is correct |
10 |
Correct |
114 ms |
4460 KB |
Output is correct |
11 |
Correct |
111 ms |
4460 KB |
Output is correct |
12 |
Correct |
120 ms |
4460 KB |
Output is correct |
13 |
Correct |
118 ms |
4536 KB |
Output is correct |
14 |
Correct |
106 ms |
4404 KB |
Output is correct |
15 |
Correct |
112 ms |
4460 KB |
Output is correct |
16 |
Correct |
115 ms |
4460 KB |
Output is correct |
17 |
Correct |
115 ms |
4436 KB |
Output is correct |
18 |
Correct |
108 ms |
4460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
9 ms |
512 KB |
Output is correct |
4 |
Correct |
8 ms |
512 KB |
Output is correct |
5 |
Correct |
9 ms |
512 KB |
Output is correct |
6 |
Correct |
9 ms |
640 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
9 ms |
512 KB |
Output is correct |
9 |
Correct |
9 ms |
640 KB |
Output is correct |
10 |
Correct |
9 ms |
512 KB |
Output is correct |
11 |
Correct |
9 ms |
640 KB |
Output is correct |
12 |
Correct |
9 ms |
512 KB |
Output is correct |
13 |
Correct |
12 ms |
512 KB |
Output is correct |
14 |
Correct |
9 ms |
512 KB |
Output is correct |
15 |
Correct |
9 ms |
640 KB |
Output is correct |
16 |
Correct |
9 ms |
512 KB |
Output is correct |
17 |
Correct |
9 ms |
512 KB |
Output is correct |
18 |
Correct |
9 ms |
640 KB |
Output is correct |
19 |
Correct |
21 ms |
1152 KB |
Output is correct |
20 |
Correct |
24 ms |
1280 KB |
Output is correct |
21 |
Correct |
22 ms |
1280 KB |
Output is correct |
22 |
Correct |
23 ms |
1280 KB |
Output is correct |
23 |
Correct |
23 ms |
1152 KB |
Output is correct |
24 |
Correct |
22 ms |
1280 KB |
Output is correct |
25 |
Correct |
21 ms |
1152 KB |
Output is correct |
26 |
Correct |
22 ms |
1152 KB |
Output is correct |
27 |
Correct |
22 ms |
1152 KB |
Output is correct |
28 |
Correct |
21 ms |
1152 KB |
Output is correct |
29 |
Correct |
30 ms |
1532 KB |
Output is correct |
30 |
Correct |
80 ms |
3184 KB |
Output is correct |
31 |
Correct |
142 ms |
5356 KB |
Output is correct |
32 |
Correct |
139 ms |
5356 KB |
Output is correct |
33 |
Correct |
132 ms |
5356 KB |
Output is correct |
34 |
Correct |
129 ms |
5356 KB |
Output is correct |
35 |
Correct |
137 ms |
5484 KB |
Output is correct |
36 |
Correct |
130 ms |
5384 KB |
Output is correct |
37 |
Correct |
130 ms |
5228 KB |
Output is correct |
38 |
Correct |
114 ms |
4460 KB |
Output is correct |
39 |
Correct |
111 ms |
4460 KB |
Output is correct |
40 |
Correct |
120 ms |
4460 KB |
Output is correct |
41 |
Correct |
118 ms |
4536 KB |
Output is correct |
42 |
Correct |
106 ms |
4404 KB |
Output is correct |
43 |
Correct |
112 ms |
4460 KB |
Output is correct |
44 |
Correct |
115 ms |
4460 KB |
Output is correct |
45 |
Correct |
115 ms |
4436 KB |
Output is correct |
46 |
Correct |
108 ms |
4460 KB |
Output is correct |
47 |
Correct |
528 ms |
19596 KB |
Output is correct |
48 |
Correct |
2001 ms |
50772 KB |
Output is correct |
49 |
Correct |
2117 ms |
53504 KB |
Output is correct |
50 |
Correct |
2154 ms |
53276 KB |
Output is correct |
51 |
Correct |
2110 ms |
53332 KB |
Output is correct |
52 |
Correct |
2148 ms |
53332 KB |
Output is correct |
53 |
Correct |
2073 ms |
53588 KB |
Output is correct |
54 |
Correct |
1993 ms |
53432 KB |
Output is correct |
55 |
Correct |
2178 ms |
53472 KB |
Output is correct |
56 |
Correct |
1847 ms |
53320 KB |
Output is correct |
57 |
Correct |
1921 ms |
53396 KB |
Output is correct |
58 |
Correct |
1798 ms |
53328 KB |
Output is correct |
59 |
Correct |
1715 ms |
52044 KB |
Output is correct |
60 |
Correct |
1687 ms |
52068 KB |
Output is correct |
61 |
Correct |
1715 ms |
52220 KB |
Output is correct |
62 |
Correct |
1662 ms |
52040 KB |
Output is correct |
63 |
Correct |
1605 ms |
51928 KB |
Output is correct |
64 |
Correct |
1616 ms |
51936 KB |
Output is correct |
65 |
Correct |
1612 ms |
51868 KB |
Output is correct |
66 |
Correct |
1628 ms |
52040 KB |
Output is correct |
67 |
Correct |
1656 ms |
51944 KB |
Output is correct |