fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5.  
  6. int main(){
  7.  
  8. ll n,q;
  9. cin>>n>>q;
  10. vector<ll>A(n+1);
  11. for(int i=1;i<=n;i++)
  12. cin>>A[i];
  13.  
  14. vector<ll> dp(n+1);
  15. for(int i=1;i<=n;i++){
  16. dp[i] = i;
  17. }
  18. int i=2,l=1;
  19. while(i<=n){
  20.  
  21. while(i<=n and A[i]>=A[i-1]){
  22. dp[i] = l;
  23. i++;
  24. }
  25. while(i<=n and A[i]<=A[i-1]){
  26. dp[i] = l;
  27. i++;
  28. }
  29. l=i-1;
  30. }
  31. for(int i=1;i<=n;i++)
  32. cout<<dp[i]<<" ";
  33. cout<<endl;
  34. while(q--){
  35. int li,ri;
  36. cin>>li>>ri;
  37. if(li>=dp[ri])
  38. cout<<"Yes"<<endl;
  39. else
  40. cout<<"No"<<endl;
  41. }
  42. return 0;
  43. }
  44.  
  45. /*
  46. 0 12
  47. 3 2 1 45 6 3 2 14 5 0
  48. 1 3
  49. 2 3
  50. 2 4
  51. 8 8
  52. 1 4
  53. 5 8
  54. 4 10
  55. 8 10
  56. 9 10
  57. 10 10
  58. 6 10
  59. 5 10
  60.  
  61. */
Runtime error #stdin #stdout #stderr 0s 4304KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc