# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
586858 |
2022-06-30T19:57:20 Z |
JovanB |
Tenis (COI19_tenis) |
C++17 |
|
157 ms |
8028 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 100000;
struct Segment{
ll sum, mn, pos;
} seg[4*N+5];
int n;
void mrg(int node){
seg[node].sum = seg[node*2].sum + seg[node*2+1].sum;
seg[node].mn = min(seg[node*2].mn, seg[node*2].sum + seg[node*2+1].mn);
if(seg[node*2].sum + seg[node*2+1].mn == seg[node].mn) seg[node].pos = seg[node*2+1].pos;
else seg[node].pos = seg[node*2].pos;
}
void init(int node, int l, int r){
if(l == r){
seg[node].mn = -2*l;
seg[node].pos = l;
seg[node].sum = -2*l;
if(l == n) seg[node].mn = 0;
return;
}
int mid = (l+r)/2;
init(node*2, l, mid);
init(node*2+1, mid+1, r);
mrg(node);
}
void upd(int node, int l, int r, int x, int v){
if(l == r){
seg[node].mn += v;
seg[node].sum += v;
return;
}
int mid = (l+r)/2;
if(x <= mid) upd(node*2, l, mid, x, v);
else upd(node*2+1, mid+1, r, x, v);
mrg(node);
}
int a[N+5], b[N+5], c[N+5];
int pa[N+5], pb[N+5], pc[N+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int qrs;
cin >> n >> qrs;
for(int i=1; i<=n; i++){
int x;
cin >> x;
pa[x] = n - i + 1;
}
init(1, 1, n);
for(int i=1; i<=n; i++){
int x;
cin >> x;
pb[x] = n - i + 1;
upd(1, 1, n, pa[x], pb[x]);
}
for(int i=1; i<=n; i++){
int x;
cin >> x;
pc[x] = n - i + 1;
upd(1, 1, n, pa[x], pc[x]);
}
while(qrs--){
int typ;
cin >> typ;
if(typ == 1){
int x;
cin >> x;
if(seg[1].mn > 0 || pa[x] > seg[1].pos) cout << "DA\n";
else cout << "NE\n";
}
else{
int p, a, b;
cin >> p >> a >> b;
if(p == 1){
upd(1, 1, n, pa[a], -pb[a]);
upd(1, 1, n, pa[a], -pc[a]);
upd(1, 1, n, pa[b], -pb[b]);
upd(1, 1, n, pa[b], -pc[b]);
swap(pa[a], pa[b]);
upd(1, 1, n, pa[a], pb[a]);
upd(1, 1, n, pa[a], pc[a]);
upd(1, 1, n, pa[b], pb[b]);
upd(1, 1, n, pa[b], pc[b]);
}
else if(p == 2){
upd(1, 1, n, pa[a], -pb[a]);
upd(1, 1, n, pa[b], -pb[b]);
swap(pb[a], pb[b]);
upd(1, 1, n, pa[a], pb[a]);
upd(1, 1, n, pa[b], pb[b]);
}
else{
upd(1, 1, n, pa[a], -pc[a]);
upd(1, 1, n, pa[b], -pc[b]);
swap(pc[a], pc[b]);
upd(1, 1, n, pa[a], pc[a]);
upd(1, 1, n, pa[b], pc[b]);
}
}
}
return 0;
}
/*
4 1
1 2 3 4
2 1 3 4
2 1 3 4
1 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
62 ms |
7644 KB |
Output is correct |
14 |
Correct |
57 ms |
7628 KB |
Output is correct |
15 |
Correct |
78 ms |
7644 KB |
Output is correct |
16 |
Correct |
52 ms |
7640 KB |
Output is correct |
17 |
Correct |
49 ms |
7644 KB |
Output is correct |
18 |
Correct |
49 ms |
7644 KB |
Output is correct |
19 |
Correct |
49 ms |
7636 KB |
Output is correct |
20 |
Correct |
51 ms |
7600 KB |
Output is correct |
21 |
Correct |
64 ms |
7528 KB |
Output is correct |
22 |
Correct |
56 ms |
7528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
7904 KB |
Output is correct |
2 |
Correct |
63 ms |
7912 KB |
Output is correct |
3 |
Correct |
69 ms |
8028 KB |
Output is correct |
4 |
Correct |
77 ms |
7904 KB |
Output is correct |
5 |
Correct |
90 ms |
7892 KB |
Output is correct |
6 |
Correct |
63 ms |
7912 KB |
Output is correct |
7 |
Correct |
69 ms |
7924 KB |
Output is correct |
8 |
Correct |
62 ms |
7904 KB |
Output is correct |
9 |
Correct |
66 ms |
7904 KB |
Output is correct |
10 |
Correct |
82 ms |
7916 KB |
Output is correct |
11 |
Correct |
79 ms |
7908 KB |
Output is correct |
12 |
Correct |
63 ms |
7896 KB |
Output is correct |
13 |
Correct |
66 ms |
7908 KB |
Output is correct |
14 |
Correct |
69 ms |
7900 KB |
Output is correct |
15 |
Correct |
73 ms |
7932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
62 ms |
7644 KB |
Output is correct |
14 |
Correct |
57 ms |
7628 KB |
Output is correct |
15 |
Correct |
78 ms |
7644 KB |
Output is correct |
16 |
Correct |
52 ms |
7640 KB |
Output is correct |
17 |
Correct |
49 ms |
7644 KB |
Output is correct |
18 |
Correct |
49 ms |
7644 KB |
Output is correct |
19 |
Correct |
49 ms |
7636 KB |
Output is correct |
20 |
Correct |
51 ms |
7600 KB |
Output is correct |
21 |
Correct |
64 ms |
7528 KB |
Output is correct |
22 |
Correct |
56 ms |
7528 KB |
Output is correct |
23 |
Correct |
65 ms |
7904 KB |
Output is correct |
24 |
Correct |
63 ms |
7912 KB |
Output is correct |
25 |
Correct |
69 ms |
8028 KB |
Output is correct |
26 |
Correct |
77 ms |
7904 KB |
Output is correct |
27 |
Correct |
90 ms |
7892 KB |
Output is correct |
28 |
Correct |
63 ms |
7912 KB |
Output is correct |
29 |
Correct |
69 ms |
7924 KB |
Output is correct |
30 |
Correct |
62 ms |
7904 KB |
Output is correct |
31 |
Correct |
66 ms |
7904 KB |
Output is correct |
32 |
Correct |
82 ms |
7916 KB |
Output is correct |
33 |
Correct |
79 ms |
7908 KB |
Output is correct |
34 |
Correct |
63 ms |
7896 KB |
Output is correct |
35 |
Correct |
66 ms |
7908 KB |
Output is correct |
36 |
Correct |
69 ms |
7900 KB |
Output is correct |
37 |
Correct |
73 ms |
7932 KB |
Output is correct |
38 |
Correct |
141 ms |
7732 KB |
Output is correct |
39 |
Correct |
80 ms |
7780 KB |
Output is correct |
40 |
Correct |
140 ms |
7644 KB |
Output is correct |
41 |
Correct |
87 ms |
7784 KB |
Output is correct |
42 |
Correct |
89 ms |
7772 KB |
Output is correct |
43 |
Correct |
139 ms |
7704 KB |
Output is correct |
44 |
Correct |
85 ms |
7884 KB |
Output is correct |
45 |
Correct |
96 ms |
7776 KB |
Output is correct |
46 |
Correct |
79 ms |
7856 KB |
Output is correct |
47 |
Correct |
90 ms |
7940 KB |
Output is correct |
48 |
Correct |
114 ms |
7784 KB |
Output is correct |
49 |
Correct |
93 ms |
7784 KB |
Output is correct |
50 |
Correct |
78 ms |
7864 KB |
Output is correct |
51 |
Correct |
100 ms |
7776 KB |
Output is correct |
52 |
Correct |
157 ms |
7688 KB |
Output is correct |
53 |
Correct |
89 ms |
7784 KB |
Output is correct |
54 |
Correct |
97 ms |
7764 KB |
Output is correct |
55 |
Correct |
100 ms |
7748 KB |
Output is correct |
56 |
Correct |
97 ms |
7760 KB |
Output is correct |
57 |
Correct |
102 ms |
7780 KB |
Output is correct |
58 |
Correct |
103 ms |
7788 KB |
Output is correct |