Submission #155895

# Submission time Handle Problem Language Result Execution time Memory
155895 2019-10-01T19:40:58 Z MetB Tenis (COI19_tenis) C++14
100 / 100
251 ms 7248 KB
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
 
using namespace std;
 
typedef long long ll;
 
const ll INF = 1e9, MOD = 1e9 + 7, MOD2 = 1e6 + 3;

int n, q, a[1000000][3], m[1000000], c[1000000];

struct SegTree {
	int t[4000000], t_add[4000000], start;

	void push (int node) {
		if (node < start) {
			t_add[2 * node] += t_add[node];
			t_add[2 * node + 1] += t_add[node];
		}
		t[node] += t_add[node];
		t_add[node] = 0;
	}

	void build (int n) {
		start = 1;
		while (start < n) start <<= 1;

		int sum = 0;

		for (int i = 0; i < n; i++) {
			sum += c[i];
			t[i + start] = i + 1 - sum;
		}

		for (int i = start - 1; i; i--)
			t[i] = min (t[2 * i], t[2 * i + 1]);
	}

	void update (int node, int tl, int tr, int l, int r, int d) {
		push (node);

		if (tr < l || r < tl) return;
		if (l <= tl && tr <= r) {
			t_add[node] += d;
			push (node);
			return;
		}

		int tm = (tl + tr) / 2;

		update (2 * node, tl, tm, l, r, d);
		update (2 * node + 1, tm + 1, tr, l, r, d);

		t[node] = min (t[2 * node], t[2 * node + 1]);
	}

	int order_stat (int node, int tl, int tr) {
		push (node);

		if (tl == tr) return tl;

		int tm = (tl + tr) / 2;

		push (2 * node);

		if (t[2 * node] == 0) return order_stat (2 * node, tl, tm);
		else return order_stat (2 * node + 1, tm + 1, tr);
	}
} t;

void update (int x) {
	t.update (1, 0, t.start - 1, m[x], n - 1, 1);
	m[x] = max (a[x][0], max (a[x][1], a[x][2]));
	t.update (1, 0, t.start - 1, m[x], n - 1, -1);
}

int main () {
	cin >> n >> q;
	for (int j = 0; j < 3; j++)
		for (int i = 0; i < n; i++) {
			int x;
			scanf ("%d", &x);
			a[x-1][j] = i;
		}

	for (int i = 0; i < n; i++) {
		m[i] = max (a[i][0], max (a[i][1], a[i][2]));
		c[m[i]]++;
	}

	t.build (n);

	for (int i = 0; i < q; i++) {
		int p, x, y, type;
		scanf ("%d", &type);

		if (type == 2) {
			scanf ("%d%d%d", &p, &x, &y);

			swap (a[x-1][p-1], a[y-1][p-1]);

			update (x - 1);
			update (y - 1);
		}
		else {
			scanf ("%d", &x);

			if (t.order_stat (1, 0, t.start - 1) >= m[x-1]) printf ("DA\n");
			else printf ("NE\n");
		}
	}
}

Compilation message

tenis.cpp: In function 'int main()':
tenis.cpp:88:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf ("%d", &x);
    ~~~~~~^~~~~~~~~~
tenis.cpp:101:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d", &type);
   ~~~~~~^~~~~~~~~~~~~
tenis.cpp:104:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf ("%d%d%d", &p, &x, &y);
    ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
tenis.cpp:112:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf ("%d", &x);
    ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 412 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 412 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 69 ms 5212 KB Output is correct
14 Correct 60 ms 5112 KB Output is correct
15 Correct 63 ms 5020 KB Output is correct
16 Correct 64 ms 4984 KB Output is correct
17 Correct 63 ms 5008 KB Output is correct
18 Correct 67 ms 4936 KB Output is correct
19 Correct 55 ms 4984 KB Output is correct
20 Correct 65 ms 4984 KB Output is correct
21 Correct 70 ms 5008 KB Output is correct
22 Correct 66 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 6184 KB Output is correct
2 Correct 99 ms 6008 KB Output is correct
3 Correct 95 ms 6008 KB Output is correct
4 Correct 96 ms 6044 KB Output is correct
5 Correct 95 ms 6008 KB Output is correct
6 Correct 97 ms 6008 KB Output is correct
7 Correct 165 ms 6020 KB Output is correct
8 Correct 103 ms 6136 KB Output is correct
9 Correct 100 ms 6040 KB Output is correct
10 Correct 114 ms 6008 KB Output is correct
11 Correct 101 ms 5968 KB Output is correct
12 Correct 94 ms 5972 KB Output is correct
13 Correct 94 ms 6008 KB Output is correct
14 Correct 95 ms 6080 KB Output is correct
15 Correct 97 ms 6056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 412 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 69 ms 5212 KB Output is correct
14 Correct 60 ms 5112 KB Output is correct
15 Correct 63 ms 5020 KB Output is correct
16 Correct 64 ms 4984 KB Output is correct
17 Correct 63 ms 5008 KB Output is correct
18 Correct 67 ms 4936 KB Output is correct
19 Correct 55 ms 4984 KB Output is correct
20 Correct 65 ms 4984 KB Output is correct
21 Correct 70 ms 5008 KB Output is correct
22 Correct 66 ms 5112 KB Output is correct
23 Correct 122 ms 6184 KB Output is correct
24 Correct 99 ms 6008 KB Output is correct
25 Correct 95 ms 6008 KB Output is correct
26 Correct 96 ms 6044 KB Output is correct
27 Correct 95 ms 6008 KB Output is correct
28 Correct 97 ms 6008 KB Output is correct
29 Correct 165 ms 6020 KB Output is correct
30 Correct 103 ms 6136 KB Output is correct
31 Correct 100 ms 6040 KB Output is correct
32 Correct 114 ms 6008 KB Output is correct
33 Correct 101 ms 5968 KB Output is correct
34 Correct 94 ms 5972 KB Output is correct
35 Correct 94 ms 6008 KB Output is correct
36 Correct 95 ms 6080 KB Output is correct
37 Correct 97 ms 6056 KB Output is correct
38 Correct 241 ms 7248 KB Output is correct
39 Correct 148 ms 6136 KB Output is correct
40 Correct 251 ms 7132 KB Output is correct
41 Correct 227 ms 6132 KB Output is correct
42 Correct 156 ms 6264 KB Output is correct
43 Correct 223 ms 6992 KB Output is correct
44 Correct 129 ms 6136 KB Output is correct
45 Correct 172 ms 6152 KB Output is correct
46 Correct 141 ms 6208 KB Output is correct
47 Correct 178 ms 6268 KB Output is correct
48 Correct 133 ms 6092 KB Output is correct
49 Correct 172 ms 6740 KB Output is correct
50 Correct 123 ms 6172 KB Output is correct
51 Correct 153 ms 6284 KB Output is correct
52 Correct 212 ms 6644 KB Output is correct
53 Correct 119 ms 6184 KB Output is correct
54 Correct 129 ms 6212 KB Output is correct
55 Correct 167 ms 6264 KB Output is correct
56 Correct 162 ms 6236 KB Output is correct
57 Correct 138 ms 6120 KB Output is correct
58 Correct 185 ms 7052 KB Output is correct