fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.math.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Main
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. new Main().run();
  14. }
  15.  
  16. int inf_res[] = {Integer.MAX_VALUE, Integer.MAX_VALUE};
  17. int a[], t[][];
  18.  
  19.  
  20. void run() {
  21. try {
  22. int n = nextInt();
  23. int k = nextInt();
  24. a = new int[n];
  25. for (int i = 0; i < n; i++) {
  26. a[i] = nextInt();
  27. }
  28. t = new int[2][4 * n];
  29. build(1, 0, n - 1);
  30. int m = nextInt();
  31. for (int i = 0; i < m; i++) {
  32. int q = nextInt();
  33. if (q == 1) {
  34. int l = nextInt() - 1;
  35. int r = nextInt() - 1;
  36. int[] res = query(1, 0, n - 1, l, r);
  37. if (res[0] < Integer.MAX_VALUE && res[1] < Integer.MAX_VALUE && res[0] + res[1] <= k)
  38. out.println("Yes");
  39. else
  40. out.println("No");
  41. } else {
  42. int l = nextInt() - 1;
  43. int x = nextInt();
  44. update(1, 0, n - 1, l, x);
  45. }
  46. }
  47. out.close();
  48. } catch (Exception e) {
  49. e.printStackTrace(out);
  50. out.close();
  51. //while (true);
  52. }
  53. }
  54.  
  55. void combine(int s1, int s2, int res) {
  56. if (t[0][s1] < t[0][s2]) {
  57. t[0][res] = t[0][s1];
  58. if (t[1][s1] < t[0][s2])
  59. t[1][res] = t[1][s1];
  60. else
  61. t[1][res] = t[0][s2];
  62. } else {
  63. t[0][res] = t[0][s2];
  64. if (t[0][s1] < t[1][s2])
  65. t[1][res] = t[0][s1];
  66. else
  67. t[1][res] = t[1][s2];
  68. }
  69. }
  70.  
  71. void combine2(int[] s1, int[] s2, int[] res) {
  72. if (s1[0] < s2[0]) {
  73. res[0] = s1[0];
  74. if (s1[1] < s2[0])
  75. res[1] = s1[1];
  76. else
  77. res[1] = s2[0];
  78. } else {
  79. res[0] = s2[0];
  80. if (s1[0] < s2[1])
  81. res[1] = s1[0];
  82. else
  83. res[1] = s2[1];
  84. }
  85. }
  86.  
  87. void build(int v, int tl, int tr) {
  88. if (tl == tr) {
  89. t[0][v] = a[tl];
  90. t[1][v] = Integer.MAX_VALUE;
  91. return;
  92. }
  93. int tm = (tl + tr) >> 1;
  94. build(v << 1, tl, tm);
  95. build((v << 1) + 1, tm + 1, tr);
  96. combine(v << 1, (v << 1) + 1, v);
  97. }
  98.  
  99. void update(int v, int tl, int tr, int pos, int x) {
  100. if (tl == tr) {
  101. t[0][v] = x;
  102. t[1][v] = Integer.MAX_VALUE;
  103. return;
  104. }
  105. int tm = (tl + tr) >> 1;
  106. if (pos <= tm)
  107. update(v << 1, tl, tm, pos, x);
  108. else
  109. update((v << 1) + 1, tm + 1, tr, pos, x);
  110. combine(v << 1, (v << 1) + 1, v);
  111. }
  112.  
  113. int[] query(int v, int tl, int tr, int l, int r) {
  114. if (l > r)
  115. return inf_res;
  116. if (l == tl && r == tr) {
  117. int[] res = new int[2];
  118. res[0] = t[0][v];
  119. res[1] = t[1][v];
  120. return res;
  121. }
  122. int tm = (tl + tr) >> 1;
  123. int[] q1 = query(v << 1, tl, tm, l, Math.min(tm, r));
  124. int[] q2 = query((v << 1) + 1, tm + 1, tr, Math.max(l, tm + 1), r);
  125. int[] res = new int[2];
  126. combine2(q1, q2, res);
  127. return res;
  128. }
  129.  
  130. int nextInt() throws Exception {
  131. st.nextToken();
  132. return (int) st.nval;
  133. }
  134.  
  135. }
Success #stdin #stdout 0.07s 380224KB
stdin
6 9
1 3 1 6 6 7
8
1 1 6
1 1 2
2 4 7
1 4 5
1 5 6
2 1 7
2 3 8
1 1 6
stdout
Yes
Yes
No
No
Yes