Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- using ld = long double;
- #define pb push_back
- #define ff first
- #define ss second
- #define oo 1000000000
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- int main(){
- ios::sync_with_stdio(false); cin.tie(0);
- int n,q; cin >> n >> q;
- vector<int> a(n);
- for(int i=0;i<n;++i) {
- cin >> a[i];
- }
- while(q--) {
- int x,y; cin >> x >> y;
- int X,Y;
- for(int i=0;i<n;++i) {
- if(a[i]==x) {
- X=i;
- }
- if(a[i]==y){
- Y=i;
- }
- }
- swap(a[X],a[Y]);
- bool f=1;
- for(int i=0;i<n;++i) {
- if(i==n-1) {
- if(a[i]!=n){
- if(a[i]+1 != a[0]){
- f=0; break;
- }
- } else {
- if(a[0] != 1) {
- f=0; break;
- }
- }
- } else {
- if(a[i]!=n) {
- if(a[i]+1 != a[i+1]){
- f=0; break;
- }
- } else {
- if(a[i+1] != 1) {
- f=0; break;
- }
- }
- }
- }
- if(!f) {
- cout << "NE\n";
- } else {
- cout << "DA\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement