Submission #777877

# Submission time Handle Problem Language Result Execution time Memory
777877 2023-07-09T20:33:59 Z Ahmed57 Tenis (COI19_tenis) C++17
100 / 100
143 ms 6612 KB
#include <bits/stdc++.h>

using namespace std;
int seg[400001];
int lazy[400001];
void prop(int p,int l,int r){
    seg[p]+=lazy[p];
    if(l!=r){
        lazy[p*2]+=lazy[p];
        lazy[p*2+1]+=lazy[p];
    }
    lazy[p] = 0;
}
void build(int p,int l,int r){
    if(l==r){
        seg[p] = l;
        return ;
    }
    int md = (l+r)/2;
    build(p*2,l,md);build(p*2+1,md+1,r);
    seg[p] = min(seg[p*2],seg[p*2+1]);
}
void update(int p,int l,int r,int lq,int rq,int val){
    prop(p,l,r);
    if(l>=lq&&r<=rq){
        lazy[p]+=val;
        prop(p,l,r);
        return ;
    }
    if(l>rq||r<lq)return ;
    int md = (l+r)/2;
    update(p*2,l,md,lq,rq,val);update(p*2+1,md+1,r,lq,rq,val);
    seg[p] = min(seg[p*2],seg[p*2+1]);
}
int query(int p,int l,int r){
    if(l==r){
        return l;
    }
    int md = (l+r)/2;
    prop(p*2,l,md);prop(p*2+1,md+1,r);
    if(seg[p*2]==0)return query(p*2,l,md);
    else return query(p*2+1,md+1,r);
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,q;
    cin>>n>>q;
    int arr1[n+1],arr2[n+1],arr3[n+1];
    int ind1[n+1],ind2[n+1],ind3[n+1];
    for(int i = 1;i<=n;i++){
        int x;cin>>x;
        ind1[x] = i;
    }for(int i = 1;i<=n;i++){
        int x;cin>>x;
        ind2[x] = i;
    }for(int i = 1;i<=n;i++){
        int x;cin>>x;
        ind3[x] = i;
    }
    build(1,1,n);
    for(int i = 1;i<=n;i++){
        update(1,1,n,max({ind1[i],ind2[i],ind3[i]}),n,-1);
    }
    while(q--){
        int ty;cin>>ty;
        if(ty==1){
            int x;cin>>x;
            prop(1,1,n);
            if(max({ind1[x],ind2[x],ind3[x]})<=query(1,1,n)){
                cout<<"DA\n";
            }else cout<<"NE\n";
        }else{
            int p,a,b;cin>>p>>a>>b;
            update(1,1,n,max({ind1[a],ind2[a],ind3[a]}),n,1);
            update(1,1,n,max({ind1[b],ind2[b],ind3[b]}),n,1);
            if(p==1)swap(ind1[a],ind1[b]);
            if(p==2)swap(ind2[a],ind2[b]);
            if(p==3)swap(ind3[a],ind3[b]);
            update(1,1,n,max({ind1[a],ind2[a],ind3[a]}),n,-1);
            update(1,1,n,max({ind1[b],ind2[b],ind3[b]}),n,-1);
        }
    }
}

Compilation message

tenis.cpp: In function 'int main()':
tenis.cpp:48:9: warning: unused variable 'arr1' [-Wunused-variable]
   48 |     int arr1[n+1],arr2[n+1],arr3[n+1];
      |         ^~~~
tenis.cpp:48:19: warning: unused variable 'arr2' [-Wunused-variable]
   48 |     int arr1[n+1],arr2[n+1],arr3[n+1];
      |                   ^~~~
tenis.cpp:48:29: warning: unused variable 'arr3' [-Wunused-variable]
   48 |     int arr1[n+1],arr2[n+1],arr3[n+1];
      |                             ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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 324 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 1 ms 340 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 324 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 332 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 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 1 ms 340 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 324 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 332 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 43 ms 5188 KB Output is correct
14 Correct 51 ms 5188 KB Output is correct
15 Correct 44 ms 5256 KB Output is correct
16 Correct 45 ms 5180 KB Output is correct
17 Correct 43 ms 5260 KB Output is correct
18 Correct 44 ms 5180 KB Output is correct
19 Correct 43 ms 5228 KB Output is correct
20 Correct 53 ms 5176 KB Output is correct
21 Correct 42 ms 5192 KB Output is correct
22 Correct 44 ms 5184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 6292 KB Output is correct
2 Correct 70 ms 6332 KB Output is correct
3 Correct 70 ms 6344 KB Output is correct
4 Correct 73 ms 6336 KB Output is correct
5 Correct 65 ms 6292 KB Output is correct
6 Correct 68 ms 6272 KB Output is correct
7 Correct 66 ms 6212 KB Output is correct
8 Correct 70 ms 6328 KB Output is correct
9 Correct 68 ms 6308 KB Output is correct
10 Correct 63 ms 6236 KB Output is correct
11 Correct 72 ms 6332 KB Output is correct
12 Correct 84 ms 6272 KB Output is correct
13 Correct 66 ms 6324 KB Output is correct
14 Correct 64 ms 6208 KB Output is correct
15 Correct 73 ms 6244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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 324 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 332 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 43 ms 5188 KB Output is correct
14 Correct 51 ms 5188 KB Output is correct
15 Correct 44 ms 5256 KB Output is correct
16 Correct 45 ms 5180 KB Output is correct
17 Correct 43 ms 5260 KB Output is correct
18 Correct 44 ms 5180 KB Output is correct
19 Correct 43 ms 5228 KB Output is correct
20 Correct 53 ms 5176 KB Output is correct
21 Correct 42 ms 5192 KB Output is correct
22 Correct 44 ms 5184 KB Output is correct
23 Correct 65 ms 6292 KB Output is correct
24 Correct 70 ms 6332 KB Output is correct
25 Correct 70 ms 6344 KB Output is correct
26 Correct 73 ms 6336 KB Output is correct
27 Correct 65 ms 6292 KB Output is correct
28 Correct 68 ms 6272 KB Output is correct
29 Correct 66 ms 6212 KB Output is correct
30 Correct 70 ms 6328 KB Output is correct
31 Correct 68 ms 6308 KB Output is correct
32 Correct 63 ms 6236 KB Output is correct
33 Correct 72 ms 6332 KB Output is correct
34 Correct 84 ms 6272 KB Output is correct
35 Correct 66 ms 6324 KB Output is correct
36 Correct 64 ms 6208 KB Output is correct
37 Correct 73 ms 6244 KB Output is correct
38 Correct 143 ms 6500 KB Output is correct
39 Correct 87 ms 6348 KB Output is correct
40 Correct 142 ms 6604 KB Output is correct
41 Correct 92 ms 6460 KB Output is correct
42 Correct 97 ms 6504 KB Output is correct
43 Correct 123 ms 6592 KB Output is correct
44 Correct 99 ms 6344 KB Output is correct
45 Correct 95 ms 6408 KB Output is correct
46 Correct 81 ms 6472 KB Output is correct
47 Correct 90 ms 6452 KB Output is correct
48 Correct 81 ms 6316 KB Output is correct
49 Correct 103 ms 6588 KB Output is correct
50 Correct 84 ms 6336 KB Output is correct
51 Correct 93 ms 6480 KB Output is correct
52 Correct 124 ms 6612 KB Output is correct
53 Correct 92 ms 6464 KB Output is correct
54 Correct 106 ms 6460 KB Output is correct
55 Correct 102 ms 6436 KB Output is correct
56 Correct 93 ms 6476 KB Output is correct
57 Correct 82 ms 6324 KB Output is correct
58 Correct 96 ms 6468 KB Output is correct