#include <bits/stdc++.h>
using namespace std;
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V);
typedef long long ll;
const int maxn=5e5+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll
#ifdef HNO2
#define IOS
#else
#include <bubblesort2.h>
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2
vector<ll> values;
ll a[maxn];
ll x[maxn],v[maxn];
const int C=1e8;
struct segtree
{
int seg[maxn*2*4],tag[maxn*2*4];
void init()
{
memset(seg,0,sizeof(seg));
memset(tag,0,sizeof(tag));
}
void push(int now,int l,int r)
{
if (l==r||tag[now]==0)
{
tag[now]=0;
return;
}
seg[now*2]+=tag[now];
tag[now*2]+=tag[now];
seg[now*2+1]+=tag[now];
tag[now*2+1]+=tag[now];
tag[now]=0;
}
void modify(int now,int l,int r,int ql,int qr,int vv)
{
if (l>=ql&&r<=qr)
{
seg[now]+=vv;
tag[now]+=vv;
return;
}
int m=(l+r)>>1;
push(now,l,r);
if (ql<=m) modify(now*2,l,m,ql,qr,vv);
if (qr>m) modify(now*2+1,m+1,r,ql,qr,vv);
seg[now]=max(seg[now*2],seg[now*2+1]);
}
int query()
{
return seg[1];
}
}tree;
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
int n=sz(A),q=sz(X);
vector<int> ans;
for (int i=1;i<=n;i++) a[i]=A[i-1]*1ll*C+i,values.pb(A[i-1]*1ll*C+i);
for (int i=1;i<=q;i++)
{
x[i]=X[i-1]+1;
v[i]=V[i-1]*1ll*C+(X[i-1]+1);
values.pb(V[i-1]*1ll*C+(X[i-1]+1));
}
//values.pb(-1);
sort(all(values));
values.resize(unique(all(values))-values.begin());
for (int i=1;i<=n;i++) a[i]=lower_bound(all(values),a[i])-values.begin()+1;
for (int i=1;i<=q;i++) v[i]=lower_bound(all(values),v[i])-values.begin()+1;
int N=sz(values);
tree.init();
for (int i=1;i<=N;i++) tree.modify(1,1,N,i,i,-C+(values[i-1]%C));
for (int i=1;i<=n;i++)
{
tree.modify(1,1,N,a[i],a[i],C);
if (a[i]!=N) tree.modify(1,1,N,a[i]+1,N,-1);
}
for (int i=1;i<=q;i++)
{
if (a[x[i]]!=N) tree.modify(1,1,N,a[x[i]]+1,N,1);
tree.modify(1,1,N,a[x[i]],a[x[i]],-C);
a[x[i]]=v[i];
if (a[x[i]]!=N) tree.modify(1,1,N,a[x[i]]+1,N,-1);
tree.modify(1,1,N,a[x[i]],a[x[i]],C);
ans.pb(tree.query()-1);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
31736 KB |
Output is correct |
2 |
Correct |
23 ms |
31736 KB |
Output is correct |
3 |
Correct |
26 ms |
31864 KB |
Output is correct |
4 |
Correct |
26 ms |
31864 KB |
Output is correct |
5 |
Correct |
28 ms |
31864 KB |
Output is correct |
6 |
Correct |
25 ms |
31864 KB |
Output is correct |
7 |
Correct |
25 ms |
31864 KB |
Output is correct |
8 |
Correct |
26 ms |
31864 KB |
Output is correct |
9 |
Correct |
25 ms |
31864 KB |
Output is correct |
10 |
Correct |
25 ms |
31864 KB |
Output is correct |
11 |
Correct |
26 ms |
31864 KB |
Output is correct |
12 |
Correct |
25 ms |
31864 KB |
Output is correct |
13 |
Correct |
25 ms |
31864 KB |
Output is correct |
14 |
Correct |
25 ms |
31864 KB |
Output is correct |
15 |
Correct |
26 ms |
31864 KB |
Output is correct |
16 |
Correct |
25 ms |
31864 KB |
Output is correct |
17 |
Correct |
25 ms |
31864 KB |
Output is correct |
18 |
Correct |
25 ms |
31900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
31736 KB |
Output is correct |
2 |
Correct |
23 ms |
31736 KB |
Output is correct |
3 |
Correct |
26 ms |
31864 KB |
Output is correct |
4 |
Correct |
26 ms |
31864 KB |
Output is correct |
5 |
Correct |
28 ms |
31864 KB |
Output is correct |
6 |
Correct |
25 ms |
31864 KB |
Output is correct |
7 |
Correct |
25 ms |
31864 KB |
Output is correct |
8 |
Correct |
26 ms |
31864 KB |
Output is correct |
9 |
Correct |
25 ms |
31864 KB |
Output is correct |
10 |
Correct |
25 ms |
31864 KB |
Output is correct |
11 |
Correct |
26 ms |
31864 KB |
Output is correct |
12 |
Correct |
25 ms |
31864 KB |
Output is correct |
13 |
Correct |
25 ms |
31864 KB |
Output is correct |
14 |
Correct |
25 ms |
31864 KB |
Output is correct |
15 |
Correct |
26 ms |
31864 KB |
Output is correct |
16 |
Correct |
25 ms |
31864 KB |
Output is correct |
17 |
Correct |
25 ms |
31864 KB |
Output is correct |
18 |
Correct |
25 ms |
31900 KB |
Output is correct |
19 |
Correct |
38 ms |
32388 KB |
Output is correct |
20 |
Correct |
42 ms |
32504 KB |
Output is correct |
21 |
Correct |
41 ms |
32504 KB |
Output is correct |
22 |
Correct |
41 ms |
32504 KB |
Output is correct |
23 |
Correct |
39 ms |
32504 KB |
Output is correct |
24 |
Correct |
39 ms |
32504 KB |
Output is correct |
25 |
Correct |
38 ms |
32504 KB |
Output is correct |
26 |
Correct |
39 ms |
32504 KB |
Output is correct |
27 |
Correct |
39 ms |
32504 KB |
Output is correct |
28 |
Correct |
39 ms |
32504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
32628 KB |
Output is correct |
2 |
Correct |
97 ms |
34048 KB |
Output is correct |
3 |
Correct |
151 ms |
35820 KB |
Output is correct |
4 |
Correct |
155 ms |
35820 KB |
Output is correct |
5 |
Correct |
158 ms |
35820 KB |
Output is correct |
6 |
Correct |
148 ms |
35820 KB |
Output is correct |
7 |
Correct |
155 ms |
35820 KB |
Output is correct |
8 |
Correct |
151 ms |
35820 KB |
Output is correct |
9 |
Correct |
150 ms |
35820 KB |
Output is correct |
10 |
Correct |
124 ms |
35948 KB |
Output is correct |
11 |
Correct |
127 ms |
35964 KB |
Output is correct |
12 |
Correct |
124 ms |
35948 KB |
Output is correct |
13 |
Correct |
124 ms |
35944 KB |
Output is correct |
14 |
Correct |
121 ms |
35948 KB |
Output is correct |
15 |
Correct |
127 ms |
35896 KB |
Output is correct |
16 |
Correct |
137 ms |
35948 KB |
Output is correct |
17 |
Correct |
119 ms |
35948 KB |
Output is correct |
18 |
Correct |
117 ms |
35948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
31736 KB |
Output is correct |
2 |
Correct |
23 ms |
31736 KB |
Output is correct |
3 |
Correct |
26 ms |
31864 KB |
Output is correct |
4 |
Correct |
26 ms |
31864 KB |
Output is correct |
5 |
Correct |
28 ms |
31864 KB |
Output is correct |
6 |
Correct |
25 ms |
31864 KB |
Output is correct |
7 |
Correct |
25 ms |
31864 KB |
Output is correct |
8 |
Correct |
26 ms |
31864 KB |
Output is correct |
9 |
Correct |
25 ms |
31864 KB |
Output is correct |
10 |
Correct |
25 ms |
31864 KB |
Output is correct |
11 |
Correct |
26 ms |
31864 KB |
Output is correct |
12 |
Correct |
25 ms |
31864 KB |
Output is correct |
13 |
Correct |
25 ms |
31864 KB |
Output is correct |
14 |
Correct |
25 ms |
31864 KB |
Output is correct |
15 |
Correct |
26 ms |
31864 KB |
Output is correct |
16 |
Correct |
25 ms |
31864 KB |
Output is correct |
17 |
Correct |
25 ms |
31864 KB |
Output is correct |
18 |
Correct |
25 ms |
31900 KB |
Output is correct |
19 |
Correct |
38 ms |
32388 KB |
Output is correct |
20 |
Correct |
42 ms |
32504 KB |
Output is correct |
21 |
Correct |
41 ms |
32504 KB |
Output is correct |
22 |
Correct |
41 ms |
32504 KB |
Output is correct |
23 |
Correct |
39 ms |
32504 KB |
Output is correct |
24 |
Correct |
39 ms |
32504 KB |
Output is correct |
25 |
Correct |
38 ms |
32504 KB |
Output is correct |
26 |
Correct |
39 ms |
32504 KB |
Output is correct |
27 |
Correct |
39 ms |
32504 KB |
Output is correct |
28 |
Correct |
39 ms |
32504 KB |
Output is correct |
29 |
Correct |
48 ms |
32628 KB |
Output is correct |
30 |
Correct |
97 ms |
34048 KB |
Output is correct |
31 |
Correct |
151 ms |
35820 KB |
Output is correct |
32 |
Correct |
155 ms |
35820 KB |
Output is correct |
33 |
Correct |
158 ms |
35820 KB |
Output is correct |
34 |
Correct |
148 ms |
35820 KB |
Output is correct |
35 |
Correct |
155 ms |
35820 KB |
Output is correct |
36 |
Correct |
151 ms |
35820 KB |
Output is correct |
37 |
Correct |
150 ms |
35820 KB |
Output is correct |
38 |
Correct |
124 ms |
35948 KB |
Output is correct |
39 |
Correct |
127 ms |
35964 KB |
Output is correct |
40 |
Correct |
124 ms |
35948 KB |
Output is correct |
41 |
Correct |
124 ms |
35944 KB |
Output is correct |
42 |
Correct |
121 ms |
35948 KB |
Output is correct |
43 |
Correct |
127 ms |
35896 KB |
Output is correct |
44 |
Correct |
137 ms |
35948 KB |
Output is correct |
45 |
Correct |
119 ms |
35948 KB |
Output is correct |
46 |
Correct |
117 ms |
35948 KB |
Output is correct |
47 |
Correct |
509 ms |
46224 KB |
Output is correct |
48 |
Correct |
1980 ms |
76500 KB |
Output is correct |
49 |
Correct |
2195 ms |
80008 KB |
Output is correct |
50 |
Correct |
2138 ms |
79900 KB |
Output is correct |
51 |
Correct |
2164 ms |
79992 KB |
Output is correct |
52 |
Correct |
2122 ms |
79876 KB |
Output is correct |
53 |
Correct |
2120 ms |
79828 KB |
Output is correct |
54 |
Correct |
2003 ms |
79948 KB |
Output is correct |
55 |
Correct |
2082 ms |
79992 KB |
Output is correct |
56 |
Correct |
1920 ms |
80092 KB |
Output is correct |
57 |
Correct |
2083 ms |
80084 KB |
Output is correct |
58 |
Correct |
1926 ms |
79956 KB |
Output is correct |
59 |
Correct |
1817 ms |
78804 KB |
Output is correct |
60 |
Correct |
1852 ms |
78676 KB |
Output is correct |
61 |
Correct |
1860 ms |
78676 KB |
Output is correct |
62 |
Correct |
1698 ms |
78552 KB |
Output is correct |
63 |
Correct |
1735 ms |
78676 KB |
Output is correct |
64 |
Correct |
1732 ms |
78460 KB |
Output is correct |
65 |
Correct |
1598 ms |
78412 KB |
Output is correct |
66 |
Correct |
1620 ms |
78420 KB |
Output is correct |
67 |
Correct |
1626 ms |
78392 KB |
Output is correct |