Submission #676416

# Submission time Handle Problem Language Result Execution time Memory
676416 2022-12-30T21:06:00 Z ziduo Tenis (COI19_tenis) C++14
100 / 100
174 ms 13480 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second

const ll MOD = 1e9+7;
int seg[400000][3];
void updateT(int x, int l, int r, int p, int v){
    if(l==r){
        seg[x][0]+=v;
        seg[x][1]=seg[x][0];
        seg[x][2]=p;
    }
    else{
        int s1=2*x, s2=2*x+1;
        int m = (l+r)/2;
        if(p<=m)updateT(s1, l, m, p, v);
        else updateT(s2, m+1, r, p, v);
        if(seg[s1][1]<=seg[s1][0]+seg[s2][1]){
            seg[x][1]=seg[s1][1];
            seg[x][2]=seg[s1][2];
        }
        else{
            seg[x][1]=seg[s1][0]+seg[s2][1];
            seg[x][2]=seg[s2][2];            
        }
        seg[x][0]=seg[s1][0]+seg[s2][0];
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, q, v, t;
    cin>>n>>q;
    vector<int> arr[n];
    int pos[n][3];
    for(int i=0; i<3; i++){
        for(int j=0; j<n; j++){
            cin>>v;
            v--;
            arr[v].push_back(j);
            pos[v][i]=j;
        }
    }
    int sum[n];
    memset(sum, -1, sizeof(sum));
    for(int i=0; i<n; i++){
        sort(arr[i].begin(), arr[i].end());
        sum[arr[i][0]]++;
    }
    for(int i=0; i<n; i++)updateT(1, 0, n-1, i, sum[i]);
    for(int i=0; i<q; i++){
        cin>>t;
        if(t==1){
            cin>>v;
            v--;
            if(arr[v][0]<=seg[1][2])cout<<"DA\n";
            else cout<<"NE\n";
        }
        else{
            int f, v1, v2;
            cin>>f>>v1>>v2;
            f--;
            v1--;
            v2--;
            updateT(1, 0, n-1, arr[v1][0], -1);
            updateT(1, 0, n-1, arr[v2][0], -1);
            int r = pos[v1][f];
            for(int j=0; j<3; j++)if(arr[v1][j]==r){
                arr[v1].erase(arr[v1].begin()+j);
                break;
            }
            arr[v1].push_back(pos[v2][f]);
            r=pos[v2][f];
            for(int j=0; j<3; j++)if(arr[v2][j]==r){
                arr[v2].erase(arr[v2].begin()+j);
                break;
            }
            arr[v2].push_back(pos[v1][f]);     
            swap(pos[v1][f], pos[v2][f]);
            sort(arr[v1].begin(), arr[v1].end());
            sort(arr[v2].begin(), arr[v2].end());
            updateT(1, 0, n-1, arr[v1][0], 1);
            updateT(1, 0, n-1, arr[v2][0], 1);
        }
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 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 63 ms 12084 KB Output is correct
14 Correct 62 ms 12048 KB Output is correct
15 Correct 83 ms 12108 KB Output is correct
16 Correct 61 ms 11964 KB Output is correct
17 Correct 61 ms 12104 KB Output is correct
18 Correct 61 ms 12076 KB Output is correct
19 Correct 61 ms 12048 KB Output is correct
20 Correct 64 ms 12144 KB Output is correct
21 Correct 60 ms 12072 KB Output is correct
22 Correct 61 ms 12076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 13136 KB Output is correct
2 Correct 82 ms 13216 KB Output is correct
3 Correct 84 ms 13128 KB Output is correct
4 Correct 91 ms 13124 KB Output is correct
5 Correct 81 ms 13208 KB Output is correct
6 Correct 78 ms 13132 KB Output is correct
7 Correct 84 ms 13180 KB Output is correct
8 Correct 83 ms 13228 KB Output is correct
9 Correct 91 ms 13232 KB Output is correct
10 Correct 79 ms 13136 KB Output is correct
11 Correct 83 ms 13188 KB Output is correct
12 Correct 89 ms 13096 KB Output is correct
13 Correct 85 ms 13224 KB Output is correct
14 Correct 86 ms 13184 KB Output is correct
15 Correct 88 ms 13112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 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 63 ms 12084 KB Output is correct
14 Correct 62 ms 12048 KB Output is correct
15 Correct 83 ms 12108 KB Output is correct
16 Correct 61 ms 11964 KB Output is correct
17 Correct 61 ms 12104 KB Output is correct
18 Correct 61 ms 12076 KB Output is correct
19 Correct 61 ms 12048 KB Output is correct
20 Correct 64 ms 12144 KB Output is correct
21 Correct 60 ms 12072 KB Output is correct
22 Correct 61 ms 12076 KB Output is correct
23 Correct 84 ms 13136 KB Output is correct
24 Correct 82 ms 13216 KB Output is correct
25 Correct 84 ms 13128 KB Output is correct
26 Correct 91 ms 13124 KB Output is correct
27 Correct 81 ms 13208 KB Output is correct
28 Correct 78 ms 13132 KB Output is correct
29 Correct 84 ms 13180 KB Output is correct
30 Correct 83 ms 13228 KB Output is correct
31 Correct 91 ms 13232 KB Output is correct
32 Correct 79 ms 13136 KB Output is correct
33 Correct 83 ms 13188 KB Output is correct
34 Correct 89 ms 13096 KB Output is correct
35 Correct 85 ms 13224 KB Output is correct
36 Correct 86 ms 13184 KB Output is correct
37 Correct 88 ms 13112 KB Output is correct
38 Correct 154 ms 13380 KB Output is correct
39 Correct 97 ms 13196 KB Output is correct
40 Correct 174 ms 13436 KB Output is correct
41 Correct 100 ms 13264 KB Output is correct
42 Correct 111 ms 13308 KB Output is correct
43 Correct 153 ms 13456 KB Output is correct
44 Correct 104 ms 13260 KB Output is correct
45 Correct 115 ms 13240 KB Output is correct
46 Correct 96 ms 13164 KB Output is correct
47 Correct 103 ms 13260 KB Output is correct
48 Correct 105 ms 13276 KB Output is correct
49 Correct 110 ms 13372 KB Output is correct
50 Correct 95 ms 13264 KB Output is correct
51 Correct 114 ms 13344 KB Output is correct
52 Correct 161 ms 13480 KB Output is correct
53 Correct 100 ms 13336 KB Output is correct
54 Correct 104 ms 13216 KB Output is correct
55 Correct 108 ms 13284 KB Output is correct
56 Correct 112 ms 13324 KB Output is correct
57 Correct 95 ms 13288 KB Output is correct
58 Correct 129 ms 13324 KB Output is correct