Guest User

Untitled

a guest
Jan 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <queue>
  6. #include <deque>
  7. #include <stack>
  8. #include <bitset>
  9. #include <algorithm>
  10. #include <functional>
  11. #include <numeric>
  12. #include <utility>
  13. #include <sstream>
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cstdio>
  17. #include <cmath>
  18. #include <cstdlib>
  19. #include <ctime>
  20. #include <string>
  21. #include <cstring>
  22. #include <cstdlib>
  23. #include <cassert>
  24. #include <climits>
  25. #include <cctype>
  26.  
  27. using namespace std;
  28.  
  29. #define MAXN 100001
  30.  
  31. int tree[MAXN*4];
  32.  
  33. int n, q,c[MAXN];
  34.  
  35. void update( int node , int a , int b , int p , int val )
  36. {
  37. if( b < p || p < a) return ;
  38. if( a == b )
  39. {
  40. tree[node] = val;
  41. return;
  42. }
  43. update(2*node+1,a,(a+b)/2,p,val);
  44. update(2*node+2,(a+b)/2+1,b,p,val);
  45. tree[node] = min( tree[2*node + 1],tree[2*node+2]);
  46. }
  47. void init( int node , int a , int b )
  48. {
  49. if( a == b )
  50. {
  51. tree[node] = c[a];
  52. return;
  53. }
  54. init(2*node +1 ,a,(a+b)/2);
  55. init(2*node+2,(a+b)/2+1,b);
  56. tree[node] = min(tree[2*node+1],tree[2*node+2]);
  57. }
  58. int query( int node , int a , int b , int p , int q )
  59. {
  60. if( q < a || b < p )return INT_MAX;
  61. if( a >= p && b <= q )
  62. return tree[node];
  63. return min( query(2*node+1,a,(a+b)/2,p,q),query(2*node+2,(a+b)/2+1,b,p,q));
  64. }
  65. int main()
  66. {
  67. scanf("%d %d ", &n,&q);
  68. for(int i = 0 ; i < n ; i++ )
  69. scanf("%d", &c[i]);
  70. init(0, 0, n-1);
  71. char s[100];
  72. while(q--)
  73. {
  74. scanf("%s",s);
  75. if( s[0] == 'q' )
  76. {
  77. int a1,a2;
  78. int ns=strlen(s);
  79. for( int j = 0 ; j < ns ; j++ )
  80. if( !isdigit(s[j]) ) s[j]=' ';
  81.  
  82. istringstream in(s);
  83. in>>a1>>a2;
  84. printf("%d\n",query(0, 0,n-1, a1-1, a2-1));
  85. }
  86. else
  87. {
  88. int ns=strlen(s);
  89. for( int j = 0 ; j < ns ; j++ )
  90. if( !isdigit(s[j]) ) s[j]=' ';
  91.  
  92. istringstream in(s);
  93. vector<int> v;
  94. int x;
  95. while(in>>x) v.push_back(x-1);
  96.  
  97. int nw = v.size();
  98. vector<int>w;
  99. for(int k = 0 ; k < nw ; k++ )
  100. w.push_back(c[v[k]]);
  101. for( int k = 1 ; k < nw ; k++)
  102. {
  103. update(0,0,n-1,v[k-1],w[k]);
  104. c[v[k-1]] = w[k];
  105. }
  106. update(0,0,n-1,v[nw-1],w[0]);
  107. c[v[nw-1]] = w[0];
  108. }
  109. }
  110. }
Add Comment
Please, Sign In to add comment