Submission #200577

# Submission time Handle Problem Language Result Execution time Memory
200577 2020-02-07T12:30:17 Z stefdasca Tenis (COI19_tenis) C++14
100 / 100
193 ms 7936 KB
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

// #define fisier 1

using namespace std;

typedef long long ll;

int n, q;
int ord[4][100002], poz[4][100002];

int find_worst(int x)
{
    return max(poz[1][x], max(poz[2][x], poz[3][x]));
}

int aint[400002], lazy[400002];
void lz(int nod, int st, int dr)
{
    aint[nod] += lazy[nod];
    if(st != dr)
    {
        lazy[nod << 1] += lazy[nod];
        lazy[nod << 1|1] += lazy[nod];
    }
    lazy[nod] = 0;
}
void build(int nod, int st, int dr)
{
    if(st == dr)
    {
        aint[nod] = st;
        return;
    }
    int mid = (st + dr) / 2;
    build(nod << 1, st, mid);
    build(nod << 1|1, mid+1, dr);
    aint[nod] = min(aint[nod << 1], aint[nod << 1|1]);
}
void update(int nod, int st, int dr, int L, int R, int val)
{
    lz(nod, st, dr);
    if(dr < L || st > R)
        return;
    if(L <= st && dr <= R)
    {
        lazy[nod] += val;
        lz(nod, st, dr);
        return;
    }
    int mid = (st + dr) / 2;
    update(nod << 1, st, mid, L, R, val);
    update(nod << 1|1, mid+1, dr, L, R, val);
    aint[nod] = min(aint[nod << 1], aint[nod << 1|1]);
}
int query(int nod, int st, int dr)
{
    lz(nod, st, dr);
    if(st == dr)
        return st;
    int mid = (st + dr) / 2;
    int ans = 0;
    if(aint[nod << 1] + lazy[nod << 1] == 0)
        ans = query(nod << 1, st, mid);
    else
        ans = query(nod << 1|1, mid+1, dr);
    aint[nod] = min(aint[nod << 1], aint[nod << 1|1]);
    return ans;
}
int main()
{

    #ifdef fisier
        ifstream f("input.in");
        ofstream g("output.out");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> q;
    for(int j = 1; j <= 3; ++j)
        for(int i = 1; i <= n; ++i)
            cin >> ord[j][i], poz[j][ord[j][i]] = i;
    build(1, 1, n);
    for(int i = 1; i <= n; ++i)
        update(1, 1, n, find_worst(i), n, -1);
    for(; q; --q)
    {
        int tip, val;
        cin >> tip;
        if(tip == 1)
        {
            cin >> val;
            int ans = query(1, 1, n);
            cout << ((find_worst(val) <= ans) ? "DA" : "NE") << '\n';
        }
        else
        {
            int wh, a, b;
            cin >> wh >> a >> b;
            update(1, 1, n, find_worst(a), n, 1);
            update(1, 1, n, find_worst(b), n, 1);
            int x = poz[wh][a];
            int y = poz[wh][b];
            swap(ord[wh][x], ord[wh][y]);
            swap(poz[wh][a], poz[wh][b]);
            update(1, 1, n, find_worst(a), n, -1);
            update(1, 1, n, find_worst(b), n, -1);
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 5 ms 388 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 5 ms 388 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 5 ms 388 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 74 ms 6520 KB Output is correct
14 Correct 73 ms 6520 KB Output is correct
15 Correct 68 ms 4856 KB Output is correct
16 Correct 72 ms 4728 KB Output is correct
17 Correct 75 ms 4856 KB Output is correct
18 Correct 73 ms 4728 KB Output is correct
19 Correct 72 ms 4728 KB Output is correct
20 Correct 75 ms 4728 KB Output is correct
21 Correct 77 ms 4728 KB Output is correct
22 Correct 72 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 6392 KB Output is correct
2 Correct 108 ms 7544 KB Output is correct
3 Correct 106 ms 6816 KB Output is correct
4 Correct 107 ms 6648 KB Output is correct
5 Correct 110 ms 6776 KB Output is correct
6 Correct 109 ms 6648 KB Output is correct
7 Correct 111 ms 6648 KB Output is correct
8 Correct 109 ms 6624 KB Output is correct
9 Correct 104 ms 6648 KB Output is correct
10 Correct 103 ms 6648 KB Output is correct
11 Correct 132 ms 6648 KB Output is correct
12 Correct 109 ms 6636 KB Output is correct
13 Correct 112 ms 6648 KB Output is correct
14 Correct 108 ms 6648 KB Output is correct
15 Correct 112 ms 6904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 5 ms 388 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 74 ms 6520 KB Output is correct
14 Correct 73 ms 6520 KB Output is correct
15 Correct 68 ms 4856 KB Output is correct
16 Correct 72 ms 4728 KB Output is correct
17 Correct 75 ms 4856 KB Output is correct
18 Correct 73 ms 4728 KB Output is correct
19 Correct 72 ms 4728 KB Output is correct
20 Correct 75 ms 4728 KB Output is correct
21 Correct 77 ms 4728 KB Output is correct
22 Correct 72 ms 4728 KB Output is correct
23 Correct 104 ms 6392 KB Output is correct
24 Correct 108 ms 7544 KB Output is correct
25 Correct 106 ms 6816 KB Output is correct
26 Correct 107 ms 6648 KB Output is correct
27 Correct 110 ms 6776 KB Output is correct
28 Correct 109 ms 6648 KB Output is correct
29 Correct 111 ms 6648 KB Output is correct
30 Correct 109 ms 6624 KB Output is correct
31 Correct 104 ms 6648 KB Output is correct
32 Correct 103 ms 6648 KB Output is correct
33 Correct 132 ms 6648 KB Output is correct
34 Correct 109 ms 6636 KB Output is correct
35 Correct 112 ms 6648 KB Output is correct
36 Correct 108 ms 6648 KB Output is correct
37 Correct 112 ms 6904 KB Output is correct
38 Correct 193 ms 5880 KB Output is correct
39 Correct 137 ms 7584 KB Output is correct
40 Correct 193 ms 7928 KB Output is correct
41 Correct 142 ms 7672 KB Output is correct
42 Correct 160 ms 7800 KB Output is correct
43 Correct 187 ms 7928 KB Output is correct
44 Correct 128 ms 7672 KB Output is correct
45 Correct 158 ms 7804 KB Output is correct
46 Correct 131 ms 7672 KB Output is correct
47 Correct 143 ms 7800 KB Output is correct
48 Correct 131 ms 7776 KB Output is correct
49 Correct 139 ms 7800 KB Output is correct
50 Correct 131 ms 7928 KB Output is correct
51 Correct 143 ms 7672 KB Output is correct
52 Correct 178 ms 7936 KB Output is correct
53 Correct 140 ms 7812 KB Output is correct
54 Correct 152 ms 7672 KB Output is correct
55 Correct 150 ms 7804 KB Output is correct
56 Correct 137 ms 7672 KB Output is correct
57 Correct 121 ms 7672 KB Output is correct
58 Correct 169 ms 7800 KB Output is correct