# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
203831 |
2020-02-22T12:12:56 Z |
Sorting |
Tenis (COI19_tenis) |
C++14 |
|
239 ms |
10912 KB |
#include <bits/stdc++.h>
using namespace std;
const int kNMax = 1e5 + 7;
struct segment_tree{
pair<int, int> nodes[4 * kNMax];
int lazy[4 * kNMax];
segment_tree(){}
void build(int idx, int l, int r){
if(l == r){
nodes[idx] = {l, l};
return;
}
int mid = (l + r) >> 1;
build(2 * idx, l, mid);
build(2 * idx + 1, mid + 1, r);
nodes[idx] = min(nodes[2 * idx], nodes[2 * idx + 1]);
}
void update(int idx, int l, int r, int sl, int sr, int val){
if(lazy[idx]){
nodes[idx].first += lazy[idx];
if(l != r){
lazy[2 * idx] += lazy[idx];
lazy[2 * idx + 1] += lazy[idx];
}
lazy[idx] = 0;
}
if(sl > r || l > sr)
return;
if(sl <= l && r <= sr){
nodes[idx].first += val;
if(l != r){
lazy[2 * idx] += val;
lazy[2 * idx + 1] += val;
}
return;
}
int mid = (l + r) >> 1;
update(2 * idx, l, mid, sl, sr, val);
update(2 * idx + 1, mid + 1, r, sl, sr, val);
nodes[idx] = min(nodes[2 * idx], nodes[2 * idx + 1]);
}
int query(){
return nodes[1].second;
}
};
int n, q;
int a[3][kNMax], mx[kNMax], pos[3][kNMax];
int cnt[kNMax];
segment_tree seg_tr;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q;
for(int i = 0; i < 3; ++i){
for(int j = 1; j <= n; ++j){
cin >> a[i][j];
pos[i][a[i][j]] = j;
}
}
for(int i = 1; i <= n; ++i){
mx[i] = 0;
for(int j = 0; j < 3; ++j)
mx[i] = max(mx[i], pos[j][i]);
++cnt[mx[i]];
}
seg_tr.build(1, 1, n);
for(int i = 1; i <= n; ++i){
seg_tr.update(1, 1, n, i, n, -cnt[i]);
}
int border = seg_tr.query();
for(int i = 0; i < q; ++i){
int type;
cin >> type;
if(type == 1){
int x;
cin >> x;
if(mx[x] <= border)
cout << "DA\n";
else
cout << "NE\n";
}
else{
int p, a, b;
cin >> p >> a >> b;
--p;
swap(pos[p][a], pos[p][b]);
int pr_mx_a = mx[a], pr_mx_b = mx[b];
mx[a] = 0;
mx[b] = 0;
for(int j = 0; j < 3; ++j){
mx[a] = max(mx[a], pos[j][a]);
mx[b] = max(mx[b], pos[j][b]);
}
array<int, 4> changed = {pr_mx_a, pr_mx_b, mx[a], mx[b]};
sort(changed.begin(), changed.end());
for(int i = 0; i < 4; ++i){
if(i == 0 || changed[i] != changed[i - 1])
seg_tr.update(1, 1, n, changed[i], n, cnt[changed[i]]);
}
--cnt[pr_mx_a];
--cnt[pr_mx_b];
++cnt[mx[a]];
++cnt[mx[b]];
for(int i = 0; i < 4; ++i){
if(i == 0 || changed[i] != changed[i - 1])
seg_tr.update(1, 1, n, changed[i], n, -cnt[changed[i]]);
}
border = seg_tr.query();
}
}
}
/*
4 2
1 2 3 4
2 1 3 4
2 4 3 1
1 1
1 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3448 KB |
Output is correct |
2 |
Correct |
6 ms |
3448 KB |
Output is correct |
3 |
Correct |
6 ms |
3448 KB |
Output is correct |
4 |
Correct |
6 ms |
3448 KB |
Output is correct |
5 |
Correct |
6 ms |
3448 KB |
Output is correct |
6 |
Correct |
6 ms |
3452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3448 KB |
Output is correct |
2 |
Correct |
6 ms |
3448 KB |
Output is correct |
3 |
Correct |
6 ms |
3448 KB |
Output is correct |
4 |
Correct |
6 ms |
3448 KB |
Output is correct |
5 |
Correct |
6 ms |
3448 KB |
Output is correct |
6 |
Correct |
6 ms |
3452 KB |
Output is correct |
7 |
Correct |
7 ms |
3576 KB |
Output is correct |
8 |
Correct |
7 ms |
3576 KB |
Output is correct |
9 |
Correct |
7 ms |
3576 KB |
Output is correct |
10 |
Correct |
7 ms |
3576 KB |
Output is correct |
11 |
Correct |
7 ms |
3580 KB |
Output is correct |
12 |
Correct |
7 ms |
3572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3448 KB |
Output is correct |
2 |
Correct |
6 ms |
3448 KB |
Output is correct |
3 |
Correct |
6 ms |
3448 KB |
Output is correct |
4 |
Correct |
6 ms |
3448 KB |
Output is correct |
5 |
Correct |
6 ms |
3448 KB |
Output is correct |
6 |
Correct |
6 ms |
3452 KB |
Output is correct |
7 |
Correct |
7 ms |
3576 KB |
Output is correct |
8 |
Correct |
7 ms |
3576 KB |
Output is correct |
9 |
Correct |
7 ms |
3576 KB |
Output is correct |
10 |
Correct |
7 ms |
3576 KB |
Output is correct |
11 |
Correct |
7 ms |
3580 KB |
Output is correct |
12 |
Correct |
7 ms |
3572 KB |
Output is correct |
13 |
Correct |
64 ms |
7672 KB |
Output is correct |
14 |
Correct |
63 ms |
9336 KB |
Output is correct |
15 |
Correct |
60 ms |
9336 KB |
Output is correct |
16 |
Correct |
62 ms |
9336 KB |
Output is correct |
17 |
Correct |
69 ms |
9336 KB |
Output is correct |
18 |
Correct |
68 ms |
9336 KB |
Output is correct |
19 |
Correct |
64 ms |
9336 KB |
Output is correct |
20 |
Correct |
66 ms |
9336 KB |
Output is correct |
21 |
Correct |
62 ms |
9336 KB |
Output is correct |
22 |
Correct |
67 ms |
9336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
7928 KB |
Output is correct |
2 |
Correct |
92 ms |
10468 KB |
Output is correct |
3 |
Correct |
88 ms |
10488 KB |
Output is correct |
4 |
Correct |
86 ms |
10492 KB |
Output is correct |
5 |
Correct |
88 ms |
10488 KB |
Output is correct |
6 |
Correct |
91 ms |
10488 KB |
Output is correct |
7 |
Correct |
97 ms |
10360 KB |
Output is correct |
8 |
Correct |
89 ms |
10488 KB |
Output is correct |
9 |
Correct |
92 ms |
10360 KB |
Output is correct |
10 |
Correct |
85 ms |
10360 KB |
Output is correct |
11 |
Correct |
90 ms |
10464 KB |
Output is correct |
12 |
Correct |
88 ms |
10476 KB |
Output is correct |
13 |
Correct |
87 ms |
10488 KB |
Output is correct |
14 |
Correct |
88 ms |
10360 KB |
Output is correct |
15 |
Correct |
90 ms |
10488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3448 KB |
Output is correct |
2 |
Correct |
6 ms |
3448 KB |
Output is correct |
3 |
Correct |
6 ms |
3448 KB |
Output is correct |
4 |
Correct |
6 ms |
3448 KB |
Output is correct |
5 |
Correct |
6 ms |
3448 KB |
Output is correct |
6 |
Correct |
6 ms |
3452 KB |
Output is correct |
7 |
Correct |
7 ms |
3576 KB |
Output is correct |
8 |
Correct |
7 ms |
3576 KB |
Output is correct |
9 |
Correct |
7 ms |
3576 KB |
Output is correct |
10 |
Correct |
7 ms |
3576 KB |
Output is correct |
11 |
Correct |
7 ms |
3580 KB |
Output is correct |
12 |
Correct |
7 ms |
3572 KB |
Output is correct |
13 |
Correct |
64 ms |
7672 KB |
Output is correct |
14 |
Correct |
63 ms |
9336 KB |
Output is correct |
15 |
Correct |
60 ms |
9336 KB |
Output is correct |
16 |
Correct |
62 ms |
9336 KB |
Output is correct |
17 |
Correct |
69 ms |
9336 KB |
Output is correct |
18 |
Correct |
68 ms |
9336 KB |
Output is correct |
19 |
Correct |
64 ms |
9336 KB |
Output is correct |
20 |
Correct |
66 ms |
9336 KB |
Output is correct |
21 |
Correct |
62 ms |
9336 KB |
Output is correct |
22 |
Correct |
67 ms |
9336 KB |
Output is correct |
23 |
Correct |
89 ms |
7928 KB |
Output is correct |
24 |
Correct |
92 ms |
10468 KB |
Output is correct |
25 |
Correct |
88 ms |
10488 KB |
Output is correct |
26 |
Correct |
86 ms |
10492 KB |
Output is correct |
27 |
Correct |
88 ms |
10488 KB |
Output is correct |
28 |
Correct |
91 ms |
10488 KB |
Output is correct |
29 |
Correct |
97 ms |
10360 KB |
Output is correct |
30 |
Correct |
89 ms |
10488 KB |
Output is correct |
31 |
Correct |
92 ms |
10360 KB |
Output is correct |
32 |
Correct |
85 ms |
10360 KB |
Output is correct |
33 |
Correct |
90 ms |
10464 KB |
Output is correct |
34 |
Correct |
88 ms |
10476 KB |
Output is correct |
35 |
Correct |
87 ms |
10488 KB |
Output is correct |
36 |
Correct |
88 ms |
10360 KB |
Output is correct |
37 |
Correct |
90 ms |
10488 KB |
Output is correct |
38 |
Correct |
233 ms |
10744 KB |
Output is correct |
39 |
Correct |
111 ms |
10488 KB |
Output is correct |
40 |
Correct |
239 ms |
10744 KB |
Output is correct |
41 |
Correct |
128 ms |
10616 KB |
Output is correct |
42 |
Correct |
133 ms |
10616 KB |
Output is correct |
43 |
Correct |
222 ms |
10748 KB |
Output is correct |
44 |
Correct |
110 ms |
10616 KB |
Output is correct |
45 |
Correct |
139 ms |
10616 KB |
Output is correct |
46 |
Correct |
114 ms |
10488 KB |
Output is correct |
47 |
Correct |
126 ms |
10616 KB |
Output is correct |
48 |
Correct |
114 ms |
10616 KB |
Output is correct |
49 |
Correct |
135 ms |
10616 KB |
Output is correct |
50 |
Correct |
107 ms |
10488 KB |
Output is correct |
51 |
Correct |
128 ms |
10616 KB |
Output is correct |
52 |
Correct |
215 ms |
10744 KB |
Output is correct |
53 |
Correct |
119 ms |
10616 KB |
Output is correct |
54 |
Correct |
123 ms |
10636 KB |
Output is correct |
55 |
Correct |
143 ms |
10912 KB |
Output is correct |
56 |
Correct |
129 ms |
10616 KB |
Output is correct |
57 |
Correct |
113 ms |
10488 KB |
Output is correct |
58 |
Correct |
159 ms |
10616 KB |
Output is correct |