Advertisement
Dmaxiya

Untitled

Apr 23rd, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cstring>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <functional>
  15. #include <algorithm>
  16. using namespace std;
  17.  
  18. #define LL long long
  19. const int maxn = 100000 + 100;
  20. const LL INF = 1e18;
  21. int n, m, command, x, y;
  22. LL k;
  23. LL num[maxn << 2][2], lazy[maxn];
  24.  
  25. void push_up(int rt) {
  26. num[rt][0] = min(num[rt << 1][0], num[rt << 1 | 1][0]);
  27. num[rt][1] = max(num[rt << 1][1], num[rt << 1 | 1][1]);
  28. }
  29.  
  30. void update_lazy(int rt, LL lz) {
  31. if(abs(lazy[rt]) >= INF / abs(lz)) {
  32. bool flag1 = (lz > 0);
  33. bool flag2 = (lazy[rt] > 0);
  34. if(flag1 == flag2) {
  35. lazy[rt] = INF;
  36. } else {
  37. lazy[rt] = -INF;
  38. }
  39. } else {
  40. lazy[rt] *= lz;
  41. }
  42. }
  43.  
  44. void Done(int rt, LL lz) {
  45. LL x = num[rt][0];
  46. LL y = num[rt][1];
  47. x /= lz;
  48. y /= lz;
  49. num[rt][0] = min(x, y);
  50. num[rt][1] = max(x, y);
  51. update_lazy(rt, lz);
  52. }
  53.  
  54. void push_down(int rt) {
  55. if(lazy[rt] != 1) {
  56. Done(rt << 1, lazy[rt]);
  57. Done(rt << 1 | 1, lazy[rt]);
  58. lazy[rt] = 1;
  59. }
  60. }
  61.  
  62. void build(int l, int r, int rt) {
  63. lazy[rt] = 1;
  64. if(l == r) {
  65. scanf("%I64d", &num[rt][0]);
  66. num[rt][1] = num[rt][0];
  67. return ;
  68. }
  69. int m = (l + r) >> 1;
  70. build(l, m, rt << 1);
  71. build(m + 1, r, rt << 1 | 1);
  72. push_up(rt);
  73. }
  74.  
  75. void update(int L, int R, LL k, int l, int r, int rt) {
  76. if(L <= l && r <= R) {
  77. Done(rt, k);
  78. return ;
  79. }
  80. push_down(rt);
  81. int m = (l + r) >> 1;
  82. if(L <= m) {
  83. update(L, R, k, l, m, rt << 1);
  84. }
  85. if(m < R) {
  86. update(L, R, k, m + 1, r, rt << 1 | 1);
  87. }
  88. push_up(rt);
  89. }
  90.  
  91. LL query(int L, int R, int l, int r, int rt) {
  92. if(L <= l && r <= R) {
  93. return num[rt][1];
  94. }
  95. int m = (l + r) >> 1;
  96. LL ret = -INF;
  97. if(L <= m) {
  98. ret = max(ret, query(L, R, l, m, rt << 1));
  99. }
  100. if(m < R) {
  101. ret = max(ret, query(L, R, m + 1, r, rt << 1 | 1));
  102. }
  103. return ret;
  104. }
  105.  
  106. int main() {
  107. #ifdef LOCAL
  108. freopen("test.txt", "r", stdin);
  109. #endif // LOCAL
  110. ios::sync_with_stdio(false);
  111.  
  112. while(scanf("%d%d", &n, &m) != EOF) {
  113. build(1, n, 1);
  114. for(int i = 0; i < m; ++i) {
  115. scanf("%d", &command);
  116. if(command == 1) {
  117. scanf("%d%d%I64d", &x, &y, &k);
  118. update(x, y, k, 1, n, 1);
  119. } else {
  120. scanf("%d%d", &x, &y);
  121. printf("%I64d\n", query(x, y, 1, n, 1));
  122. }
  123. }
  124. }
  125.  
  126. return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement