Submission #144285

# Submission time Handle Problem Language Result Execution time Memory
144285 2019-08-16T13:51:53 Z Abelyan Tenis (COI19_tenis) C++17
100 / 100
481 ms 9436 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define all(v) v.begin(),v.end()
#define ad push_back
#define fr first
#define sc second
#define mpr(a,b) make_pair(a,b)
#define pir pair<int,int>
#define all(v) v.begin(),v.end()
#define make_unique(v) v.erase(unique(all(v)),v.end())
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define srng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define y1 EsiHancagorcRepa

const int N=2e5+10;
const ll MOD2=998244353;
const ll MOD=1e9+7;

void yes(){
    cout<<"DA"<<endl;
}
void no(){
    cout<<"NE"<<endl;
}
pir operator +(pir a,int k){return {a.fr+k,a.sc};}
void operator +=(pir &a,int k){a.fr+=k;}
pir sg[4*N];
int lazy[4*N];

void build(int v,int tl,int tr){
    if (tl==tr){
        sg[v]={tl+1,tl};
        return;
    }
    int tm=(tl+tr)/2;
    build(v+v,tl,tm);
    build(v+v+1,tm+1,tr);
    sg[v]=min(sg[v+v],sg[v+v+1]);
}

void update(int v,int tl,int tr,int l,int r,int del){
    if (l>r)return;
    if (tl==l && tr==r){
        lazy[v]+=del;
        sg[v]+=del;
        return;
    }
    int tm=(tl+tr)/2;
    update(v+v,tl,tm,l,min(r,tm),del);
    update(v+v+1,tm+1,tr,max(l,tm+1),r,del);
    sg[v]=min(sg[v+v],sg[v+v+1])+lazy[v];
}


int a[3][N],ind[3][N],mx[N];

void upd(int v){
    mx[v]=max(ind[0][v],max(ind[1][v],ind[2][v]));
}

int main(){
    fastio;
    srng;
    int n,q;
    cin>>n>>q;
    build(1,0,n-1);
    FOR(i,3)
        FOR(j,n){

            cin>>a[i][j];
            //ad(1,0,n-1,j,i,a[i][j]);
            ind[i][a[i][j]]=j;
        }
    FORT(i,1,n){
        upd(i);
        update(1,0,n-1,mx[i],n-1,-1);
    }
    //cout<<sg[1].fr<<" "<<sg[1].sc<<endl;
    FOR(i,q){
        int tp;
        cin>>tp;
        if (tp==1){
            int x;
            cin>>x;
            //cout<<query(1,0,n-1)<<endl;
            if (ind[0][x]<=sg[1].sc && sg[1].fr==0)yes();
            else no();
        }
        else{
            int tp,v,u;
            cin>>tp>>v>>u;
            tp--;
            update(1,0,n-1,mx[v],n-1,1);
            update(1,0,n-1,mx[u],n-1,1);
            swap(ind[tp][v],ind[tp][u]);
            upd(v);
            upd(u);
            update(1,0,n-1,mx[v],n-1,-1);
            update(1,0,n-1,mx[u],n-1,-1);
        }
    }
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 380 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 380 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 71 ms 6192 KB Output is correct
14 Correct 72 ms 6204 KB Output is correct
15 Correct 72 ms 6140 KB Output is correct
16 Correct 72 ms 6136 KB Output is correct
17 Correct 72 ms 6120 KB Output is correct
18 Correct 73 ms 6136 KB Output is correct
19 Correct 70 ms 6136 KB Output is correct
20 Correct 71 ms 6264 KB Output is correct
21 Correct 70 ms 6136 KB Output is correct
22 Correct 71 ms 6188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 357 ms 6564 KB Output is correct
2 Correct 352 ms 6520 KB Output is correct
3 Correct 357 ms 6648 KB Output is correct
4 Correct 360 ms 6520 KB Output is correct
5 Correct 379 ms 6672 KB Output is correct
6 Correct 354 ms 6520 KB Output is correct
7 Correct 352 ms 6520 KB Output is correct
8 Correct 361 ms 6648 KB Output is correct
9 Correct 361 ms 6648 KB Output is correct
10 Correct 353 ms 6520 KB Output is correct
11 Correct 355 ms 6648 KB Output is correct
12 Correct 352 ms 6492 KB Output is correct
13 Correct 355 ms 6520 KB Output is correct
14 Correct 365 ms 6620 KB Output is correct
15 Correct 352 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 380 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 71 ms 6192 KB Output is correct
14 Correct 72 ms 6204 KB Output is correct
15 Correct 72 ms 6140 KB Output is correct
16 Correct 72 ms 6136 KB Output is correct
17 Correct 72 ms 6120 KB Output is correct
18 Correct 73 ms 6136 KB Output is correct
19 Correct 70 ms 6136 KB Output is correct
20 Correct 71 ms 6264 KB Output is correct
21 Correct 70 ms 6136 KB Output is correct
22 Correct 71 ms 6188 KB Output is correct
23 Correct 357 ms 6564 KB Output is correct
24 Correct 352 ms 6520 KB Output is correct
25 Correct 357 ms 6648 KB Output is correct
26 Correct 360 ms 6520 KB Output is correct
27 Correct 379 ms 6672 KB Output is correct
28 Correct 354 ms 6520 KB Output is correct
29 Correct 352 ms 6520 KB Output is correct
30 Correct 361 ms 6648 KB Output is correct
31 Correct 361 ms 6648 KB Output is correct
32 Correct 353 ms 6520 KB Output is correct
33 Correct 355 ms 6648 KB Output is correct
34 Correct 352 ms 6492 KB Output is correct
35 Correct 355 ms 6520 KB Output is correct
36 Correct 365 ms 6620 KB Output is correct
37 Correct 352 ms 6648 KB Output is correct
38 Correct 285 ms 7396 KB Output is correct
39 Correct 321 ms 9156 KB Output is correct
40 Correct 288 ms 9372 KB Output is correct
41 Correct 298 ms 9208 KB Output is correct
42 Correct 292 ms 9356 KB Output is correct
43 Correct 285 ms 9436 KB Output is correct
44 Correct 319 ms 9080 KB Output is correct
45 Correct 293 ms 9208 KB Output is correct
46 Correct 321 ms 9228 KB Output is correct
47 Correct 304 ms 9208 KB Output is correct
48 Correct 342 ms 9080 KB Output is correct
49 Correct 296 ms 9080 KB Output is correct
50 Correct 332 ms 9268 KB Output is correct
51 Correct 294 ms 9208 KB Output is correct
52 Correct 283 ms 9404 KB Output is correct
53 Correct 304 ms 9208 KB Output is correct
54 Correct 295 ms 9208 KB Output is correct
55 Correct 293 ms 9208 KB Output is correct
56 Correct 296 ms 9180 KB Output is correct
57 Correct 324 ms 9308 KB Output is correct
58 Correct 481 ms 9236 KB Output is correct