답안 #705272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
705272 2023-03-03T18:15:34 Z Nursik Tenis (COI19_tenis) C++14
100 / 100
150 ms 7804 KB
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <functional>
#include <complex>
#include <random>

using namespace std;
 
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
 
const ll maxn = 1e5 + 1, maxm = 3e5 + 1;
const ll mod = 1e9 + 7, cmod = 998244353, inf = 1e9, blcok = 400, p2 = 31;
const ld eps = 1e-9;

int n, q;
int a[5][maxn], pos[5][maxn];
struct seg_tree{
    int t[maxn * 4], mv[maxn * 4];
    void build(int v = 1, int tl = 1, int tr = n){
        mv[v] = 0;
        if (tl == tr){
            t[v] = tl;
            return;
        }
        int tm = (tl + tr) / 2;
        build(v + v, tl, tm);
        build(v + v + 1, tm + 1, tr);
        t[v] = min(t[v + v], t[v + v + 1]);
    }
    void push(int v, int l, int r){
        if (mv[v]){
            t[v] += mv[v];
            if (l != r){
                mv[v + v] += mv[v];
                mv[v + v + 1] += mv[v];
            }
            mv[v] = 0;
        }
    }
    void updlr(int l, int r, int val, int v = 1, int tl = 1, int tr = n){
        push(v, tl, tr);
      //  cout << v << " " << tl << " " << tr << '\n';
        if (l <= tl && tr <= r){
            mv[v] += val;
            push(v, tl, tr);
            return;
        }
        if (l > tr || r < tl)
            return;
        int tm = (tl + tr) / 2;
        updlr(l, r, val, v + v, tl, tm);
        updlr(l, r, val, v + v + 1, tm + 1, tr);
        t[v] = min(t[v + v], t[v + v + 1]);
    }
    int get(int v = 1, int tl = 1, int tr = n){
        push(v, tl, tr);
        if (tl == tr)
            return tl;
        int tm = (tl + tr) / 2;
        push(v + v, tl, tm);
        push(v + v + 1, tm + 1, tr);
        if (t[v + v] == 0)
            return get(v + v, tl, tm);
        else
            return get(v + v + 1, tm + 1, tr);
    }
} rt;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); 
    cin >> n >> q;
    for (int i = 1; i <= 3; ++i){
        for (int j = 1; j <= n; ++j){
            cin >> a[i][j];
            pos[i][a[i][j]] = j;
        }
    }
    rt.build();
    for (int i = 1; i <= n; ++i){
        int x = max({pos[1][i], pos[2][i], pos[3][i]});
     //   cout << x << " " << n << '\n';
        rt.updlr(x, n, -1);
    }
   // exit(0);
    for (int i = 1; i <= q; ++i){
        int type;
        cin >> type;
        if (type == 1){
            int x;
            cin >> x;
            int y = rt.get();
            int z = max({pos[1][x], pos[2][x], pos[3][x]});
            if (z <= y){
                cout << "DA\n";
            }
            else{
                cout << "NE\n";
            }
        }
        else{
            int p, x, y, z;
            cin >> p >> x >> y;
            z = max({pos[1][x], pos[2][x], pos[3][x]});
            rt.updlr(z, n, 1);
            z = max({pos[1][y], pos[2][y], pos[3][y]});
            rt.updlr(z, n, 1);
            swap(pos[p][x], pos[p][y]);
            z = max({pos[1][x], pos[2][x], pos[3][x]});
            rt.updlr(z, n, -1);
            z = max({pos[1][y], pos[2][y], pos[3][y]});
            rt.updlr(z, n, -1);
        }
    }
}
/*
*/

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 324 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 336 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 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 324 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 336 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 336 KB Output is correct
13 Correct 73 ms 6424 KB Output is correct
14 Correct 52 ms 6336 KB Output is correct
15 Correct 50 ms 6436 KB Output is correct
16 Correct 49 ms 6336 KB Output is correct
17 Correct 50 ms 6332 KB Output is correct
18 Correct 52 ms 6452 KB Output is correct
19 Correct 50 ms 6340 KB Output is correct
20 Correct 55 ms 6344 KB Output is correct
21 Correct 52 ms 6444 KB Output is correct
22 Correct 61 ms 6348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 7408 KB Output is correct
2 Correct 70 ms 7448 KB Output is correct
3 Correct 93 ms 7524 KB Output is correct
4 Correct 71 ms 7528 KB Output is correct
5 Correct 103 ms 7428 KB Output is correct
6 Correct 79 ms 7472 KB Output is correct
7 Correct 69 ms 7400 KB Output is correct
8 Correct 78 ms 7628 KB Output is correct
9 Correct 71 ms 7404 KB Output is correct
10 Correct 68 ms 7452 KB Output is correct
11 Correct 77 ms 7396 KB Output is correct
12 Correct 74 ms 7392 KB Output is correct
13 Correct 72 ms 7488 KB Output is correct
14 Correct 77 ms 7504 KB Output is correct
15 Correct 70 ms 7392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 324 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 336 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 336 KB Output is correct
13 Correct 73 ms 6424 KB Output is correct
14 Correct 52 ms 6336 KB Output is correct
15 Correct 50 ms 6436 KB Output is correct
16 Correct 49 ms 6336 KB Output is correct
17 Correct 50 ms 6332 KB Output is correct
18 Correct 52 ms 6452 KB Output is correct
19 Correct 50 ms 6340 KB Output is correct
20 Correct 55 ms 6344 KB Output is correct
21 Correct 52 ms 6444 KB Output is correct
22 Correct 61 ms 6348 KB Output is correct
23 Correct 82 ms 7408 KB Output is correct
24 Correct 70 ms 7448 KB Output is correct
25 Correct 93 ms 7524 KB Output is correct
26 Correct 71 ms 7528 KB Output is correct
27 Correct 103 ms 7428 KB Output is correct
28 Correct 79 ms 7472 KB Output is correct
29 Correct 69 ms 7400 KB Output is correct
30 Correct 78 ms 7628 KB Output is correct
31 Correct 71 ms 7404 KB Output is correct
32 Correct 68 ms 7452 KB Output is correct
33 Correct 77 ms 7396 KB Output is correct
34 Correct 74 ms 7392 KB Output is correct
35 Correct 72 ms 7488 KB Output is correct
36 Correct 77 ms 7504 KB Output is correct
37 Correct 70 ms 7392 KB Output is correct
38 Correct 149 ms 7736 KB Output is correct
39 Correct 85 ms 7520 KB Output is correct
40 Correct 150 ms 7732 KB Output is correct
41 Correct 99 ms 7564 KB Output is correct
42 Correct 105 ms 7700 KB Output is correct
43 Correct 137 ms 7804 KB Output is correct
44 Correct 85 ms 7536 KB Output is correct
45 Correct 116 ms 7628 KB Output is correct
46 Correct 97 ms 7604 KB Output is correct
47 Correct 99 ms 7624 KB Output is correct
48 Correct 103 ms 7508 KB Output is correct
49 Correct 113 ms 7680 KB Output is correct
50 Correct 84 ms 7588 KB Output is correct
51 Correct 109 ms 7612 KB Output is correct
52 Correct 142 ms 7792 KB Output is correct
53 Correct 88 ms 7668 KB Output is correct
54 Correct 99 ms 7660 KB Output is correct
55 Correct 114 ms 7672 KB Output is correct
56 Correct 101 ms 7580 KB Output is correct
57 Correct 84 ms 7532 KB Output is correct
58 Correct 117 ms 7652 KB Output is correct