Advertisement
Ahmed_Negm

Untitled

Apr 9th, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include<iomanip>
  4. #include<algorithm>
  5. #include<cstdlib>
  6. #include<cstring>
  7. #include<vector>
  8. #include<utility>
  9.  
  10. #define ll long long
  11. #define sz(x) int(x.size())
  12. #define all(x) x.begin(),x.end()
  13. using namespace std;
  14.  
  15. void Fast_IO(){
  16.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  17.     #ifndef ONLINE_JUDGE
  18.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  19.     #endif
  20. }
  21.  
  22.  
  23.  
  24.  
  25.  
  26. void solve(){
  27.   ll n,q; cin>>n>>q;
  28.   vector<ll>v;
  29. ll small[100005]{};
  30. ll big[100005]{};
  31. ll j =1;
  32.   for(int i=0; i<n; i++){
  33.       ll x; cin>>x;
  34.       v.push_back(x);
  35.       if(i>0){
  36.           if(v[i-1]<=v[i]){
  37.               small[i]=j;
  38.               small[i+1]=j;
  39.           }else if(v[i-1]>=v[i]){
  40.               big[i]=j;
  41.               big[i+1]=j;
  42.           }
  43.       }
  44.       if(i>1){
  45.           if(v[i-1]<v[i]&&v[i-1]<v[i-2]){
  46.               small[i]=j+1;
  47.               j++;
  48.           }
  49.           else if(v[i-1]>v[i]&& v[i-1]>v[i-2]){
  50.               big[i]=j+1;
  51.              
  52.               j++;
  53.       }
  54.   }
  55.   }
  56. //   big[n]=big[n-1];
  57. //   small[n]=small[n-1];
  58.  
  59. //   for(int i=1; i<=n; i++){
  60. //       cout<<small[i]<<' ';
  61. //   }
  62. //   cout<<'\n';
  63.  
  64.   while(q--){
  65.       ll l,r; cin>>l>>r;
  66.      
  67.       if(l==r){
  68.           cout<<"Yes\n";
  69.           continue;
  70.       }
  71.       else if(r-l==1){
  72.           cout<<"Yes\n";
  73.           continue;
  74.       }
  75.  if(v[l-1]==v[r-1]){
  76.      if(small[l]==small[r] || big[l]==big[r]) cout<<"Yes\n";
  77.      else cout<<"No\n";
  78.  } else if(v[l-1]>v[r-1]){
  79.      if(big[l]==big[r]){
  80.          cout<<"Yes\n";
  81.      }else cout<<"No\n";
  82.  } else{
  83.      if(small[l]==small[r]){
  84.          cout<<"Yes\n";
  85.      }else cout<<"No\n";
  86.  }
  87.  
  88. }
  89. }
  90.  
  91. int main(){
  92.     Fast_IO();
  93. int t =1;
  94. //cin>>t;
  95. while(t--){
  96. solve();
  97. }
  98. return 0;
  99. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement