#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(),v.end()
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }
const int N = 1e6 + 7;
const int Mod = 1e9 + 7;
const int INF = 2e9;
const ll BASE = 137;
int n, nval, Q;
int a[N];
pair<int, int> qr[N];
vector<pair<int,int>> vals;
struct Segment_Tree {
int m;
int st[N << 2];
int lz[N << 2];
void init (int n) {
m = n;
}
void down (int id) {
rep (i, id << 1, id << 1 | 1) {
st[i] += lz[id];
lz[i] += lz[id];
}
lz[id] = 0;
}
void update (int id, int l, int r, int u, int v, int val) {
if (l > v || r < u) return;
if (l >= u && r <= v) {
st[id] += val;
lz[id] += val;
return;
}
int mid = l + r >> 1;
down(id);
update (id << 1, l, mid, u, v, val);
update (id << 1 | 1, mid + 1, r, u, v, val);
st[id] = max(st[id << 1], st[id << 1 | 1]);
}
void update (int u, int v, int val) {
update (1, 1, m, u, v, val);
}
}ST;
int cps (pair<int,int> X) {
return lower_bound(ALL(vals), X) - vals.begin() + 1;
}
//void solution() {
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
// cin >> n;
// rep (i, 1, n) cin >> a[i];
// cin >> Q;
// rep (i, 1, Q) cin >> qr[i].fs >> qr[i].se, ++qr[i].fs;
n = SZ(A);
Q = SZ(X);
rep (i, 1, n) a[i] = A[i - 1];
rep (i, 1, Q) qr[i].fs = X[i - 1], qr[i].se = V[i - 1], ++qr[i].fs;
rep (i, 1, n) vals.push_back({a[i], i});
rep (i, 1, Q) vals.push_back({qr[i].se, qr[i].fs});
sort (ALL(vals));
vals.resize(nval = unique(ALL(vals)) - vals.begin());
rep (i, 1, n) a[i] = cps(MP(a[i], i));
rep (i, 1, Q) qr[i].se = cps(MP(qr[i].se, qr[i].fs));
ST.init(nval);
rep (i, 1, n) {
ST.update(a[i], a[i], i);
ST.update (a[i], nval, -1);
}
vector<int> Ans;
rep (i, 1, Q) {
int p, val;
tie(p, val) = qr[i];
ST.update(a[p], a[p], -p);
ST.update(a[p], nval, 1);
ST.update(val, val, p);
ST.update(val, nval, -1);
a[p] = val;
Ans.push_back(ST.st[1]);
// cout << ST.st[1].val <<"\n";
}
return Ans;
}
//#define file(name) freopen(name".inp","r",stdin); \
//freopen(name".out","w",stdout);
//int main () {
//// file("c");
// ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
// int num_Test = 1;
//// cin >> num_Test;
// while (num_Test--)
// solution();
//}
/*
no bug challenge +2
4
1 2 3 4
2
0 3
2 1
*/
Compilation message
bubblesort2.cpp:107:1: warning: multi-line comment [-Wcomment]
107 | //#define file(name) freopen(name".inp","r",stdin); \
| ^
bubblesort2.cpp: In member function 'void Segment_Tree::update(int, int, int, int, int, int)':
bubblesort2.cpp:52:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
52 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
2 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
3 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
3 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
2 ms |
4700 KB |
Output is correct |
12 |
Correct |
2 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
4700 KB |
Output is correct |
14 |
Correct |
2 ms |
4728 KB |
Output is correct |
15 |
Correct |
3 ms |
4700 KB |
Output is correct |
16 |
Correct |
3 ms |
4700 KB |
Output is correct |
17 |
Correct |
3 ms |
4700 KB |
Output is correct |
18 |
Correct |
3 ms |
4696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
2 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
3 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
3 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
2 ms |
4700 KB |
Output is correct |
12 |
Correct |
2 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
4700 KB |
Output is correct |
14 |
Correct |
2 ms |
4728 KB |
Output is correct |
15 |
Correct |
3 ms |
4700 KB |
Output is correct |
16 |
Correct |
3 ms |
4700 KB |
Output is correct |
17 |
Correct |
3 ms |
4700 KB |
Output is correct |
18 |
Correct |
3 ms |
4696 KB |
Output is correct |
19 |
Correct |
8 ms |
7256 KB |
Output is correct |
20 |
Correct |
13 ms |
7260 KB |
Output is correct |
21 |
Correct |
9 ms |
7260 KB |
Output is correct |
22 |
Correct |
9 ms |
7260 KB |
Output is correct |
23 |
Correct |
9 ms |
7256 KB |
Output is correct |
24 |
Correct |
9 ms |
7352 KB |
Output is correct |
25 |
Correct |
9 ms |
7260 KB |
Output is correct |
26 |
Correct |
8 ms |
7260 KB |
Output is correct |
27 |
Correct |
9 ms |
7260 KB |
Output is correct |
28 |
Correct |
9 ms |
7260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
9684 KB |
Output is correct |
2 |
Correct |
42 ms |
10708 KB |
Output is correct |
3 |
Correct |
63 ms |
14156 KB |
Output is correct |
4 |
Correct |
64 ms |
14024 KB |
Output is correct |
5 |
Correct |
65 ms |
14060 KB |
Output is correct |
6 |
Correct |
62 ms |
14004 KB |
Output is correct |
7 |
Correct |
62 ms |
14092 KB |
Output is correct |
8 |
Correct |
73 ms |
14024 KB |
Output is correct |
9 |
Correct |
63 ms |
14144 KB |
Output is correct |
10 |
Correct |
52 ms |
11716 KB |
Output is correct |
11 |
Correct |
53 ms |
11628 KB |
Output is correct |
12 |
Correct |
51 ms |
11716 KB |
Output is correct |
13 |
Correct |
53 ms |
11720 KB |
Output is correct |
14 |
Correct |
49 ms |
11692 KB |
Output is correct |
15 |
Correct |
49 ms |
11516 KB |
Output is correct |
16 |
Correct |
47 ms |
11680 KB |
Output is correct |
17 |
Correct |
48 ms |
11720 KB |
Output is correct |
18 |
Correct |
47 ms |
11720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
2 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
3 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
3 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
2 ms |
4700 KB |
Output is correct |
12 |
Correct |
2 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
4700 KB |
Output is correct |
14 |
Correct |
2 ms |
4728 KB |
Output is correct |
15 |
Correct |
3 ms |
4700 KB |
Output is correct |
16 |
Correct |
3 ms |
4700 KB |
Output is correct |
17 |
Correct |
3 ms |
4700 KB |
Output is correct |
18 |
Correct |
3 ms |
4696 KB |
Output is correct |
19 |
Correct |
8 ms |
7256 KB |
Output is correct |
20 |
Correct |
13 ms |
7260 KB |
Output is correct |
21 |
Correct |
9 ms |
7260 KB |
Output is correct |
22 |
Correct |
9 ms |
7260 KB |
Output is correct |
23 |
Correct |
9 ms |
7256 KB |
Output is correct |
24 |
Correct |
9 ms |
7352 KB |
Output is correct |
25 |
Correct |
9 ms |
7260 KB |
Output is correct |
26 |
Correct |
8 ms |
7260 KB |
Output is correct |
27 |
Correct |
9 ms |
7260 KB |
Output is correct |
28 |
Correct |
9 ms |
7260 KB |
Output is correct |
29 |
Correct |
15 ms |
9684 KB |
Output is correct |
30 |
Correct |
42 ms |
10708 KB |
Output is correct |
31 |
Correct |
63 ms |
14156 KB |
Output is correct |
32 |
Correct |
64 ms |
14024 KB |
Output is correct |
33 |
Correct |
65 ms |
14060 KB |
Output is correct |
34 |
Correct |
62 ms |
14004 KB |
Output is correct |
35 |
Correct |
62 ms |
14092 KB |
Output is correct |
36 |
Correct |
73 ms |
14024 KB |
Output is correct |
37 |
Correct |
63 ms |
14144 KB |
Output is correct |
38 |
Correct |
52 ms |
11716 KB |
Output is correct |
39 |
Correct |
53 ms |
11628 KB |
Output is correct |
40 |
Correct |
51 ms |
11716 KB |
Output is correct |
41 |
Correct |
53 ms |
11720 KB |
Output is correct |
42 |
Correct |
49 ms |
11692 KB |
Output is correct |
43 |
Correct |
49 ms |
11516 KB |
Output is correct |
44 |
Correct |
47 ms |
11680 KB |
Output is correct |
45 |
Correct |
48 ms |
11720 KB |
Output is correct |
46 |
Correct |
47 ms |
11720 KB |
Output is correct |
47 |
Correct |
219 ms |
24508 KB |
Output is correct |
48 |
Correct |
735 ms |
50104 KB |
Output is correct |
49 |
Correct |
810 ms |
51660 KB |
Output is correct |
50 |
Correct |
829 ms |
51892 KB |
Output is correct |
51 |
Correct |
865 ms |
51872 KB |
Output is correct |
52 |
Correct |
805 ms |
51664 KB |
Output is correct |
53 |
Correct |
788 ms |
51892 KB |
Output is correct |
54 |
Correct |
771 ms |
51660 KB |
Output is correct |
55 |
Correct |
821 ms |
51580 KB |
Output is correct |
56 |
Correct |
773 ms |
51756 KB |
Output is correct |
57 |
Correct |
800 ms |
51724 KB |
Output is correct |
58 |
Correct |
748 ms |
51632 KB |
Output is correct |
59 |
Correct |
740 ms |
51640 KB |
Output is correct |
60 |
Correct |
740 ms |
51968 KB |
Output is correct |
61 |
Correct |
762 ms |
51760 KB |
Output is correct |
62 |
Correct |
723 ms |
51724 KB |
Output is correct |
63 |
Correct |
726 ms |
52152 KB |
Output is correct |
64 |
Correct |
728 ms |
51632 KB |
Output is correct |
65 |
Correct |
797 ms |
51724 KB |
Output is correct |
66 |
Correct |
706 ms |
51916 KB |
Output is correct |
67 |
Correct |
767 ms |
51648 KB |
Output is correct |