답안 #611815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
611815 2022-07-29T07:49:36 Z 이동현(#8500) Tenis (COI19_tenis) C++17
100 / 100
270 ms 12016 KB
#include <bits/stdc++.h>
using namespace std;

const int NS = (int)1e5 + 4;

int n, q;
int a[3][NS];
vector<int> pos[NS];

struct Seg{
    int n;
    vector<int> lazy;
    vector<pair<int, int>> tr;
    Seg(){}
    void build(int x, int s, int e){
        if(s == e){
            tr[x].second = s;
            return;
        }
        int m = s + e >> 1;
        build(x * 2, s, m), build(x * 2 + 1, m + 1, e);
        tr[x].second = s;
    }
    Seg(int n):n(n + 4){
        tr.resize(n * 4);
        lazy.resize(n * 4);
    }
    void push(int x, int s, int e, int ps, int pe, int val){
        if(pe < s || ps > e || ps > pe) return;
        if(ps <= s && pe >= e){
            tr[x].first += val, lazy[x] += val;
            if(s == e) tr[x].second = s;
            return;
        }
        if(lazy[x]){
            tr[x * 2].first += lazy[x], lazy[x * 2] += lazy[x];
            tr[x * 2 + 1].first += lazy[x], lazy[x * 2 + 1] += lazy[x];
            lazy[x] = 0;
        }
        int m = s + e >> 1;
        push(x * 2, s, m, ps, pe, val), push(x * 2 + 1, m + 1, e, ps, pe, val);
        tr[x] = min(tr[x * 2], tr[x * 2 + 1]);
    }
}tree;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> q;
    for(int i = 0; i < 3; ++i){
        for(int j = 0; j < n; ++j){
            cin >> a[i][j];
            pos[a[i][j]].push_back(j);
        }
    }
    tree = Seg(n + 4);
    tree.build(1, 0, n - 2);
    for(int i = 1; i <= n; ++i){
        int mn = min({pos[i][0], pos[i][1], pos[i][2]}), mx = max({pos[i][0], pos[i][1], pos[i][2]});
        tree.push(1, 0, n - 2, mn, mx - 1, 1);
    }
    while(q--){
        int x; cin >> x;
        if(x == 1){
            int id; cin >> id;
            int cant = 0;
            if(tree.tr[1].first == 0 && tree.tr[1].second < pos[id][0]) cant = 1;
            if(cant) cout << "NE\n";
            else cout << "DA\n";
        }
        else{
            int y, z; cin >> x >> y >> z; --x;
            int mn, mx;
            mn = min({pos[y][0], pos[y][1], pos[y][2]}), mx = max({pos[y][0], pos[y][1], pos[y][2]});
            tree.push(1, 0, n - 2, mn, mx - 1, -1);
            mn = min({pos[z][0], pos[z][1], pos[z][2]}), mx = max({pos[z][0], pos[z][1], pos[z][2]});
            tree.push(1, 0, n - 2, mn, mx - 1, -1);

            swap(a[x][pos[y][x]], a[x][pos[z][x]]);
            swap(pos[y][x], pos[z][x]);

            mn = min({pos[y][0], pos[y][1], pos[y][2]}), mx = max({pos[y][0], pos[y][1], pos[y][2]});
            tree.push(1, 0, n - 2, mn, mx - 1, 1);
            mn = min({pos[z][0], pos[z][1], pos[z][2]}), mx = max({pos[z][0], pos[z][1], pos[z][2]});
            tree.push(1, 0, n - 2, mn, mx - 1, 1);
        }
    }
    return 0;
}

Compilation message

tenis.cpp: In member function 'void Seg::build(int, int, int)':
tenis.cpp:20:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |         int m = s + e >> 1;
      |                 ~~^~~
tenis.cpp: In member function 'void Seg::push(int, int, int, int, int, int)':
tenis.cpp:40:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |         int m = s + e >> 1;
      |                 ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2660 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 3 ms 2772 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2660 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 3 ms 2772 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 109 ms 11628 KB Output is correct
14 Correct 95 ms 11648 KB Output is correct
15 Correct 84 ms 11596 KB Output is correct
16 Correct 97 ms 11480 KB Output is correct
17 Correct 78 ms 11632 KB Output is correct
18 Correct 88 ms 11596 KB Output is correct
19 Correct 100 ms 11472 KB Output is correct
20 Correct 103 ms 11712 KB Output is correct
21 Correct 83 ms 11612 KB Output is correct
22 Correct 84 ms 11668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 11924 KB Output is correct
2 Correct 103 ms 11924 KB Output is correct
3 Correct 145 ms 12016 KB Output is correct
4 Correct 112 ms 11940 KB Output is correct
5 Correct 125 ms 11992 KB Output is correct
6 Correct 94 ms 11872 KB Output is correct
7 Correct 143 ms 11844 KB Output is correct
8 Correct 123 ms 11848 KB Output is correct
9 Correct 117 ms 11916 KB Output is correct
10 Correct 100 ms 11880 KB Output is correct
11 Correct 133 ms 11912 KB Output is correct
12 Correct 141 ms 11812 KB Output is correct
13 Correct 100 ms 11880 KB Output is correct
14 Correct 107 ms 11872 KB Output is correct
15 Correct 119 ms 11904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2660 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 3 ms 2772 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 109 ms 11628 KB Output is correct
14 Correct 95 ms 11648 KB Output is correct
15 Correct 84 ms 11596 KB Output is correct
16 Correct 97 ms 11480 KB Output is correct
17 Correct 78 ms 11632 KB Output is correct
18 Correct 88 ms 11596 KB Output is correct
19 Correct 100 ms 11472 KB Output is correct
20 Correct 103 ms 11712 KB Output is correct
21 Correct 83 ms 11612 KB Output is correct
22 Correct 84 ms 11668 KB Output is correct
23 Correct 115 ms 11924 KB Output is correct
24 Correct 103 ms 11924 KB Output is correct
25 Correct 145 ms 12016 KB Output is correct
26 Correct 112 ms 11940 KB Output is correct
27 Correct 125 ms 11992 KB Output is correct
28 Correct 94 ms 11872 KB Output is correct
29 Correct 143 ms 11844 KB Output is correct
30 Correct 123 ms 11848 KB Output is correct
31 Correct 117 ms 11916 KB Output is correct
32 Correct 100 ms 11880 KB Output is correct
33 Correct 133 ms 11912 KB Output is correct
34 Correct 141 ms 11812 KB Output is correct
35 Correct 100 ms 11880 KB Output is correct
36 Correct 107 ms 11872 KB Output is correct
37 Correct 119 ms 11904 KB Output is correct
38 Correct 254 ms 11664 KB Output is correct
39 Correct 145 ms 11796 KB Output is correct
40 Correct 260 ms 11704 KB Output is correct
41 Correct 158 ms 11724 KB Output is correct
42 Correct 151 ms 11792 KB Output is correct
43 Correct 270 ms 11628 KB Output is correct
44 Correct 119 ms 11864 KB Output is correct
45 Correct 178 ms 11696 KB Output is correct
46 Correct 141 ms 11848 KB Output is correct
47 Correct 137 ms 11816 KB Output is correct
48 Correct 142 ms 11824 KB Output is correct
49 Correct 181 ms 11796 KB Output is correct
50 Correct 132 ms 11804 KB Output is correct
51 Correct 157 ms 11800 KB Output is correct
52 Correct 233 ms 11724 KB Output is correct
53 Correct 148 ms 11808 KB Output is correct
54 Correct 133 ms 11792 KB Output is correct
55 Correct 155 ms 11716 KB Output is correct
56 Correct 167 ms 11748 KB Output is correct
57 Correct 139 ms 11808 KB Output is correct
58 Correct 196 ms 11804 KB Output is correct