fork(1) download
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5.  
  6. ll gb=-1;
  7. void build_tree(ll int *a, ll int s,ll int e, ll int *tree, ll int index)
  8. {
  9. if(s==e)
  10. {
  11. tree[index] = a[s];
  12. return;
  13. }
  14. ll int mid = (s+e)/2;
  15. build_tree(a,s,mid,tree,2*index);
  16. build_tree(a,mid+1,e,tree,2*index+1);
  17. tree[index] = max(tree[2*index],tree[2*index+1]);
  18. return;
  19. }
  20. void query(ll int *tree,ll int ss,ll int se,ll x ,ll int index)
  21. {
  22. //complete overlap
  23.  
  24. if(tree[index]<x)
  25. return;
  26. if(gb>=0)
  27. return;
  28. if(ss==se)
  29. {
  30. if(tree[index]>=x)
  31. gb=ss;
  32. return;
  33. }
  34. ll int mid = (ss + se)/2;
  35. query(tree,ss,mid,x,2*index);
  36. query(tree,mid+1,se,x,2*index+1);
  37. return;
  38.  
  39. }
  40. //point update
  41. void point_update(ll int *tree, ll int ss,ll int se, ll int i,ll int inc,ll int index)
  42. {
  43. if(i>se || i<ss)
  44. return;
  45. if(ss == se)
  46. {
  47. tree[index] = inc;
  48. return;
  49. }
  50. ll int mid = (ss + se)/2;
  51. point_update(tree,ss,mid,i,inc,2*index);
  52. point_update(tree,mid+1,se,i,inc,2*index+1);
  53. tree[index] = max(tree[2*index],tree[2*index+1]);
  54. return;
  55. }
  56.  
  57. void solve()
  58. {
  59. int n,q;
  60. cin>>n>>q;
  61.  
  62. ll a[n];
  63. for(int i=0;i<n;i++)
  64. cin>>a[i];
  65. ll tree[4*n+1]={0};
  66. build_tree(a,0,n-1,tree,1);
  67.  
  68. while(q--)
  69. {
  70. ll num;
  71. cin>>num;
  72. if(num==1)
  73. {
  74. ll l,r;
  75. cin>>l>>r;
  76. point_update(tree,0,n-1,l,r,1);
  77.  
  78. }
  79. else
  80. {
  81. ll x;
  82. cin>>x;
  83. gb=-1;
  84. query(tree,0,n-1,x,1);
  85. cout<<gb<<endl;
  86. }
  87.  
  88. }
  89.  
  90. }
  91. int main()
  92. {
  93. ios_base::sync_with_stdio(false);
  94. cin.tie(NULL);
  95.  
  96. ll int t=1;
  97. // cin>>t;
  98. while(t--)
  99. {
  100. solve();
  101. }
  102.  
  103. return 0;
  104. }
  105.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:65:10: error: variable-sized object may not be initialized
        ll tree[4*n+1]={0};
                ^~~~~
1 error generated.
stdout
Standard output is empty