fork download
  1. #define DEBUG 1
  2. #include <algorithm>
  3. #include <functional>
  4. #include <numeric>
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <cstdio>
  8. #include <cmath>
  9. #include <complex>
  10. #include <cstdlib>
  11. #include <ctime>
  12. #include <cstring>
  13. #include <cassert>
  14. #include <string>
  15. #include <vector>
  16. #include <list>
  17. #include <map>
  18. #include <set>
  19. #include <deque>
  20. #include <queue>
  21. #include <stack>
  22. #include <bitset>
  23. #include <sstream>
  24. using namespace std;
  25. #define LL long long
  26. #define LD long double
  27. #define PR pair<int,int>
  28. #define Fox(i,n) for (i=0; i<n; i++)
  29. #define Fox1(i,n) for (i=1; i<=n; i++)
  30. #define FoxI(i,a,b) for (i=a; i<=b; i++)
  31. #define FoxR(i,n) for (i=(n)-1; i>=0; i--)
  32. #define FoxR1(i,n) for (i=n; i>0; i--)
  33. #define FoxRI(i,a,b) for (i=b; i>=a; i--)
  34. #define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
  35. #define Min(a,b) a=min(a,b)
  36. #define Max(a,b) a=max(a,b)
  37. #define Sz(s) int((s).size())
  38. #define All(s) (s).begin(),(s).end()
  39. #define Fill(s,v) memset(s,v,sizeof(s))
  40. #define pb push_back
  41. #define mp make_pair
  42. #define x first
  43. #define y second
  44.  
  45. #define VV vector<int>
  46.  
  47. #if DEBUG
  48. #define GETCHAR getchar
  49. #else
  50. #define GETCHAR getchar_unlocked
  51. #endif
  52.  
  53. char c;
  54. bool Read(LL &x)
  55. {
  56. char c,r=0,n=0;
  57. x=0;
  58. for(;;)
  59. {
  60. c=GETCHAR();
  61. if ((c<0) && (!r))
  62. return(0);
  63. if ((c=='-') && (!r))
  64. n=1;
  65. else
  66. if ((c>='0') && (c<='9'))
  67. x=x*10+c-'0',r=1;
  68. else
  69. if (r)
  70. break;
  71. }
  72. if (n)
  73. x=-x;
  74. return(1);
  75. }
  76. bool Read(int &x)
  77. {
  78. char c,r=0,n=0;
  79. x=0;
  80. for(;;)
  81. {
  82. c=GETCHAR();
  83. if ((c<0) && (!r))
  84. return(0);
  85. if ((c=='-') && (!r))
  86. n=1;
  87. else
  88. if ((c>='0') && (c<='9'))
  89. x=x*10+c-'0',r=1;
  90. else
  91. if (r)
  92. break;
  93. }
  94. if (n)
  95. x=-x;
  96. return(1);
  97. }
  98. #define N 100001
  99.  
  100. LL a[N];
  101. std::set<int> myset[6];
  102.  
  103. void update(int idx, int d)
  104. {
  105.  
  106.  
  107. if(a[idx] % 2 == 0)
  108. {
  109. myset[2].erase(idx);
  110. }
  111. if(a[idx] % 3 == 0)
  112. {
  113. myset[3].erase(idx);
  114. }
  115. if(a[idx]%5 == 0)
  116. {
  117. myset[5].erase(idx);
  118. }
  119. if(d % 2 == 0)
  120. {
  121. myset[2].insert(idx);
  122. }
  123.  
  124. if(d % 3 == 0)
  125. {
  126. myset[3].insert(idx);
  127. }
  128.  
  129. if(d % 5 == 0)
  130. {
  131. myset[5].insert(idx);
  132.  
  133. }
  134. a[idx] = d;
  135.  
  136. }
  137. int main()
  138. {
  139.  
  140. if(DEBUG)
  141. {
  142. freopen("/home/kshitij/Desktop/in","r", stdin);
  143. }
  144. int n,m,i,j;
  145. set<int>::iterator it;
  146. Read(n);
  147. for(i = 0 ; i < n ; i++)
  148. {
  149. Read(a[i]);
  150. if(a[i]%2 == 0)
  151. {
  152. myset[2].insert(i);
  153. }
  154. if(a[i]%3 == 0)
  155. {
  156. myset[3].insert(i);
  157. }
  158. if(a[i]%5 == 0)
  159. {
  160. myset[5].insert(i);
  161. }
  162. }
  163. Read(m);
  164. while(m--)
  165. {
  166. int type;
  167. Read(type);
  168. if(type == 1)
  169. {
  170. int l,r,p;
  171. Read(l);
  172. l--;
  173. Read(r);
  174. r--;
  175. Read(p);
  176. for(it = myset[p].lower_bound(l); it != myset[p].end(); it++ )
  177. {
  178. if(*it > r)
  179. {
  180. break;
  181. }
  182.  
  183. a[*it] = a[*it] / p;
  184. if(a[*it] % p != 0)
  185. {
  186. myset[p].erase(*it);
  187. }
  188. }
  189. }
  190. else
  191. {
  192. int l,d;
  193. Read(l);
  194. Read(d);
  195. l--;
  196. update(l,d);
  197. }
  198.  
  199.  
  200. }
  201. for(i = 0 ; i < n ; i++)
  202. {
  203. printf("%lld " , a[i]);
  204. }
  205. return 0;
  206. }
  207.  
Success #stdin #stdout 0s 3508KB
stdin
Standard input is empty
stdout
Standard output is empty