Submission #167312

# Submission time Handle Problem Language Result Execution time Memory
167312 2019-12-07T09:29:43 Z theStaticMind Tenis (COI19_tenis) C++14
0 / 100
139 ms 21188 KB
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
vector<vector<int>> data(3,vector<int>(100005));
vector<vector<int>> arr(3);
vector<int> P(3,0);
vector<vector<int>> adj(100005,vector<int>(3,0));
vector<vector<int>> radj(100005,vector<int>(3,0));
vector<bool>vis(100005,false);
vector<bool>win(100005,false);
void dfs(int x){
      vis[x]=true;
      for(int i=0;i<3;i++){
            int y=adj[x][i];
            if(vis[y])continue;
            dfs(y);
      }
}
void rdfs(int x){
      win[x]=true;
      for(int i=0;i<3;i++){
            int y=radj[x][i];
            if(win[y])continue;
            rdfs(y);
      }
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      int n,q;
      cin>>n>>q;
      for(int k=0;k<3;k++){
            for(int i=0;i<n;i++){
                  int x;
                  cin>>x;
                  arr[k].pb(x);
                  data[k][x]=i;
                  if(i==0)P[k]=x;
            }
            arr[k].pb(0);
      }
      for(int k=0;k<3;k++)
      for(int i=0;i<n;i++){
            int x=arr[k][i];
            adj[x][k]=arr[k][i+1];
            radj[arr[k][i+1]][k]=x;
      }
      for(int i=0;i<3;i++){
            rdfs(arr[i][0]);
      }
      bool task4=true;
      while(q--){
            int k;
            cin>>k;
            if(k==1){
                  int x;
                  cin>>x;
                  if(task4){
                        if(win[x])cout<<"DA\n";
                        else cout<<"NE\n";
                        continue;
                  }
                  for(int i=1;i<=n;i++)vis[i]=false;
                  bool yes=true;
                  dfs(x);
                  for(int i=1;i<=n;i++)yes=(yes&vis[i]);
                  if(yes)cout<<"DA\n";
                  else cout<<"NE\n";
            }
            else{
                  task4=false;
                  int p,x,y;
                  cin>>p>>x>>y;p--;
                  swap(arr[p][data[p][x]],arr[p][data[p][y]]);
                  swap(data[p][x],data[p][y]);
                  int X=data[p][x];
                  int Y=data[p][y];
                  adj[x][p]=arr[p][X+1];
                  adj[y][p]=arr[p][Y+1];
                  if(X>0){
                        adj[arr[p][X-1]][p]=x;
                  }
                  if(Y>0){
                        adj[arr[p][Y-1]][p]=y;
                  }
            }
      }

}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 13672 KB Output is correct
2 Incorrect 23 ms 13672 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 13672 KB Output is correct
2 Incorrect 23 ms 13672 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 13672 KB Output is correct
2 Incorrect 23 ms 13672 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 139 ms 21188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 13672 KB Output is correct
2 Incorrect 23 ms 13672 KB Output isn't correct
3 Halted 0 ms 0 KB -