답안 #558683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558683 2022-05-08T04:09:52 Z Yazan_Alattar Tenis (COI19_tenis) C++14
100 / 100
223 ms 10712 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 100007;
const ll inf = 2e9;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-6;
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;

ll n, q, pos[5][M], mx[M], seg[4 * M], lazy[4 * M];

void push(int node, int l, int r){
    if(lazy[node]){
        seg[node] += lazy[node];

        if(l != r){
            lazy[2 * node] += lazy[node];
            lazy[2 * node + 1] += lazy[node];
        }
        lazy[node] = 0;
    }
    return;
}

void upd(int st, int en, int v, int node = 1, int l = 0, int r = n){
    push(node, l, r);
    if(l > en || r < st) return;
    if(l >= st && r <= en){
        lazy[node] += v;
        push(node, l, r);
        return;
    }
    int mid = (l + r) / 2;
    upd(st, en, v, 2 * node, l, mid);
    upd(st, en, v, 2 * node + 1, mid + 1, r);

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

ll get(int pos, int node = 1, int l = 0, int r = n){
    push(node, l, r);
    if(l > pos) return inf;
    if(r <= pos) return seg[node];
    int mid = (l + r) / 2;
    return min(get(pos, 2 * node, l, mid), get(pos, 2 * node + 1, mid + 1, r));
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    for(int i = 1; i <= 3; ++i){
        for(int j = 1; j <= n; ++j){
            int x; cin >> x;

            pos[i][x] = j;
            mx[x] = max(mx[x], 1ll * j);
        }
    }

    upd(0, 0, inf);
    for(int i = 1; i <= n; ++i){
        upd(mx[i], n, -1);
        upd(i, i, i);
    }

    while(q--){
        int type;
        cin >> type;

        if(type == 1){
            int x;
            cin >> x;

            if(get(mx[x] - 1)) cout << "DA\n";
            else cout << "NE\n";
        }

        else{
            int k, x, y;
            cin >> k >> x >> y;

            upd(mx[x], n, 1); upd(mx[y], n, 1);

            swap(pos[k][x], pos[k][y]);
            mx[x] = mx[y] = 0;
            for(int i = 1; i <= 3; ++i){
                mx[x] = max(mx[x], pos[i][x]);
                mx[y] = max(mx[y], pos[i][y]);
            }

            upd(mx[x], n, -1); upd(mx[y], n, -1);
        }
    }
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 85 ms 9280 KB Output is correct
14 Correct 81 ms 9292 KB Output is correct
15 Correct 93 ms 9196 KB Output is correct
16 Correct 93 ms 9260 KB Output is correct
17 Correct 82 ms 9268 KB Output is correct
18 Correct 82 ms 9296 KB Output is correct
19 Correct 80 ms 9172 KB Output is correct
20 Correct 99 ms 9200 KB Output is correct
21 Correct 88 ms 9164 KB Output is correct
22 Correct 83 ms 9292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 7784 KB Output is correct
2 Correct 126 ms 10240 KB Output is correct
3 Correct 184 ms 10360 KB Output is correct
4 Correct 122 ms 10344 KB Output is correct
5 Correct 116 ms 10316 KB Output is correct
6 Correct 129 ms 10372 KB Output is correct
7 Correct 142 ms 10288 KB Output is correct
8 Correct 154 ms 10364 KB Output is correct
9 Correct 139 ms 10236 KB Output is correct
10 Correct 121 ms 10200 KB Output is correct
11 Correct 134 ms 10232 KB Output is correct
12 Correct 116 ms 10208 KB Output is correct
13 Correct 125 ms 10340 KB Output is correct
14 Correct 168 ms 10320 KB Output is correct
15 Correct 127 ms 10316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 85 ms 9280 KB Output is correct
14 Correct 81 ms 9292 KB Output is correct
15 Correct 93 ms 9196 KB Output is correct
16 Correct 93 ms 9260 KB Output is correct
17 Correct 82 ms 9268 KB Output is correct
18 Correct 82 ms 9296 KB Output is correct
19 Correct 80 ms 9172 KB Output is correct
20 Correct 99 ms 9200 KB Output is correct
21 Correct 88 ms 9164 KB Output is correct
22 Correct 83 ms 9292 KB Output is correct
23 Correct 117 ms 7784 KB Output is correct
24 Correct 126 ms 10240 KB Output is correct
25 Correct 184 ms 10360 KB Output is correct
26 Correct 122 ms 10344 KB Output is correct
27 Correct 116 ms 10316 KB Output is correct
28 Correct 129 ms 10372 KB Output is correct
29 Correct 142 ms 10288 KB Output is correct
30 Correct 154 ms 10364 KB Output is correct
31 Correct 139 ms 10236 KB Output is correct
32 Correct 121 ms 10200 KB Output is correct
33 Correct 134 ms 10232 KB Output is correct
34 Correct 116 ms 10208 KB Output is correct
35 Correct 125 ms 10340 KB Output is correct
36 Correct 168 ms 10320 KB Output is correct
37 Correct 127 ms 10316 KB Output is correct
38 Correct 209 ms 10608 KB Output is correct
39 Correct 147 ms 10352 KB Output is correct
40 Correct 223 ms 10636 KB Output is correct
41 Correct 159 ms 10624 KB Output is correct
42 Correct 145 ms 10472 KB Output is correct
43 Correct 195 ms 10572 KB Output is correct
44 Correct 158 ms 10712 KB Output is correct
45 Correct 177 ms 10472 KB Output is correct
46 Correct 130 ms 10432 KB Output is correct
47 Correct 146 ms 10604 KB Output is correct
48 Correct 141 ms 10376 KB Output is correct
49 Correct 166 ms 10444 KB Output is correct
50 Correct 142 ms 10348 KB Output is correct
51 Correct 145 ms 10512 KB Output is correct
52 Correct 198 ms 10632 KB Output is correct
53 Correct 155 ms 10512 KB Output is correct
54 Correct 150 ms 10584 KB Output is correct
55 Correct 155 ms 10444 KB Output is correct
56 Correct 163 ms 10464 KB Output is correct
57 Correct 150 ms 10444 KB Output is correct
58 Correct 160 ms 10488 KB Output is correct