#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL
const int N = 1000002;
int tree[4 * N];
int valu[4 * N];
int push[4 * N];
int act[4 * N];
void Push(int V, int L, int M, int R)
{
tree[2 * V + 1] += push[V];
valu[2 * V + 1] += push[V];
push[2 * V + 1] += push[V];
tree[2 * V + 2] += push[V];
valu[2 * V + 2] += push[V];
push[2 * V + 2] += push[V];
push[V] = 0;
if (L + 1 == M && !act[2 * V + 1]) tree[2 * V + 1] = 0;
if (M + 1 == R && !act[2 * V + 2]) tree[2 * V + 2] = 0;
}
void Active(int pos, int L = 0, int R = N, int V = 0)
{
if (L + 1 == R)
{
act[V] ^= 1;
if (act[V]) tree[V] = valu[V];
else tree[V] = 0;
return;
}
int M = (L + R) / 2;
Push(V, L, M, R);
if (pos < M) Active(pos, L, M, 2 * V + 1);
else Active(pos, M, R, 2 * V + 2);
tree[V] = max(tree[2 * V + 1], tree[2 * V + 2]);
}
void Add(int l, int r, int x, int L = 0, int R = N, int V = 0)
{
if (l <= L && R <= r)
{
tree[V] += x;
valu[V] += x;
push[V] += x;
if (L + 1 == R && !act[V]) tree[V] = 0;
return;
}
if (R <= l || r <= L)
{
return;
}
int M = (L + R) / 2;
Push(V, L, M, R);
Add(l, r, x, L, M, 2 * V + 1);
Add(l, r, x, M, R, 2 * V + 2);
tree[V] = max(tree[2 * V + 1], tree[2 * V + 2]);
}
int Get()
{
return tree[0];
}
vi countScans(vi a, vi x, vi v)
{
vector<pair<int, int> > elems;
int n = a.size();
int q = x.size();
for (int i = 0; i < n; i++)
{
elems.push_back({a[i], i});
}
for (int i = 0; i < q; i++)
{
elems.push_back({v[i], x[i]});
}
uniq(elems);
map<pii, int> mm;
for (int i = 0; i < elems.size(); i++)
{
mm[elems[i]] = i;
}
for (int i = 0; i < elems.size(); i++)
{
Add(i, i + 1, elems[i].second);
}
for (int i = 0; i < n; i++)
{
a[i] = mm[{a[i], i}];
Active(a[i]);
Add(a[i] + 1, elems.size(), -1);
}
vi ans(q);
for (int i = 0; i < q; i++)
{
int pos = x[i];
Add(a[pos] + 1, elems.size(), 1);
Active(a[pos]);
a[pos] = v[i];
a[pos] = mm[{a[pos], pos}];
Active(a[pos]);
Add(a[pos] + 1, elems.size(), -1);
ans[i] = Get();
}
return ans;
}
#ifdef LOCAL
signed main()
{
int n, q;
cin >> n >> q;
vi a(n), x(q), v(q);
forn(i, n) cin >> a[i];
forn(i, q) cin >> x[i] >> v[i];
vi ans = countScans(a, x, v);
forn(i, q) cout << ans[i] << "\n";
}
#endif // LOCAL
/*
4 2
1 2 3 4
0 3
2 1
10 20
1 2 3 4 5 1 2 3 4 5
0 10
1 9
2 8
3 7
4 6
5 5
6 4
7 3
8 2
9 1
0 10
1 9
2 8
3 7
4 6
5 5
6 4
7 3
8 2
9 1
*/
Compilation message
bubblesort2.cpp: In function 'vi countScans(vi, vi, vi)':
bubblesort2.cpp:108:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < elems.size(); i++)
~~^~~~~~~~~~~~~~
bubblesort2.cpp:112:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < elems.size(); i++)
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Correct |
8 ms |
1024 KB |
Output is correct |
4 |
Correct |
8 ms |
1024 KB |
Output is correct |
5 |
Correct |
9 ms |
896 KB |
Output is correct |
6 |
Correct |
9 ms |
1024 KB |
Output is correct |
7 |
Correct |
8 ms |
896 KB |
Output is correct |
8 |
Correct |
8 ms |
896 KB |
Output is correct |
9 |
Correct |
8 ms |
896 KB |
Output is correct |
10 |
Correct |
7 ms |
896 KB |
Output is correct |
11 |
Correct |
9 ms |
896 KB |
Output is correct |
12 |
Correct |
8 ms |
968 KB |
Output is correct |
13 |
Correct |
7 ms |
896 KB |
Output is correct |
14 |
Correct |
7 ms |
896 KB |
Output is correct |
15 |
Correct |
9 ms |
896 KB |
Output is correct |
16 |
Correct |
8 ms |
896 KB |
Output is correct |
17 |
Correct |
7 ms |
896 KB |
Output is correct |
18 |
Correct |
7 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Correct |
8 ms |
1024 KB |
Output is correct |
4 |
Correct |
8 ms |
1024 KB |
Output is correct |
5 |
Correct |
9 ms |
896 KB |
Output is correct |
6 |
Correct |
9 ms |
1024 KB |
Output is correct |
7 |
Correct |
8 ms |
896 KB |
Output is correct |
8 |
Correct |
8 ms |
896 KB |
Output is correct |
9 |
Correct |
8 ms |
896 KB |
Output is correct |
10 |
Correct |
7 ms |
896 KB |
Output is correct |
11 |
Correct |
9 ms |
896 KB |
Output is correct |
12 |
Correct |
8 ms |
968 KB |
Output is correct |
13 |
Correct |
7 ms |
896 KB |
Output is correct |
14 |
Correct |
7 ms |
896 KB |
Output is correct |
15 |
Correct |
9 ms |
896 KB |
Output is correct |
16 |
Correct |
8 ms |
896 KB |
Output is correct |
17 |
Correct |
7 ms |
896 KB |
Output is correct |
18 |
Correct |
7 ms |
896 KB |
Output is correct |
19 |
Correct |
31 ms |
2176 KB |
Output is correct |
20 |
Correct |
34 ms |
2304 KB |
Output is correct |
21 |
Correct |
34 ms |
2304 KB |
Output is correct |
22 |
Correct |
34 ms |
2304 KB |
Output is correct |
23 |
Correct |
34 ms |
2168 KB |
Output is correct |
24 |
Correct |
33 ms |
2176 KB |
Output is correct |
25 |
Correct |
33 ms |
2048 KB |
Output is correct |
26 |
Correct |
35 ms |
2048 KB |
Output is correct |
27 |
Correct |
32 ms |
1920 KB |
Output is correct |
28 |
Correct |
31 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
3700 KB |
Output is correct |
2 |
Correct |
154 ms |
7716 KB |
Output is correct |
3 |
Correct |
315 ms |
12028 KB |
Output is correct |
4 |
Correct |
298 ms |
12424 KB |
Output is correct |
5 |
Correct |
275 ms |
12396 KB |
Output is correct |
6 |
Correct |
296 ms |
12436 KB |
Output is correct |
7 |
Correct |
277 ms |
12268 KB |
Output is correct |
8 |
Correct |
384 ms |
12300 KB |
Output is correct |
9 |
Correct |
295 ms |
12268 KB |
Output is correct |
10 |
Correct |
213 ms |
8304 KB |
Output is correct |
11 |
Correct |
205 ms |
8428 KB |
Output is correct |
12 |
Correct |
204 ms |
8428 KB |
Output is correct |
13 |
Correct |
198 ms |
8428 KB |
Output is correct |
14 |
Correct |
203 ms |
8428 KB |
Output is correct |
15 |
Correct |
201 ms |
8428 KB |
Output is correct |
16 |
Correct |
186 ms |
8428 KB |
Output is correct |
17 |
Correct |
185 ms |
8428 KB |
Output is correct |
18 |
Correct |
195 ms |
8428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Correct |
8 ms |
1024 KB |
Output is correct |
4 |
Correct |
8 ms |
1024 KB |
Output is correct |
5 |
Correct |
9 ms |
896 KB |
Output is correct |
6 |
Correct |
9 ms |
1024 KB |
Output is correct |
7 |
Correct |
8 ms |
896 KB |
Output is correct |
8 |
Correct |
8 ms |
896 KB |
Output is correct |
9 |
Correct |
8 ms |
896 KB |
Output is correct |
10 |
Correct |
7 ms |
896 KB |
Output is correct |
11 |
Correct |
9 ms |
896 KB |
Output is correct |
12 |
Correct |
8 ms |
968 KB |
Output is correct |
13 |
Correct |
7 ms |
896 KB |
Output is correct |
14 |
Correct |
7 ms |
896 KB |
Output is correct |
15 |
Correct |
9 ms |
896 KB |
Output is correct |
16 |
Correct |
8 ms |
896 KB |
Output is correct |
17 |
Correct |
7 ms |
896 KB |
Output is correct |
18 |
Correct |
7 ms |
896 KB |
Output is correct |
19 |
Correct |
31 ms |
2176 KB |
Output is correct |
20 |
Correct |
34 ms |
2304 KB |
Output is correct |
21 |
Correct |
34 ms |
2304 KB |
Output is correct |
22 |
Correct |
34 ms |
2304 KB |
Output is correct |
23 |
Correct |
34 ms |
2168 KB |
Output is correct |
24 |
Correct |
33 ms |
2176 KB |
Output is correct |
25 |
Correct |
33 ms |
2048 KB |
Output is correct |
26 |
Correct |
35 ms |
2048 KB |
Output is correct |
27 |
Correct |
32 ms |
1920 KB |
Output is correct |
28 |
Correct |
31 ms |
1920 KB |
Output is correct |
29 |
Correct |
53 ms |
3700 KB |
Output is correct |
30 |
Correct |
154 ms |
7716 KB |
Output is correct |
31 |
Correct |
315 ms |
12028 KB |
Output is correct |
32 |
Correct |
298 ms |
12424 KB |
Output is correct |
33 |
Correct |
275 ms |
12396 KB |
Output is correct |
34 |
Correct |
296 ms |
12436 KB |
Output is correct |
35 |
Correct |
277 ms |
12268 KB |
Output is correct |
36 |
Correct |
384 ms |
12300 KB |
Output is correct |
37 |
Correct |
295 ms |
12268 KB |
Output is correct |
38 |
Correct |
213 ms |
8304 KB |
Output is correct |
39 |
Correct |
205 ms |
8428 KB |
Output is correct |
40 |
Correct |
204 ms |
8428 KB |
Output is correct |
41 |
Correct |
198 ms |
8428 KB |
Output is correct |
42 |
Correct |
203 ms |
8428 KB |
Output is correct |
43 |
Correct |
201 ms |
8428 KB |
Output is correct |
44 |
Correct |
186 ms |
8428 KB |
Output is correct |
45 |
Correct |
185 ms |
8428 KB |
Output is correct |
46 |
Correct |
195 ms |
8428 KB |
Output is correct |
47 |
Correct |
1163 ms |
38376 KB |
Output is correct |
48 |
Correct |
4415 ms |
117540 KB |
Output is correct |
49 |
Correct |
4492 ms |
128240 KB |
Output is correct |
50 |
Correct |
4575 ms |
128212 KB |
Output is correct |
51 |
Correct |
4468 ms |
128440 KB |
Output is correct |
52 |
Correct |
4697 ms |
128320 KB |
Output is correct |
53 |
Correct |
4781 ms |
128212 KB |
Output is correct |
54 |
Incorrect |
4430 ms |
128492 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |