#pragma g++ optimize("Ofast")
#include <bits/stdc++.h>
#define pb emplace_back
#define get_pos(u,x) (lower_bound(begin(u),end(u),x) - begin(u))
using namespace std;
const int N = 1000025;
struct Segtree {
int n;
vector<int> mx, lz;
void init(int v[], int _n) {
n = _n;
mx.resize(n*2), lz.resize(n);
for(int i = 0; i < n; i++) mx[i+n] = v[i], lz[i] = 0;
for(int i = n-1; i > 0; i--) mx[i] = max(mx[i<<1], mx[i<<1|1]);
}
void upd(int p, int d) {
mx[p] += d;
if(p < n) lz[p] += d;
}
void pull(int p) {
for(; p>1; p>>=1) mx[p>>1] = max(mx[p],mx[p^1]) + lz[p>>1];
}
void push(int p) {
for(int h = __lg(n); h >= 0; h--) {
int i = p>>h;
if(!lz[i>>1]) continue;
upd(i,lz[i>>1]);
upd(i^1,lz[i>>1]);
lz[i>>1] = 0;
}
}
void add(int l, int r, int d) {
int L = l, R = r;
for(l+=n,r+=n; l<r; l>>=1,r>>=1) {
if(l&1) upd(l++, d);
if(r&1) upd(--r, d);
}
pull(L+n), pull(R-1+n);
}
int query(int l, int r) {
int res = 0;
push(l+n), push(r-1+n);
for(l+=n,r+=n; l<r; l>>=1,r>>=1) {
if(l&1) res = max(res, mx[l++]);
if(r&1) res = max(res, mx[--r]);
}
return res;
}
/*void dbg() {
cout << "-------\n";
for(int i = 0; i < 10; i++) {
push(i+N);
cout << mx[i+N] << ' ';
}
cout << '\n';
}*/
} sgt;
int S[N];
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
int n = A.size(), q = X.size();
vector<pair<long long,int>> u;
for(int i = 0; i < n; i++) u.pb(1LL * A[i] * N + i, i);
for(int i = 0; i < q; i++) u.pb(1LL * V[i] * N + X[i], i+n);
sort(u.begin(), u.end());
long long last = u.front().first;
int j = 0;
for(auto [val, id]: u) {
if(val != last) ++j;
if(id < n)
A[id] = j;
else
V[id-n] = j;
last = val;
}
++j;
vector<int> Q(q);
/*for(int i = 0; i < n; i++) {
sgt.add(A[i], A[i]+1, i);
sgt.add(A[i]+1, j, -1);
}*/
for(int i = 0; i < n; i++) --S[A[i]+1];
for(int i = 1; i < N; i++) S[i] += S[i-1];
for(int i = 0; i < n; i++) S[A[i]] += i;
sgt.init(S, N);
for(int i = 0; i < q; i++) {
int x = X[i];
sgt.add(A[x],A[x]+1, -x);
sgt.add(A[x]+1, N, 1);
A[x] = V[i];
sgt.add(A[x],A[x]+1, x);
sgt.add(A[x]+1, N, -1);
//sgt.dbg();
Q[i] = sgt.mx[1];
}
return Q;
}
/*
*/
Compilation message
bubblesort2.cpp:1:0: warning: ignoring #pragma g [-Wunknown-pragmas]
#pragma g++ optimize("Ofast")
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:69:14: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
for(auto [val, id]: u) {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
16128 KB |
Output is correct |
2 |
Correct |
20 ms |
16128 KB |
Output is correct |
3 |
Correct |
22 ms |
16128 KB |
Output is correct |
4 |
Correct |
22 ms |
16128 KB |
Output is correct |
5 |
Correct |
22 ms |
16128 KB |
Output is correct |
6 |
Correct |
22 ms |
16128 KB |
Output is correct |
7 |
Correct |
22 ms |
16128 KB |
Output is correct |
8 |
Correct |
22 ms |
16128 KB |
Output is correct |
9 |
Correct |
23 ms |
16128 KB |
Output is correct |
10 |
Correct |
23 ms |
16128 KB |
Output is correct |
11 |
Correct |
22 ms |
16128 KB |
Output is correct |
12 |
Correct |
21 ms |
16128 KB |
Output is correct |
13 |
Correct |
22 ms |
16128 KB |
Output is correct |
14 |
Correct |
22 ms |
16128 KB |
Output is correct |
15 |
Correct |
22 ms |
16256 KB |
Output is correct |
16 |
Correct |
23 ms |
16256 KB |
Output is correct |
17 |
Correct |
22 ms |
16128 KB |
Output is correct |
18 |
Correct |
21 ms |
16128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
16128 KB |
Output is correct |
2 |
Correct |
20 ms |
16128 KB |
Output is correct |
3 |
Correct |
22 ms |
16128 KB |
Output is correct |
4 |
Correct |
22 ms |
16128 KB |
Output is correct |
5 |
Correct |
22 ms |
16128 KB |
Output is correct |
6 |
Correct |
22 ms |
16128 KB |
Output is correct |
7 |
Correct |
22 ms |
16128 KB |
Output is correct |
8 |
Correct |
22 ms |
16128 KB |
Output is correct |
9 |
Correct |
23 ms |
16128 KB |
Output is correct |
10 |
Correct |
23 ms |
16128 KB |
Output is correct |
11 |
Correct |
22 ms |
16128 KB |
Output is correct |
12 |
Correct |
21 ms |
16128 KB |
Output is correct |
13 |
Correct |
22 ms |
16128 KB |
Output is correct |
14 |
Correct |
22 ms |
16128 KB |
Output is correct |
15 |
Correct |
22 ms |
16256 KB |
Output is correct |
16 |
Correct |
23 ms |
16256 KB |
Output is correct |
17 |
Correct |
22 ms |
16128 KB |
Output is correct |
18 |
Correct |
21 ms |
16128 KB |
Output is correct |
19 |
Correct |
29 ms |
16508 KB |
Output is correct |
20 |
Correct |
31 ms |
16636 KB |
Output is correct |
21 |
Correct |
31 ms |
16508 KB |
Output is correct |
22 |
Correct |
30 ms |
16636 KB |
Output is correct |
23 |
Correct |
28 ms |
16636 KB |
Output is correct |
24 |
Correct |
29 ms |
16508 KB |
Output is correct |
25 |
Correct |
29 ms |
16508 KB |
Output is correct |
26 |
Correct |
29 ms |
16508 KB |
Output is correct |
27 |
Correct |
29 ms |
16508 KB |
Output is correct |
28 |
Correct |
29 ms |
16540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
16760 KB |
Output is correct |
2 |
Correct |
58 ms |
17876 KB |
Output is correct |
3 |
Correct |
87 ms |
18920 KB |
Output is correct |
4 |
Correct |
89 ms |
18920 KB |
Output is correct |
5 |
Correct |
85 ms |
18920 KB |
Output is correct |
6 |
Correct |
90 ms |
19048 KB |
Output is correct |
7 |
Correct |
89 ms |
18920 KB |
Output is correct |
8 |
Correct |
94 ms |
18920 KB |
Output is correct |
9 |
Correct |
88 ms |
18920 KB |
Output is correct |
10 |
Correct |
81 ms |
18920 KB |
Output is correct |
11 |
Correct |
86 ms |
18920 KB |
Output is correct |
12 |
Correct |
82 ms |
18920 KB |
Output is correct |
13 |
Correct |
85 ms |
19048 KB |
Output is correct |
14 |
Correct |
80 ms |
18920 KB |
Output is correct |
15 |
Correct |
79 ms |
18920 KB |
Output is correct |
16 |
Correct |
78 ms |
18920 KB |
Output is correct |
17 |
Correct |
82 ms |
18920 KB |
Output is correct |
18 |
Correct |
79 ms |
18920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
16128 KB |
Output is correct |
2 |
Correct |
20 ms |
16128 KB |
Output is correct |
3 |
Correct |
22 ms |
16128 KB |
Output is correct |
4 |
Correct |
22 ms |
16128 KB |
Output is correct |
5 |
Correct |
22 ms |
16128 KB |
Output is correct |
6 |
Correct |
22 ms |
16128 KB |
Output is correct |
7 |
Correct |
22 ms |
16128 KB |
Output is correct |
8 |
Correct |
22 ms |
16128 KB |
Output is correct |
9 |
Correct |
23 ms |
16128 KB |
Output is correct |
10 |
Correct |
23 ms |
16128 KB |
Output is correct |
11 |
Correct |
22 ms |
16128 KB |
Output is correct |
12 |
Correct |
21 ms |
16128 KB |
Output is correct |
13 |
Correct |
22 ms |
16128 KB |
Output is correct |
14 |
Correct |
22 ms |
16128 KB |
Output is correct |
15 |
Correct |
22 ms |
16256 KB |
Output is correct |
16 |
Correct |
23 ms |
16256 KB |
Output is correct |
17 |
Correct |
22 ms |
16128 KB |
Output is correct |
18 |
Correct |
21 ms |
16128 KB |
Output is correct |
19 |
Correct |
29 ms |
16508 KB |
Output is correct |
20 |
Correct |
31 ms |
16636 KB |
Output is correct |
21 |
Correct |
31 ms |
16508 KB |
Output is correct |
22 |
Correct |
30 ms |
16636 KB |
Output is correct |
23 |
Correct |
28 ms |
16636 KB |
Output is correct |
24 |
Correct |
29 ms |
16508 KB |
Output is correct |
25 |
Correct |
29 ms |
16508 KB |
Output is correct |
26 |
Correct |
29 ms |
16508 KB |
Output is correct |
27 |
Correct |
29 ms |
16508 KB |
Output is correct |
28 |
Correct |
29 ms |
16540 KB |
Output is correct |
29 |
Correct |
28 ms |
16760 KB |
Output is correct |
30 |
Correct |
58 ms |
17876 KB |
Output is correct |
31 |
Correct |
87 ms |
18920 KB |
Output is correct |
32 |
Correct |
89 ms |
18920 KB |
Output is correct |
33 |
Correct |
85 ms |
18920 KB |
Output is correct |
34 |
Correct |
90 ms |
19048 KB |
Output is correct |
35 |
Correct |
89 ms |
18920 KB |
Output is correct |
36 |
Correct |
94 ms |
18920 KB |
Output is correct |
37 |
Correct |
88 ms |
18920 KB |
Output is correct |
38 |
Correct |
81 ms |
18920 KB |
Output is correct |
39 |
Correct |
86 ms |
18920 KB |
Output is correct |
40 |
Correct |
82 ms |
18920 KB |
Output is correct |
41 |
Correct |
85 ms |
19048 KB |
Output is correct |
42 |
Correct |
80 ms |
18920 KB |
Output is correct |
43 |
Correct |
79 ms |
18920 KB |
Output is correct |
44 |
Correct |
78 ms |
18920 KB |
Output is correct |
45 |
Correct |
82 ms |
18920 KB |
Output is correct |
46 |
Correct |
79 ms |
18920 KB |
Output is correct |
47 |
Correct |
254 ms |
24660 KB |
Output is correct |
48 |
Correct |
897 ms |
43048 KB |
Output is correct |
49 |
Correct |
935 ms |
58304 KB |
Output is correct |
50 |
Correct |
963 ms |
58176 KB |
Output is correct |
51 |
Correct |
952 ms |
58304 KB |
Output is correct |
52 |
Correct |
958 ms |
58304 KB |
Output is correct |
53 |
Correct |
956 ms |
58176 KB |
Output is correct |
54 |
Correct |
935 ms |
58432 KB |
Output is correct |
55 |
Correct |
958 ms |
58440 KB |
Output is correct |
56 |
Correct |
948 ms |
58304 KB |
Output is correct |
57 |
Correct |
951 ms |
58324 KB |
Output is correct |
58 |
Correct |
937 ms |
58304 KB |
Output is correct |
59 |
Correct |
879 ms |
57152 KB |
Output is correct |
60 |
Correct |
874 ms |
57024 KB |
Output is correct |
61 |
Correct |
886 ms |
57152 KB |
Output is correct |
62 |
Correct |
853 ms |
56896 KB |
Output is correct |
63 |
Correct |
845 ms |
56896 KB |
Output is correct |
64 |
Correct |
849 ms |
56896 KB |
Output is correct |
65 |
Correct |
818 ms |
56768 KB |
Output is correct |
66 |
Correct |
813 ms |
56768 KB |
Output is correct |
67 |
Correct |
816 ms |
56848 KB |
Output is correct |