Naxocist

AEIOU

Apr 4th, 2022
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define endll '\n'
  3. using namespace std;
  4.  
  5. const int N = 1e6 + 3;
  6. pair<int, int> a[N];
  7.  
  8. int main()
  9. {
  10.     int n, t; scanf("%d%d", &n, &t);
  11.     for(int i=1; i<= n; ++i){
  12.         a[i].first = i-1;
  13.         a[i].second = i+1;
  14.         if(i == 1) a[i].first = -1;
  15.         if(i == n) a[i].second = -1;
  16.     }
  17.  
  18.     while(t--){
  19.         int l, r; scanf("%d%d", &l, &r);
  20.         a[a[l].first].second = a[r].second;
  21.         a[a[r].second].first = a[l].first;
  22.         int x = a[a[r].second].first, y = a[a[l].first].second;
  23.  
  24.         if(x == -1) printf("* ");
  25.         else printf("%d ", x);
  26.         if(y == -1) printf("*\n");
  27.         else printf("%d\n", y);
  28.     }
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment