Submission #283802

# Submission time Handle Problem Language Result Execution time Memory
283802 2020-08-26T07:28:04 Z AMO5 Tenis (COI19_tenis) C++17
100 / 100
295 ms 8056 KB
//koosaga's sol
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MAXT = 270000;
using lint = long long;

struct seg{
	int tree[MAXT], lazy[MAXT];
	void lazydown(int p){
		lazy[2*p] += lazy[p];
		lazy[2*p+1] += lazy[p];
		tree[2*p] += lazy[p];
		tree[2*p+1] += lazy[p];
		lazy[p] = 0;
	}
	void add(int s, int e, int ps, int pe, int p, int v){
		if(e < ps || pe < s) return;
		if(s <= ps && pe <= e){
			tree[p] += v;
			lazy[p] += v;
			return;
		}
		int pm = (ps+pe)/2;
		lazydown(p);
		add(s, e, ps, pm, 2*p, v);
		add(s, e, pm+1, pe, 2*p+1, v);
		tree[p] = min(tree[2*p], tree[2*p+1]);
	}
	int query(int s, int e, int ps, int pe, int p){
		if(e < ps || pe < s) return 1e9;
		if(s <= ps && pe <= e) return tree[p];
		lazydown(p);
		int pm = (ps+pe)/2;
		return min(query(s, e, ps, pm, 2*p), query(s, e, pm+1, pe, 2*p+1));
	}
}seg;

int n, q;
int a[3][MAXN], rev[3][MAXN];
int mtch[3][MAXN];

int main(){
	scanf("%d %d",&n,&q);
	for(int i=0; i<3; i++){
		for(int j=1; j<=n; j++){
			scanf("%d",&a[i][j]);
			rev[i][a[i][j]] = j;
		}
	}
	auto Upload = [&](int x, int v){
		int st = min({rev[0][x], rev[1][x], rev[2][x]});
		int ed = max({rev[0][x], rev[1][x], rev[2][x]});
		seg.add(st, ed - 1, 1, n - 1, 1, v);
	};
	for(int i=1; i<=n; i++) Upload(i, +1);
	while(q--){
		int t; scanf("%d",&t);
		if(t == 1){
			scanf("%d",&t);
			int ans = min({rev[0][t], rev[1][t], rev[2][t]});
			puts(seg.query(1, ans - 1, 1, n - 1, 1) ? "DA" : "NE");
		}
		else{
			int p, x, y; scanf("%d %d %d",&p,&x,&y);
			Upload(x, -1);
			Upload(y, -1);
			p--;
			swap(rev[p][x], rev[p][y]);
			Upload(x, +1);
			Upload(y, +1);
		}
	}
}

Compilation message

tenis.cpp: In function 'int main()':
tenis.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |  scanf("%d %d",&n,&q);
      |  ~~~~~^~~~~~~~~~~~~~~
tenis.cpp:47:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |    scanf("%d",&a[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~
tenis.cpp:58:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |   int t; scanf("%d",&t);
      |          ~~~~~^~~~~~~~~
tenis.cpp:60:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   60 |    scanf("%d",&t);
      |    ~~~~~^~~~~~~~~
tenis.cpp:65:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |    int p, x, y; scanf("%d %d %d",&p,&x,&y);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 416 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 416 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 94 ms 4856 KB Output is correct
14 Correct 101 ms 4984 KB Output is correct
15 Correct 94 ms 4984 KB Output is correct
16 Correct 95 ms 4856 KB Output is correct
17 Correct 96 ms 4860 KB Output is correct
18 Correct 91 ms 4984 KB Output is correct
19 Correct 90 ms 4984 KB Output is correct
20 Correct 103 ms 4872 KB Output is correct
21 Correct 102 ms 4968 KB Output is correct
22 Correct 96 ms 4856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 170 ms 5240 KB Output is correct
2 Correct 167 ms 7544 KB Output is correct
3 Correct 186 ms 7672 KB Output is correct
4 Correct 166 ms 7672 KB Output is correct
5 Correct 162 ms 7616 KB Output is correct
6 Correct 158 ms 7544 KB Output is correct
7 Correct 187 ms 7672 KB Output is correct
8 Correct 167 ms 7600 KB Output is correct
9 Correct 163 ms 7544 KB Output is correct
10 Correct 168 ms 7672 KB Output is correct
11 Correct 175 ms 7544 KB Output is correct
12 Correct 158 ms 7544 KB Output is correct
13 Correct 180 ms 7800 KB Output is correct
14 Correct 173 ms 7544 KB Output is correct
15 Correct 168 ms 7672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 416 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 94 ms 4856 KB Output is correct
14 Correct 101 ms 4984 KB Output is correct
15 Correct 94 ms 4984 KB Output is correct
16 Correct 95 ms 4856 KB Output is correct
17 Correct 96 ms 4860 KB Output is correct
18 Correct 91 ms 4984 KB Output is correct
19 Correct 90 ms 4984 KB Output is correct
20 Correct 103 ms 4872 KB Output is correct
21 Correct 102 ms 4968 KB Output is correct
22 Correct 96 ms 4856 KB Output is correct
23 Correct 170 ms 5240 KB Output is correct
24 Correct 167 ms 7544 KB Output is correct
25 Correct 186 ms 7672 KB Output is correct
26 Correct 166 ms 7672 KB Output is correct
27 Correct 162 ms 7616 KB Output is correct
28 Correct 158 ms 7544 KB Output is correct
29 Correct 187 ms 7672 KB Output is correct
30 Correct 167 ms 7600 KB Output is correct
31 Correct 163 ms 7544 KB Output is correct
32 Correct 168 ms 7672 KB Output is correct
33 Correct 175 ms 7544 KB Output is correct
34 Correct 158 ms 7544 KB Output is correct
35 Correct 180 ms 7800 KB Output is correct
36 Correct 173 ms 7544 KB Output is correct
37 Correct 168 ms 7672 KB Output is correct
38 Correct 286 ms 7936 KB Output is correct
39 Correct 181 ms 7544 KB Output is correct
40 Correct 295 ms 8056 KB Output is correct
41 Correct 218 ms 7808 KB Output is correct
42 Correct 224 ms 7716 KB Output is correct
43 Correct 282 ms 7940 KB Output is correct
44 Correct 210 ms 7672 KB Output is correct
45 Correct 245 ms 7860 KB Output is correct
46 Correct 199 ms 7576 KB Output is correct
47 Correct 203 ms 7672 KB Output is correct
48 Correct 202 ms 7588 KB Output is correct
49 Correct 264 ms 7672 KB Output is correct
50 Correct 182 ms 7672 KB Output is correct
51 Correct 224 ms 7672 KB Output is correct
52 Correct 277 ms 7800 KB Output is correct
53 Correct 193 ms 7692 KB Output is correct
54 Correct 223 ms 7800 KB Output is correct
55 Correct 224 ms 7672 KB Output is correct
56 Correct 202 ms 7672 KB Output is correct
57 Correct 187 ms 7672 KB Output is correct
58 Correct 241 ms 7672 KB Output is correct