답안 #492974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492974 2021-12-09T21:11:58 Z Habitus Tenis (COI19_tenis) C++14
100 / 100
126 ms 6596 KB
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dec(x, y) fixed << setprecision((y)) << (x)
#define xx first
#define yy second
#define srt(v) sort((v).begin(), (v).end())
#define srtr(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define popb pop_back
#define sz(a) (int)(a).size()
#define len(a) (int)(a).length()
#define mp make_pair
#define endl "\n"

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int n, q, gde[100002][3];
struct ralf {
    int vr, lazy;
} st[400002];
void prop(int node, int tl, int tr) {
    st[node].vr+=st[node].lazy;
    if(tl!=tr) {
        st[2*node].lazy+=st[node].lazy;
        st[2*node+1].lazy+=st[node].lazy;
    }
    st[node].lazy=0;
}
void build(int node, int tl, int tr) {
    if(tl==tr) {
        st[node].vr=tl;
        return;
    }
    int mid=(tl+tr)/2;
    build(2*node, tl, mid);
    build(2*node+1, mid+1, tr);
    st[node].vr=min(st[2*node].vr, st[2*node+1].vr);
}
void upd(int node, int tl, int tr, int gl, int gr, int val) {
    prop(node, tl, tr);
    if(tl>=gl && tr<=gr) {
        st[node].lazy+=val;
        return;
    }
    int mid=(tl+tr)/2;
    if(mid>=gl) upd(2*node, tl, mid, gl, gr, val);
    if(mid+1<=gr) upd(2*node+1, mid+1, tr, gl, gr, val);
    prop(2*node, tl, mid);
    prop(2*node+1, mid+1, tr);
    st[node].vr=min(st[2*node].vr, st[2*node+1].vr);
}
int query(int node, int tl, int tr) {
    prop(node, tl, tr);
    if(tl==tr) return tl;
    int mid=(tl+tr)/2;
    prop(2*node, tl, mid);
    if(st[2*node].vr==0) return query(2*node, tl, mid);
    return query(2*node+1, mid+1, tr);
}
int main() {
    ios;
    cin >> n >> q;
    for(int i=0; i<3; i++) {
        for(int j=1; j<=n; j++) {
            int x; cin >> x;
            gde[x][i]=j;
        }
    }
    build(1, 1, n);
    for(int i=1; i<=n; i++) {
        int d=max(max(gde[i][0], gde[i][1]), gde[i][2]);
        upd(1, 1, n, d, n, -1);
    }
    while(q--) {
        int t, x;
        cin >> t >> x;
        if(t==1) {
            int uzmi=query(1, 1, n);
            if(max(max(gde[x][0], gde[x][1]), gde[x][2])<=uzmi) cout << "DA" << endl;
            else cout << "NE" << endl;
        }
        else {
            int y, z; cin >> y >> z;
            x--;
            int stari1=max(max(gde[y][0], gde[y][1]), gde[y][2]), stari2=max(max(gde[z][0], gde[z][1]), gde[z][2]);
            int novi1=gde[z][x], novi2=gde[y][x];
            gde[y][x]=novi1, gde[z][x]=novi2;
            novi1=max(max(gde[y][0], gde[y][1]), gde[y][2]), novi2=max(max(gde[z][0], gde[z][1]), gde[z][2]);
            if(novi1>stari1) {
                upd(1, 1, n, stari1, novi1-1, 1);
            }
            else if(novi1<stari1) {
                upd(1, 1, n, novi1, stari1-1, -1);
            }
            if(novi2>stari2) {
                upd(1, 1, n, stari2, novi2-1, 1);
            }
            else if(novi2<stari2) {
                upd(1, 1, n, novi2, stari2-1, -1);
            }
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 60 ms 5248 KB Output is correct
14 Correct 54 ms 5188 KB Output is correct
15 Correct 54 ms 5180 KB Output is correct
16 Correct 54 ms 5196 KB Output is correct
17 Correct 56 ms 5188 KB Output is correct
18 Correct 55 ms 5188 KB Output is correct
19 Correct 55 ms 5248 KB Output is correct
20 Correct 56 ms 5236 KB Output is correct
21 Correct 57 ms 5188 KB Output is correct
22 Correct 55 ms 5184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 3784 KB Output is correct
2 Correct 84 ms 6196 KB Output is correct
3 Correct 88 ms 6328 KB Output is correct
4 Correct 87 ms 6212 KB Output is correct
5 Correct 88 ms 6200 KB Output is correct
6 Correct 94 ms 6328 KB Output is correct
7 Correct 86 ms 6200 KB Output is correct
8 Correct 113 ms 6340 KB Output is correct
9 Correct 87 ms 6204 KB Output is correct
10 Correct 95 ms 6292 KB Output is correct
11 Correct 82 ms 6212 KB Output is correct
12 Correct 86 ms 6204 KB Output is correct
13 Correct 95 ms 6336 KB Output is correct
14 Correct 82 ms 6212 KB Output is correct
15 Correct 82 ms 6272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 60 ms 5248 KB Output is correct
14 Correct 54 ms 5188 KB Output is correct
15 Correct 54 ms 5180 KB Output is correct
16 Correct 54 ms 5196 KB Output is correct
17 Correct 56 ms 5188 KB Output is correct
18 Correct 55 ms 5188 KB Output is correct
19 Correct 55 ms 5248 KB Output is correct
20 Correct 56 ms 5236 KB Output is correct
21 Correct 57 ms 5188 KB Output is correct
22 Correct 55 ms 5184 KB Output is correct
23 Correct 81 ms 3784 KB Output is correct
24 Correct 84 ms 6196 KB Output is correct
25 Correct 88 ms 6328 KB Output is correct
26 Correct 87 ms 6212 KB Output is correct
27 Correct 88 ms 6200 KB Output is correct
28 Correct 94 ms 6328 KB Output is correct
29 Correct 86 ms 6200 KB Output is correct
30 Correct 113 ms 6340 KB Output is correct
31 Correct 87 ms 6204 KB Output is correct
32 Correct 95 ms 6292 KB Output is correct
33 Correct 82 ms 6212 KB Output is correct
34 Correct 86 ms 6204 KB Output is correct
35 Correct 95 ms 6336 KB Output is correct
36 Correct 82 ms 6212 KB Output is correct
37 Correct 82 ms 6272 KB Output is correct
38 Correct 125 ms 6596 KB Output is correct
39 Correct 99 ms 6360 KB Output is correct
40 Correct 126 ms 6588 KB Output is correct
41 Correct 91 ms 6448 KB Output is correct
42 Correct 95 ms 6460 KB Output is correct
43 Correct 120 ms 6512 KB Output is correct
44 Correct 95 ms 6352 KB Output is correct
45 Correct 98 ms 6468 KB Output is correct
46 Correct 85 ms 6332 KB Output is correct
47 Correct 94 ms 6336 KB Output is correct
48 Correct 102 ms 6320 KB Output is correct
49 Correct 95 ms 6468 KB Output is correct
50 Correct 86 ms 6340 KB Output is correct
51 Correct 95 ms 6460 KB Output is correct
52 Correct 125 ms 6596 KB Output is correct
53 Correct 97 ms 6452 KB Output is correct
54 Correct 92 ms 6456 KB Output is correct
55 Correct 91 ms 6452 KB Output is correct
56 Correct 89 ms 6456 KB Output is correct
57 Correct 91 ms 6424 KB Output is correct
58 Correct 115 ms 6468 KB Output is correct