답안 #160738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
160738 2019-10-29T15:43:34 Z alexandra_udristoiu Tenis (COI19_tenis) C++14
100 / 100
180 ms 10040 KB
#include<iostream>
#include<cstdio>
#define DIM 100005
#define f first
#define s second
using namespace std;
int n, q, i, ii, x, y, t, sol;
int poz[3][DIM], v[3][DIM];
pair<long long, long long> aint[4 * DIM];
void update(int nod, int st, int dr, int p){
    if(st == dr){
        aint[nod].f = aint[nod].s = 2 * st - poz[0][ v[1][p] ] - poz[0][ v[2][p] ];
    }
    else{
        int mid = (st + dr) / 2;
        if(p <= mid){
            update(2 * nod, st, mid, p);
        }
        else{
            update(2 * nod + 1, mid + 1, dr, p);
        }
        aint[nod].s = aint[2 * nod].s + aint[2 * nod + 1].s;
        aint[nod].f = max(aint[2 * nod].f, aint[2 * nod + 1].f + aint[2 * nod].s);
    }
}
int query(int nod, int st, int dr){
    if(st == dr){
        return st;
    }
    else{
        int mid = (st + dr) / 2;
        if(aint[nod].f == aint[2 * nod].f){
            return query(2 * nod, st, mid);
        }
        else{
            return query(2 * nod + 1, mid + 1, dr);
        }
    }
}
int main(){
    scanf("%d%d", &n, &q);
    for(ii = 0; ii < 3; ii++){
        for(i = 1; i <= n; i++){
            scanf("%d", &v[ii][i]);
            poz[ii][ v[ii][i] ] = i;
        }
    }
    for(i = 1; i <= n; i++){
        update(1, 1, n, i);
    }
    sol = query(1, 1, n);
    for(; q; q--){
        scanf("%d", &t);
        if(t == 1){
            scanf("%d", &x);
            if(poz[0][x] <= sol){
                cout<<"DA\n";
            }
            else{
                cout<<"NE\n";
            }
        }
        else{
            scanf("%d%d%d", &ii, &x, &y);
            ii--;
            swap(poz[ii][x], poz[ii][y]);
            v[ii][ poz[ii][x] ] = x;
            v[ii][ poz[ii][y] ] = y;
            update(1, 1, n, poz[1][x]);
            update(1, 1, n, poz[1][y]);
            update(1, 1, n, poz[2][x]);
            update(1, 1, n, poz[2][y]);
            sol = query(1, 1, n);
        }
    }
}

Compilation message

tenis.cpp: In function 'int main()':
tenis.cpp:41: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:44:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &v[ii][i]);
             ~~~~~^~~~~~~~~~~~~~~~~
tenis.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &t);
         ~~~~~^~~~~~~~~~
tenis.cpp:55:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
tenis.cpp:64:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d%d", &ii, &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 2 ms 380 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 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 2 ms 380 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 68 ms 6820 KB Output is correct
14 Correct 66 ms 6800 KB Output is correct
15 Correct 67 ms 6816 KB Output is correct
16 Correct 70 ms 6776 KB Output is correct
17 Correct 67 ms 6748 KB Output is correct
18 Correct 68 ms 6712 KB Output is correct
19 Correct 66 ms 6776 KB Output is correct
20 Correct 67 ms 6904 KB Output is correct
21 Correct 67 ms 6776 KB Output is correct
22 Correct 68 ms 6776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 7032 KB Output is correct
2 Correct 96 ms 9668 KB Output is correct
3 Correct 94 ms 9592 KB Output is correct
4 Correct 94 ms 9596 KB Output is correct
5 Correct 95 ms 9592 KB Output is correct
6 Correct 99 ms 9720 KB Output is correct
7 Correct 97 ms 9604 KB Output is correct
8 Correct 97 ms 9572 KB Output is correct
9 Correct 97 ms 9720 KB Output is correct
10 Correct 96 ms 9640 KB Output is correct
11 Correct 98 ms 9684 KB Output is correct
12 Correct 96 ms 9584 KB Output is correct
13 Correct 95 ms 9616 KB Output is correct
14 Correct 95 ms 9592 KB Output is correct
15 Correct 97 ms 9592 KB Output is correct
# 결과 실행 시간 메모리 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 2 ms 380 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 68 ms 6820 KB Output is correct
14 Correct 66 ms 6800 KB Output is correct
15 Correct 67 ms 6816 KB Output is correct
16 Correct 70 ms 6776 KB Output is correct
17 Correct 67 ms 6748 KB Output is correct
18 Correct 68 ms 6712 KB Output is correct
19 Correct 66 ms 6776 KB Output is correct
20 Correct 67 ms 6904 KB Output is correct
21 Correct 67 ms 6776 KB Output is correct
22 Correct 68 ms 6776 KB Output is correct
23 Correct 96 ms 7032 KB Output is correct
24 Correct 96 ms 9668 KB Output is correct
25 Correct 94 ms 9592 KB Output is correct
26 Correct 94 ms 9596 KB Output is correct
27 Correct 95 ms 9592 KB Output is correct
28 Correct 99 ms 9720 KB Output is correct
29 Correct 97 ms 9604 KB Output is correct
30 Correct 97 ms 9572 KB Output is correct
31 Correct 97 ms 9720 KB Output is correct
32 Correct 96 ms 9640 KB Output is correct
33 Correct 98 ms 9684 KB Output is correct
34 Correct 96 ms 9584 KB Output is correct
35 Correct 95 ms 9616 KB Output is correct
36 Correct 95 ms 9592 KB Output is correct
37 Correct 97 ms 9592 KB Output is correct
38 Correct 179 ms 10040 KB Output is correct
39 Correct 117 ms 9720 KB Output is correct
40 Correct 180 ms 9972 KB Output is correct
41 Correct 120 ms 9720 KB Output is correct
42 Correct 129 ms 9848 KB Output is correct
43 Correct 173 ms 9916 KB Output is correct
44 Correct 113 ms 9660 KB Output is correct
45 Correct 132 ms 9808 KB Output is correct
46 Correct 112 ms 9720 KB Output is correct
47 Correct 122 ms 9708 KB Output is correct
48 Correct 112 ms 9720 KB Output is correct
49 Correct 129 ms 9848 KB Output is correct
50 Correct 108 ms 9692 KB Output is correct
51 Correct 122 ms 9720 KB Output is correct
52 Correct 168 ms 9848 KB Output is correct
53 Correct 119 ms 9900 KB Output is correct
54 Correct 121 ms 9720 KB Output is correct
55 Correct 125 ms 9720 KB Output is correct
56 Correct 124 ms 9824 KB Output is correct
57 Correct 113 ms 9672 KB Output is correct
58 Correct 143 ms 9720 KB Output is correct