Advertisement
a53

B_o_g_d_a_n_OF

a53
Jun 14th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. /* Ionut Dobricean
  2. * Arbori + Parsare
  3. * 100 puncte
  4. */
  5. #include <cstdio>
  6. using namespace std;
  7.  
  8. const int Dim = 100001;
  9. int Tree[Dim * 4], n,O,A[Dim],s;
  10.  
  11. void Get (int &x);
  12. void Update(int node, int le,int ri,int pos ,int val);
  13. void Query(int node , int le , int ri , int a , int b);
  14.  
  15. int main() {
  16.  
  17. freopen("bogdan.in","r",stdin);
  18. freopen("bogdan.out","w", stdout);
  19. Get(n);
  20. for ( int i = 1; i <= n; ++i) {
  21. Get(A[i]);
  22. if( A[i] < A[i-1] )
  23. Update(1,1,n,i,1);
  24. else
  25. Update(1,1,n,i,0);
  26. }
  27. Get(O);
  28. int type, x, y;
  29. for ( int i = 1; i <= O; ++i) {
  30. Get(type), Get(x), Get(y);
  31. if ( type == 1) {
  32. A[x] = y;
  33. {
  34. if ( A[x] < A[x-1])
  35. Update(1,1,n,x,1);
  36. else
  37. Update(1,1,n,x,0);
  38. }
  39. if( A[x+1] < A[x] )
  40. Update(1,1,n,x+1,1);
  41. else
  42. Update(1,1,n,x+1,0);
  43. }
  44. else {
  45. s = 0;
  46. Query(1,1,n,x + 1,y);
  47. if ( s == 0 )
  48. printf("DA\n");
  49. else
  50. printf("NU\n");
  51. }
  52. }
  53. return 0;
  54. }
  55.  
  56. void Update(int node, int le,int ri,int pos ,int val) {
  57. if(le == ri) {
  58. Tree[node] = val;
  59. return ;
  60. }
  61. int mj = (le + ri) / 2;
  62. if( pos <= mj)
  63. Update(node * 2, le, mj , pos , val);
  64. else
  65. Update(node * 2 + 1 , mj + 1 , ri , pos , val);
  66. Tree[node] = Tree[node * 2] + Tree[node * 2 + 1];
  67. }
  68. void Query(int node , int le , int ri , int a , int b){
  69. if(a <= le and b >= ri) {
  70. s += Tree[node];
  71. return ;
  72. }
  73. int mj = (le + ri) / 2;
  74. if(a <= mj)
  75. Query(2 * node, le , mj, a , b);
  76. if(b > mj)
  77. Query(2 * node + 1, mj + 1 , ri ,a , b);
  78. }
  79.  
  80. const int Lim = 1000001;
  81. int u = Lim - 1;
  82. char S[Lim];
  83.  
  84. void Next () {
  85. if (++u == Lim)
  86. std::fread(S, 1, Lim, stdin), u = 0;
  87. }
  88.  
  89. void Get (int &x) {
  90.  
  91. for (; S[u] < '0' || S[u] > '9'; Next());
  92. for (x = 0; S[u] >= '0' and S[u] <= '9'; Next())
  93. x = x * 10 + S[u] - '0';
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement