#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)i);
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
sz = v.size() + 5;
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)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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
8 ms |
376 KB |
Output is correct |
3 |
Correct |
10 ms |
504 KB |
Output is correct |
4 |
Correct |
9 ms |
504 KB |
Output is correct |
5 |
Correct |
10 ms |
504 KB |
Output is correct |
6 |
Correct |
10 ms |
504 KB |
Output is correct |
7 |
Correct |
9 ms |
504 KB |
Output is correct |
8 |
Correct |
11 ms |
504 KB |
Output is correct |
9 |
Correct |
9 ms |
504 KB |
Output is correct |
10 |
Correct |
11 ms |
504 KB |
Output is correct |
11 |
Correct |
9 ms |
504 KB |
Output is correct |
12 |
Correct |
11 ms |
504 KB |
Output is correct |
13 |
Correct |
9 ms |
504 KB |
Output is correct |
14 |
Correct |
10 ms |
504 KB |
Output is correct |
15 |
Correct |
9 ms |
504 KB |
Output is correct |
16 |
Correct |
10 ms |
504 KB |
Output is correct |
17 |
Correct |
10 ms |
504 KB |
Output is correct |
18 |
Correct |
9 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
8 ms |
376 KB |
Output is correct |
3 |
Correct |
10 ms |
504 KB |
Output is correct |
4 |
Correct |
9 ms |
504 KB |
Output is correct |
5 |
Correct |
10 ms |
504 KB |
Output is correct |
6 |
Correct |
10 ms |
504 KB |
Output is correct |
7 |
Correct |
9 ms |
504 KB |
Output is correct |
8 |
Correct |
11 ms |
504 KB |
Output is correct |
9 |
Correct |
9 ms |
504 KB |
Output is correct |
10 |
Correct |
11 ms |
504 KB |
Output is correct |
11 |
Correct |
9 ms |
504 KB |
Output is correct |
12 |
Correct |
11 ms |
504 KB |
Output is correct |
13 |
Correct |
9 ms |
504 KB |
Output is correct |
14 |
Correct |
10 ms |
504 KB |
Output is correct |
15 |
Correct |
9 ms |
504 KB |
Output is correct |
16 |
Correct |
10 ms |
504 KB |
Output is correct |
17 |
Correct |
10 ms |
504 KB |
Output is correct |
18 |
Correct |
9 ms |
504 KB |
Output is correct |
19 |
Correct |
21 ms |
1016 KB |
Output is correct |
20 |
Correct |
25 ms |
1016 KB |
Output is correct |
21 |
Correct |
23 ms |
1016 KB |
Output is correct |
22 |
Correct |
23 ms |
1020 KB |
Output is correct |
23 |
Correct |
24 ms |
1016 KB |
Output is correct |
24 |
Correct |
23 ms |
1020 KB |
Output is correct |
25 |
Correct |
25 ms |
1016 KB |
Output is correct |
26 |
Correct |
28 ms |
1016 KB |
Output is correct |
27 |
Correct |
23 ms |
1016 KB |
Output is correct |
28 |
Correct |
22 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
1524 KB |
Output is correct |
2 |
Incorrect |
84 ms |
2800 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
8 ms |
376 KB |
Output is correct |
3 |
Correct |
10 ms |
504 KB |
Output is correct |
4 |
Correct |
9 ms |
504 KB |
Output is correct |
5 |
Correct |
10 ms |
504 KB |
Output is correct |
6 |
Correct |
10 ms |
504 KB |
Output is correct |
7 |
Correct |
9 ms |
504 KB |
Output is correct |
8 |
Correct |
11 ms |
504 KB |
Output is correct |
9 |
Correct |
9 ms |
504 KB |
Output is correct |
10 |
Correct |
11 ms |
504 KB |
Output is correct |
11 |
Correct |
9 ms |
504 KB |
Output is correct |
12 |
Correct |
11 ms |
504 KB |
Output is correct |
13 |
Correct |
9 ms |
504 KB |
Output is correct |
14 |
Correct |
10 ms |
504 KB |
Output is correct |
15 |
Correct |
9 ms |
504 KB |
Output is correct |
16 |
Correct |
10 ms |
504 KB |
Output is correct |
17 |
Correct |
10 ms |
504 KB |
Output is correct |
18 |
Correct |
9 ms |
504 KB |
Output is correct |
19 |
Correct |
21 ms |
1016 KB |
Output is correct |
20 |
Correct |
25 ms |
1016 KB |
Output is correct |
21 |
Correct |
23 ms |
1016 KB |
Output is correct |
22 |
Correct |
23 ms |
1020 KB |
Output is correct |
23 |
Correct |
24 ms |
1016 KB |
Output is correct |
24 |
Correct |
23 ms |
1020 KB |
Output is correct |
25 |
Correct |
25 ms |
1016 KB |
Output is correct |
26 |
Correct |
28 ms |
1016 KB |
Output is correct |
27 |
Correct |
23 ms |
1016 KB |
Output is correct |
28 |
Correct |
22 ms |
1016 KB |
Output is correct |
29 |
Correct |
31 ms |
1524 KB |
Output is correct |
30 |
Incorrect |
84 ms |
2800 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |