Advertisement
HaciyevAlik

Untitled

Jan 14th, 2023
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5. using ld = long double;
  6. #define pb push_back
  7. #define ff first
  8. #define ss second
  9. #define oo 1000000000
  10.  
  11. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  12.  
  13. int main(){
  14.     ios::sync_with_stdio(false); cin.tie(0);
  15.     int n,q; cin >> n >> q;
  16.     vector<int> a(n);
  17.     for(int i=0;i<n;++i) {
  18.         cin >> a[i];
  19.     }
  20.     while(q--) {
  21.         int x,y; cin >> x >> y;
  22.         int X,Y;
  23.         for(int i=0;i<n;++i) {
  24.             if(a[i]==x) {
  25.                 X=i;
  26.             }
  27.             if(a[i]==y){
  28.                 Y=i;
  29.             }
  30.         }
  31.         swap(a[X],a[Y]);
  32.         bool f=1;
  33.         for(int i=0;i<n;++i) {
  34.             if(i==n-1) {
  35.                 if(a[i]!=n){
  36.                     if(a[i]+1 != a[0]){
  37.                         f=0; break;
  38.                     }
  39.                 } else {
  40.                     if(a[0] != 1) {
  41.                         f=0; break;
  42.                     }
  43.                 }
  44.             } else {
  45.                 if(a[i]!=n) {
  46.                     if(a[i]+1 != a[i+1]){
  47.                         f=0; break;
  48.                     }
  49.                 } else {
  50.                     if(a[i+1] != 1) {
  51.                         f=0; break;
  52.                     }
  53.                 }
  54.             }
  55.         }
  56.         if(!f) {
  57.             cout << "NE\n";
  58.         } else {
  59.             cout << "DA\n";
  60.         }
  61.     }
  62.     return 0;
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement