fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. void Abdullah() {
  4. ios_base::sync_with_stdio(0),
  5. cin.tie(0), cout.tie(0);
  6. }
  7. long long fast_power(long long base, long long power, long long mod = 1e9 + 7) {
  8. long long result = 1;
  9. base = base % mod;
  10.  
  11. while (power > 0) {
  12. if (power % 2 == 1) {
  13. result = (result * base) % mod;
  14. }
  15. base = (base * base) % mod;
  16. power = power / 2;
  17. }
  18.  
  19. return result;
  20. }
  21. int main() {
  22. Abdullah();
  23. int n ; cin>>n ;
  24. vector<int>v(n+2,0);
  25. for(int i=1 ; i<=n ; i++){
  26. cin>>v[i];
  27. }
  28. int q ; cin>>q ;
  29. int cnt_inc =0 ;
  30. int cnt_dec =0 ;
  31. for(int i=2 ; i<=n ; i++){
  32. if(v[i]>v[i-1]){
  33. cnt_inc++;
  34. }
  35. else{
  36. cnt_dec++;
  37. }
  38.  
  39. }
  40. while(q--){
  41. int y;cin>>y;
  42. if(y==1){
  43. int index , x ;
  44. cin>>index>>x ;
  45. int index_before = index-1 ;
  46. int index_after = index+1;
  47. if(v[index] > v[index_before]){
  48. if(x < v[index_before]){
  49. cnt_inc--;
  50. cnt_dec++;
  51. }
  52.  
  53. }
  54. if(v[index] < v[index_before]){
  55. if(x > v[index_before]){
  56. cnt_inc++;
  57. cnt_dec--;
  58. }
  59. }
  60. if(v[index] < v[index_after]){
  61. if(x > v[index_after]){
  62. cnt_inc--;
  63. cnt_dec++;
  64. }
  65. }
  66. if(v[index] > v[index_after]){
  67. if(x < v[index_after]){
  68. cnt_dec--;
  69. cnt_inc++;
  70. }
  71. }
  72. }
  73. else if(y==2){
  74. if(cnt_inc == n-1 && cnt_dec ==0){cout<<"YES\n";}
  75. else{cout<<"NO\n";}
  76. }
  77. else{
  78. if(cnt_dec == n-1 && cnt_inc==0){cout<<"YES\n";}
  79. else{cout<<"NO\n";}
  80. }
  81. }
  82.  
  83.  
  84.  
  85. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
NO
NO