Advertisement
Guest User

1234

a guest
Aug 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int n,m,a,b;
  5. char W;
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(0);
  10.     cout.tie(0);
  11.     cin>>n>>m;
  12.     for(int k=0;k<m;k++){
  13.         cin>>W;
  14.         if(W=='P'){
  15.             cin>>a>>b;
  16.             a+=n-1;
  17.             b+=n-1;
  18.             while(a!=b){
  19.                 a/=2;
  20.                 b/=2;
  21.  
  22.             }
  23.             cout<<a<<"\n";
  24.         }
  25.         else{
  26.             cin>>a;
  27.             b=a;
  28.             while(a<n&&b<n){
  29.                 a=a*2;
  30.                 b=(b*2)+1;
  31.             }
  32.             cout<<a-(n-1)<<" "<<b-(n-1)<<"\n";
  33.         }
  34.     }
  35.  
  36.  
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement