답안 #167321

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167321 2019-12-07T11:10:53 Z egekabas Tenis (COI19_tenis) C++14
100 / 100
372 ms 8056 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ull, ull>    pull;
typedef pair<ll, ll>  pll;
typedef pair<ld, ld>  pld;
struct player{
    int a, b, c;
};
struct node{
    int maxi;
    int go;
};
int n, q;
player ar[100009];
node seg[400009];
int a[100009], b[100009], c[100009];
int getmaxi(player x){
    return max(max(x.a, x.b), (int)x.c);
}
int getmini(player x){
    return min(min(x.a, x.b), (int)x.c);
}
node merge(node a, node b){
    if(b.maxi >= a.go)
        return {b.maxi, max(a.go, b.go)};
    else
        return {a.maxi, max(a.go, b.go)};
    
}
void update(int v, int tl, int tr, int idx){ 
    if(tr < idx || idx < tl)
        return;
    if(tl == idx && tr == idx){
        seg[v].go = max(max(getmaxi(ar[a[tl]]),
        getmaxi(ar[b[tl]])), getmaxi(ar[c[tl]]));
        if(tl >= seg[v].go)
            seg[v].maxi = tl;
        else
            seg[v].maxi = -1;
    }
    else{
        int tm = (tl+tr)/2;
        update(2*v, tl, tm, idx);
        update(2*v+1, tm+1, tr, idx);
        seg[v] = merge(seg[2*v], seg[2*v+1]);
    }
}

node get(int v, int tl, int tr, int l, int r){
    if(r < tl || l > tr)
        return {-1, -1};
    if(l <= tl && tr <= r)
        return seg[v];
    else{
        int tm = (tl+tr)/2;
        return merge(get(2*v, tl, tm, l, r), get(2*v+1, tm+1, tr, l, r));
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n >> q;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        ar[a[i]].a = i;
    }
    for(int i = 0; i < n; ++i){
        cin >> b[i];
        ar[b[i]].b = i;
    }
    for(int i = 0; i < n; ++i){
        cin >> c[i];
        ar[c[i]].c = i;
    }
    for(int i = 0; i < n; ++i)
        update(1, 0, n-1, i);
    while(q--){
        int t;
        cin >> t;
        if(t == 1){
            int x;
            cin >> x;
            if(get(1, 0, n-1, 0, getmini(ar[x])-1).maxi != -1)
                cout << "NE\n";
            else
                cout << "DA\n";
        }
        else{
            int x, y, z;
            cin >> x >> y >> z;
            player &p1 = ar[y];
            player &p2 = ar[z];
            if(x == 1){
                swap(p1.a, p2.a);
                swap(a[p1.a], a[p2.a]);
            }
            if(x == 2){
                swap(p1.b, p2.b);
                swap(b[p1.b], b[p2.b]);
            }
            if(x == 3){
                swap(p1.c, p2.c);
                swap(c[p1.c], c[p2.c]);
            }
            update(1, 0, n-1, p1.a);
            update(1, 0, n-1, p1.b);
            update(1, 0, n-1, p1.c);
            
            update(1, 0, n-1, p2.a);
            update(1, 0, n-1, p2.b);
            update(1, 0, n-1, p2.c);
            
        }
    }
}
# 결과 실행 시간 메모리 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 4 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 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 4 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 69 ms 4732 KB Output is correct
14 Correct 69 ms 4728 KB Output is correct
15 Correct 69 ms 4728 KB Output is correct
16 Correct 71 ms 4712 KB Output is correct
17 Correct 68 ms 4728 KB Output is correct
18 Correct 65 ms 4764 KB Output is correct
19 Correct 66 ms 4728 KB Output is correct
20 Correct 66 ms 4780 KB Output is correct
21 Correct 71 ms 5020 KB Output is correct
22 Correct 71 ms 5940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 7580 KB Output is correct
2 Correct 130 ms 7388 KB Output is correct
3 Correct 131 ms 7616 KB Output is correct
4 Correct 128 ms 7160 KB Output is correct
5 Correct 128 ms 7500 KB Output is correct
6 Correct 166 ms 7708 KB Output is correct
7 Correct 128 ms 7528 KB Output is correct
8 Correct 128 ms 7672 KB Output is correct
9 Correct 127 ms 7580 KB Output is correct
10 Correct 372 ms 7516 KB Output is correct
11 Correct 127 ms 7552 KB Output is correct
12 Correct 133 ms 7048 KB Output is correct
13 Correct 135 ms 7548 KB Output is correct
14 Correct 128 ms 7544 KB Output is correct
15 Correct 123 ms 7544 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 4 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 69 ms 4732 KB Output is correct
14 Correct 69 ms 4728 KB Output is correct
15 Correct 69 ms 4728 KB Output is correct
16 Correct 71 ms 4712 KB Output is correct
17 Correct 68 ms 4728 KB Output is correct
18 Correct 65 ms 4764 KB Output is correct
19 Correct 66 ms 4728 KB Output is correct
20 Correct 66 ms 4780 KB Output is correct
21 Correct 71 ms 5020 KB Output is correct
22 Correct 71 ms 5940 KB Output is correct
23 Correct 124 ms 7580 KB Output is correct
24 Correct 130 ms 7388 KB Output is correct
25 Correct 131 ms 7616 KB Output is correct
26 Correct 128 ms 7160 KB Output is correct
27 Correct 128 ms 7500 KB Output is correct
28 Correct 166 ms 7708 KB Output is correct
29 Correct 128 ms 7528 KB Output is correct
30 Correct 128 ms 7672 KB Output is correct
31 Correct 127 ms 7580 KB Output is correct
32 Correct 372 ms 7516 KB Output is correct
33 Correct 127 ms 7552 KB Output is correct
34 Correct 133 ms 7048 KB Output is correct
35 Correct 135 ms 7548 KB Output is correct
36 Correct 128 ms 7544 KB Output is correct
37 Correct 123 ms 7544 KB Output is correct
38 Correct 233 ms 7768 KB Output is correct
39 Correct 143 ms 7672 KB Output is correct
40 Correct 276 ms 7852 KB Output is correct
41 Correct 182 ms 7772 KB Output is correct
42 Correct 168 ms 7772 KB Output is correct
43 Correct 231 ms 7924 KB Output is correct
44 Correct 148 ms 7708 KB Output is correct
45 Correct 185 ms 7636 KB Output is correct
46 Correct 157 ms 7764 KB Output is correct
47 Correct 175 ms 7748 KB Output is correct
48 Correct 148 ms 7672 KB Output is correct
49 Correct 177 ms 7672 KB Output is correct
50 Correct 147 ms 7672 KB Output is correct
51 Correct 168 ms 7800 KB Output is correct
52 Correct 235 ms 8056 KB Output is correct
53 Correct 164 ms 7676 KB Output is correct
54 Correct 167 ms 7672 KB Output is correct
55 Correct 167 ms 7720 KB Output is correct
56 Correct 170 ms 7708 KB Output is correct
57 Correct 154 ms 7732 KB Output is correct
58 Correct 186 ms 7652 KB Output is correct