Submission #144206

# Submission time Handle Problem Language Result Execution time Memory
144206 2019-08-16T09:59:11 Z Abelyan Tenis (COI19_tenis) C++17
51 / 100
500 ms 3500 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=1e5+10;
const ll MOD2=998244353;
const ll MOD=1e9+7;

void yes(){
    cout<<"DA"<<endl;
}
void no(){
    cout<<"NE"<<endl;
}
/*
struct node{
    set<int> s[3],tarb[3][3];
    int qan;
    node(){qan=0;}
};

set<int>::iterator it;
node sg[4*N];



void ad(int v,int tl,int tr,int ind,int ham,int val){
    sg[v].s[ham].insert(val);
    FOR(i,3){
        if (ham==i)continue;
        it=sg[v].tarb[i][ham].find(val);
        if (it==sg[v].tarb[i][ham].end()){
            sg[v].tarb[ham][i].insert(val);
            sg[v].qan++;
        }
        else{
            sg[v].tarb[i][ham].erase(it);
            sg[v].qan--;
        }
    }
    if (tl==tr)return;
    int tm=(tl+tr)/2;
    if (ind<=tm)ad(v+v,tl,tm,ind,ham,val);
    else ad(v+v+1,tm+1,tr,ind,ham,val);
}

void rem(int v,int tl,int tr,int ind,int ham,int val){
    sg[v].s[ham].erase(val);
    FOR(i,3){
        if (ham==i)continue;
        it=sg[v].tarb[ham][i].find(val);
        if (it!=sg[v].tarb[ham][i].end()){
            sg[v].tarb[ham][i].erase(it);
            sg[v].qan--;
        }
        else{
            sg[v].tarb[i][ham].insert(val);
            sg[v].qan++;
        }
    }
    if (tl==tr)return;
    int tm=(tl+tr)/2;
    if (ind<=tm)rem(v+v,tl,tm,ind,ham,val);
    else rem(v+v+1,tm+1,tr,ind,ham,val);
}

int n,q;
int query(int v,int tl,int tr){
    if (sg[v].qan==0 && tr!=n-1) return tr-tl+1;
    if (tl==tr)return -1;
    int tm=(tl+tr)/2;
    int ans=query(v+v,tl,tm);
    if (query(v+v,tl,tm)==tm-tl+1){
        return tm-tl+1+query(v+v+1,tm+1,tr);
    }
    return ans;
}
*/
int a[3][N],ind[3][N],col[N];
int n,q,qan;


int get(){
    int pat=-1;
    qan=0;
    FOR(i,n-1){
        //cout<<a[0][i]<<" "<<a[1][i]<<" "<<a[2][i]<<endl;
        col[a[0][i]]++;
        if (col[a[0][i]]==1 )qan++;
        if (col[a[0][i]]==3)qan--;
        col[a[1][i]]++;
        if (col[a[1][i]]==1)qan++;
        if (col[a[1][i]]==3)qan--;
        col[a[2][i]]++;
        if (col[a[2][i]]==1)qan++;
        if (col[a[2][i]]==3)qan--;
        //cout<<qan<<" ";
        if (!qan)pat=i;
    }
    FORT(i,1,n)col[i]=0;
    return pat;
}

int main(){
    fastio;
    srng;
    cin>>n>>q;
    FOR(i,3)
        FORD(j,n){

            cin>>a[i][j];
            //ad(1,0,n-1,j,i,a[i][j]);
            ind[i][a[i][j]]=j;
        }
    int pat=get();
    //cout<<pat<<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]<=pat)no();
            else yes();
        }
        else{
            int tp,v,u;
            cin>>tp>>v>>u;
            tp--;
            /*
            int indv=ind[tp][v];
            int indu=ind[tp][u];

            rem(1,0,n-1,indv,tp,v);
            ad(1,0,n-1,indv,tp,u);
            rem(1,0,n-1,indu,tp,u);
            ad(1,0,n-1,indu,tp,v);
            */
            swap(ind[tp][v],ind[tp][u]);
            a[tp][ind[tp][v]]=v;
            a[tp][ind[tp][u]]=u;
            pat=get();
            //cout<<pat<<endl;

        }
    }
    return 0;
}
/*
7 2 8
C 1
C 2
C 3
C 4
C 5
C 6
O 7
O 7

*/
# 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 348 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 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 348 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 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 348 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 64 ms 3036 KB Output is correct
14 Correct 61 ms 3064 KB Output is correct
15 Correct 67 ms 3020 KB Output is correct
16 Correct 59 ms 3104 KB Output is correct
17 Correct 44 ms 3036 KB Output is correct
18 Correct 66 ms 3064 KB Output is correct
19 Correct 54 ms 3068 KB Output is correct
20 Correct 70 ms 3064 KB Output is correct
21 Correct 48 ms 3036 KB Output is correct
22 Correct 63 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 326 ms 3396 KB Output is correct
2 Correct 320 ms 3440 KB Output is correct
3 Correct 324 ms 3480 KB Output is correct
4 Correct 321 ms 3320 KB Output is correct
5 Correct 318 ms 3444 KB Output is correct
6 Correct 329 ms 3448 KB Output is correct
7 Correct 343 ms 3448 KB Output is correct
8 Correct 332 ms 3360 KB Output is correct
9 Correct 320 ms 3320 KB Output is correct
10 Correct 323 ms 3500 KB Output is correct
11 Correct 324 ms 3312 KB Output is correct
12 Correct 324 ms 3448 KB Output is correct
13 Correct 323 ms 3304 KB Output is correct
14 Correct 319 ms 3320 KB Output is correct
15 Correct 320 ms 3448 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 348 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 64 ms 3036 KB Output is correct
14 Correct 61 ms 3064 KB Output is correct
15 Correct 67 ms 3020 KB Output is correct
16 Correct 59 ms 3104 KB Output is correct
17 Correct 44 ms 3036 KB Output is correct
18 Correct 66 ms 3064 KB Output is correct
19 Correct 54 ms 3068 KB Output is correct
20 Correct 70 ms 3064 KB Output is correct
21 Correct 48 ms 3036 KB Output is correct
22 Correct 63 ms 3064 KB Output is correct
23 Correct 326 ms 3396 KB Output is correct
24 Correct 320 ms 3440 KB Output is correct
25 Correct 324 ms 3480 KB Output is correct
26 Correct 321 ms 3320 KB Output is correct
27 Correct 318 ms 3444 KB Output is correct
28 Correct 329 ms 3448 KB Output is correct
29 Correct 343 ms 3448 KB Output is correct
30 Correct 332 ms 3360 KB Output is correct
31 Correct 320 ms 3320 KB Output is correct
32 Correct 323 ms 3500 KB Output is correct
33 Correct 324 ms 3312 KB Output is correct
34 Correct 324 ms 3448 KB Output is correct
35 Correct 323 ms 3304 KB Output is correct
36 Correct 319 ms 3320 KB Output is correct
37 Correct 320 ms 3448 KB Output is correct
38 Execution timed out 1073 ms 3036 KB Time limit exceeded
39 Halted 0 ms 0 KB -