답안 #222725

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
222725 2020-04-13T22:01:06 Z kingfran1907 Tenis (COI19_tenis) C++14
100 / 100
294 ms 7544 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long llint;

const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;

const int logo = 18;
const int off = 1 << logo;
const int treesiz = off << 1;

int n, q;
int niz[3][maxn];
int pos[3][maxn];
int tour[treesiz];
int prop[treesiz];

void send(int node) {
    tour[node * 2] += prop[node];
    tour[node * 2 + 1] += prop[node];

    prop[node * 2] += prop[node];
    prop[node * 2 + 1] += prop[node];
    prop[node] = 0;
}

void update(int a, int b, int l, int r, int node, int val) {
    //printf("debug update: %d %d %d %d %d %d", a, b, l, r, node, val);
    if (l > b || r < a) return;
    if (l >= a && r <= b) {
        tour[node] += val;
        prop[node] += val;
        return;
    }

    send(node);
    int mid = (l + r) / 2;
    update(a, b, l, mid, node * 2, val);
    update(a, b, mid + 1, r, node * 2 + 1, val);
    tour[node] = min(tour[node * 2], tour[node * 2 + 1]);
}

int query(int l, int r, int node) {
    if (l == r) return l;

    send(node);
    int mid = (l + r) / 2;
    if (tour[2 * node] == 0) return query(l, mid, node * 2);
    else return query(mid + 1, r, node * 2 + 1);
}

int cal(int x) {
    int maxi = -1;
    for (int i = 0; i < 3; i++)
        maxi = max(maxi, pos[i][x]);
    return maxi;
}

int main() {
    scanf("%d%d", &n, &q);
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < n; j++)
            scanf("%d", &niz[i][j]);

    for (int i = 0; i < 3; i++)
        for (int j = 0; j < n; j++)
            pos[i][niz[i][j]] = j;

    for (int i = 0; i < n; i++)
        update(i, n - 1, 0, off - 1, 1, 1);

    for (int i = 1; i <= n; i++) {
        int maxi = -1;
        for (int j = 0; j < 3; j++)
            maxi = max(maxi, pos[j][i]);
        update(maxi, n - 1, 0, off - 1, 1, -1);
    }

    while (q--) {
        int type;
        scanf("%d", &type);

        if (type == 1) {
            int x;
            scanf("%d", &x);

            int ac = query(0, off - 1, 1);
            int tren = -1;
            for (int i = 0; i < 3; i++)
                tren = max(tren, pos[i][x]);

            if (tren <= ac) printf("DA\n");
            else printf("NE\n");
        } else {
            int p, a, b;
            scanf("%d%d%d", &p, &a, &b); p--;

            int pa = pos[p][a], pb = pos[p][b];
            swap(niz[p][pa], niz[p][pb]);

            update(cal(a), n - 1, 0, off - 1, 1, 1);
            update(cal(b), n - 1, 0, off - 1, 1, 1);
            swap(pos[p][a], pos[p][b]);
            update(cal(a), n - 1, 0, off - 1, 1, -1);
            update(cal(b), n - 1, 0, off - 1, 1, -1);
        }
    }
    return 0;
}

Compilation message

tenis.cpp: In function 'int main()':
tenis.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~
tenis.cpp:64:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &niz[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~
tenis.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &type);
         ~~~~~^~~~~~~~~~~~~
tenis.cpp:86:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
tenis.cpp:97:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d%d", &p, &a, &b); p--;
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 139 ms 5968 KB Output is correct
14 Correct 142 ms 6008 KB Output is correct
15 Correct 131 ms 6008 KB Output is correct
16 Correct 138 ms 5944 KB Output is correct
17 Correct 135 ms 6008 KB Output is correct
18 Correct 139 ms 6008 KB Output is correct
19 Correct 134 ms 6008 KB Output is correct
20 Correct 131 ms 6008 KB Output is correct
21 Correct 145 ms 6008 KB Output is correct
22 Correct 133 ms 6008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 5240 KB Output is correct
2 Correct 168 ms 7068 KB Output is correct
3 Correct 181 ms 7152 KB Output is correct
4 Correct 205 ms 7160 KB Output is correct
5 Correct 186 ms 7032 KB Output is correct
6 Correct 215 ms 7288 KB Output is correct
7 Correct 181 ms 7160 KB Output is correct
8 Correct 218 ms 7164 KB Output is correct
9 Correct 174 ms 7160 KB Output is correct
10 Correct 212 ms 7032 KB Output is correct
11 Correct 182 ms 7160 KB Output is correct
12 Correct 186 ms 7032 KB Output is correct
13 Correct 209 ms 7160 KB Output is correct
14 Correct 185 ms 7160 KB Output is correct
15 Correct 191 ms 7180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 139 ms 5968 KB Output is correct
14 Correct 142 ms 6008 KB Output is correct
15 Correct 131 ms 6008 KB Output is correct
16 Correct 138 ms 5944 KB Output is correct
17 Correct 135 ms 6008 KB Output is correct
18 Correct 139 ms 6008 KB Output is correct
19 Correct 134 ms 6008 KB Output is correct
20 Correct 131 ms 6008 KB Output is correct
21 Correct 145 ms 6008 KB Output is correct
22 Correct 133 ms 6008 KB Output is correct
23 Correct 167 ms 5240 KB Output is correct
24 Correct 168 ms 7068 KB Output is correct
25 Correct 181 ms 7152 KB Output is correct
26 Correct 205 ms 7160 KB Output is correct
27 Correct 186 ms 7032 KB Output is correct
28 Correct 215 ms 7288 KB Output is correct
29 Correct 181 ms 7160 KB Output is correct
30 Correct 218 ms 7164 KB Output is correct
31 Correct 174 ms 7160 KB Output is correct
32 Correct 212 ms 7032 KB Output is correct
33 Correct 182 ms 7160 KB Output is correct
34 Correct 186 ms 7032 KB Output is correct
35 Correct 209 ms 7160 KB Output is correct
36 Correct 185 ms 7160 KB Output is correct
37 Correct 191 ms 7180 KB Output is correct
38 Correct 281 ms 7416 KB Output is correct
39 Correct 218 ms 7160 KB Output is correct
40 Correct 294 ms 7416 KB Output is correct
41 Correct 254 ms 7288 KB Output is correct
42 Correct 248 ms 7544 KB Output is correct
43 Correct 294 ms 7416 KB Output is correct
44 Correct 237 ms 7160 KB Output is correct
45 Correct 268 ms 7288 KB Output is correct
46 Correct 213 ms 7288 KB Output is correct
47 Correct 252 ms 7292 KB Output is correct
48 Correct 218 ms 7160 KB Output is correct
49 Correct 231 ms 7288 KB Output is correct
50 Correct 211 ms 7416 KB Output is correct
51 Correct 237 ms 7288 KB Output is correct
52 Correct 284 ms 7416 KB Output is correct
53 Correct 208 ms 7340 KB Output is correct
54 Correct 223 ms 7288 KB Output is correct
55 Correct 263 ms 7288 KB Output is correct
56 Correct 249 ms 7288 KB Output is correct
57 Correct 231 ms 7288 KB Output is correct
58 Correct 266 ms 7416 KB Output is correct