Submission #186835

# Submission time Handle Problem Language Result Execution time Memory
186835 2020-01-12T10:53:57 Z anonymous Tenis (COI19_tenis) C++14
100 / 100
180 ms 7916 KB
#include<iostream>
#define MAXN 100005
using namespace std;
int N,Q, L[MAXN][3], Pos[MAXN][3]; //(i,j,k) lowest ranked player on court type i in first k of court type j
bool done[MAXN];
int op, qa, qb, qc;
/* The critical observation is that the people who can win tournament occupy a prefix
of the rankings in each of the 3 court type. Otherwise, if l<=x<=r in a court type
and l, r can win then x can win also. Hence we want to find a ranking P
that the first P people in each of the 3 court types are same. This is done with segment tree*/
class Segtree {
    int ST[MAXN*4][2]; //sum, prefix max
    void pushup(int cur) {
        ST[cur][0]=ST[2*cur][0]+ST[2*cur+1][0];
        ST[cur][1]=max(ST[2*cur][1], ST[2*cur][0]+ST[2*cur+1][1]);
    }
public:
    void build(int l, int r, int cur) {
        if (l == r) {
            ST[cur][0]=ST[cur][1]=-1;
        } else {
            int mid=(l+r)>>1;
            build(l, mid, 2*cur);
            build(mid+1, r, 2*cur+1);
            pushup(cur);
        }
    }
    void upd(int ind, int val, int l, int r, int cur) {
        if (l > ind || ind > r) {return;}
        if (l == r) {
            ST[cur][0]+=val, ST[cur][1]+=val;
        } else {
            int mid=(l+r)>>1;
            upd(ind, val, l, mid, 2*cur);
            upd(ind, val, mid+1, r, 2*cur+1);
            pushup(cur);
        }
    }
    int Find(int s, int l, int r, int cur) {
        if (l == r) {return(l);}
        else {
            int mid=(l+r)>>1;
            if (ST[2*cur][1] + s < 0) {
                return(Find(s+ST[2*cur][0], mid+1,r, 2*cur+1));
            } else {
                return(Find(s, l, mid, 2*cur));
            }
        }
    }
} ST;
int worst(int p) {
    return(max(Pos[p][0], max(Pos[p][1], Pos[p][2])));
}
bool ask(int x) {
    return(worst(x) <= ST.Find(0, 1, N, 1));
}
int main() {
    //freopen("tenin.txt","r",stdin);
    scanf("%d %d",&N,&Q);
    for (int i=0; i<3; i++) {
        for (int j=1; j<=N; j++) {
            scanf("%d", &L[j][i]);
        }
    }

    ST.build(1, N, 1);
    for (int i=0; i<3; i++) {
        for (int j=1; j<=N; j++) {
            Pos[L[j][i]][i]=j;
        }
    }
    for (int i=1; i<=N; i++) {
        ST.upd(worst(i), 1, 1, N, 1);
    }

    for (int i=0; i<Q; i++) {
        scanf("%d", &op);
        if (op == 2) {
            scanf("%d %d %d", &qa, &qb, &qc);
            ST.upd(worst(qb), -1, 1, N, 1);
            ST.upd(worst(qc), -1, 1, N, 1);
            swap(L[Pos[qb][qa-1]][qa-1], L[Pos[qc][qa-1]][qa-1]);
            swap(Pos[qb][qa-1], Pos[qc][qa-1]);
            ST.upd(worst(qb), 1, 1, N, 1);
            ST.upd(worst(qc), 1, 1, N, 1);
        } else {
            scanf("%d", &qa);
            printf("%s\n", ask(qa) ? "DA" : "NE");
        }
    }
}

Compilation message

tenis.cpp: In function 'int main()':
tenis.cpp:59: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:62:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &L[j][i]);
             ~~~~~^~~~~~~~~~~~~~~~
tenis.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &op);
         ~~~~~^~~~~~~~~~~
tenis.cpp:79:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d %d", &qa, &qb, &qc);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
tenis.cpp:87:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &qa);
             ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 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 380 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 0 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 380 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 376 KB Output is correct
8 Correct 2 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 348 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 380 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 376 KB Output is correct
8 Correct 2 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 348 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 71 ms 6480 KB Output is correct
14 Correct 71 ms 6516 KB Output is correct
15 Correct 74 ms 6520 KB Output is correct
16 Correct 72 ms 6352 KB Output is correct
17 Correct 71 ms 6436 KB Output is correct
18 Correct 70 ms 6392 KB Output is correct
19 Correct 71 ms 6392 KB Output is correct
20 Correct 71 ms 6392 KB Output is correct
21 Correct 72 ms 6384 KB Output is correct
22 Correct 71 ms 6392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 7568 KB Output is correct
2 Correct 114 ms 7560 KB Output is correct
3 Correct 115 ms 7676 KB Output is correct
4 Correct 112 ms 7516 KB Output is correct
5 Correct 112 ms 7540 KB Output is correct
6 Correct 113 ms 7544 KB Output is correct
7 Correct 124 ms 7544 KB Output is correct
8 Correct 150 ms 7544 KB Output is correct
9 Correct 125 ms 7544 KB Output is correct
10 Correct 122 ms 7536 KB Output is correct
11 Correct 124 ms 7516 KB Output is correct
12 Correct 127 ms 7416 KB Output is correct
13 Correct 122 ms 7500 KB Output is correct
14 Correct 119 ms 7540 KB Output is correct
15 Correct 111 ms 7544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 380 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 376 KB Output is correct
8 Correct 2 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 348 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 71 ms 6480 KB Output is correct
14 Correct 71 ms 6516 KB Output is correct
15 Correct 74 ms 6520 KB Output is correct
16 Correct 72 ms 6352 KB Output is correct
17 Correct 71 ms 6436 KB Output is correct
18 Correct 70 ms 6392 KB Output is correct
19 Correct 71 ms 6392 KB Output is correct
20 Correct 71 ms 6392 KB Output is correct
21 Correct 72 ms 6384 KB Output is correct
22 Correct 71 ms 6392 KB Output is correct
23 Correct 117 ms 7568 KB Output is correct
24 Correct 114 ms 7560 KB Output is correct
25 Correct 115 ms 7676 KB Output is correct
26 Correct 112 ms 7516 KB Output is correct
27 Correct 112 ms 7540 KB Output is correct
28 Correct 113 ms 7544 KB Output is correct
29 Correct 124 ms 7544 KB Output is correct
30 Correct 150 ms 7544 KB Output is correct
31 Correct 125 ms 7544 KB Output is correct
32 Correct 122 ms 7536 KB Output is correct
33 Correct 124 ms 7516 KB Output is correct
34 Correct 127 ms 7416 KB Output is correct
35 Correct 122 ms 7500 KB Output is correct
36 Correct 119 ms 7540 KB Output is correct
37 Correct 111 ms 7544 KB Output is correct
38 Correct 180 ms 7916 KB Output is correct
39 Correct 123 ms 7544 KB Output is correct
40 Correct 175 ms 7800 KB Output is correct
41 Correct 135 ms 7760 KB Output is correct
42 Correct 137 ms 7708 KB Output is correct
43 Correct 174 ms 7800 KB Output is correct
44 Correct 123 ms 7672 KB Output is correct
45 Correct 133 ms 7704 KB Output is correct
46 Correct 122 ms 7424 KB Output is correct
47 Correct 136 ms 7704 KB Output is correct
48 Correct 130 ms 7620 KB Output is correct
49 Correct 137 ms 7628 KB Output is correct
50 Correct 136 ms 7612 KB Output is correct
51 Correct 132 ms 7656 KB Output is correct
52 Correct 170 ms 7848 KB Output is correct
53 Correct 130 ms 7676 KB Output is correct
54 Correct 136 ms 7720 KB Output is correct
55 Correct 135 ms 7824 KB Output is correct
56 Correct 131 ms 7672 KB Output is correct
57 Correct 123 ms 7672 KB Output is correct
58 Correct 150 ms 7652 KB Output is correct