Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <climits>
- #include <cstring>
- #include <string>
- #include <vector>
- #include <list>
- #include <queue>
- #include <stack>
- #include <map>
- #include <set>
- #include <functional>
- #include <algorithm>
- using namespace std;
- #define LL long long
- const int maxn = 100000 + 100;
- const LL INF = 1e18;
- int n, m, command, x, y;
- LL k;
- LL num[maxn << 2][2], lazy[maxn];
- void push_up(int rt) {
- num[rt][0] = min(num[rt << 1][0], num[rt << 1 | 1][0]);
- num[rt][1] = max(num[rt << 1][1], num[rt << 1 | 1][1]);
- }
- void update_lazy(int rt, LL lz) {
- if(abs(lazy[rt]) >= INF / abs(lz)) {
- bool flag1 = (lz > 0);
- bool flag2 = (lazy[rt] > 0);
- if(flag1 == flag2) {
- lazy[rt] = INF;
- } else {
- lazy[rt] = -INF;
- }
- } else {
- lazy[rt] *= lz;
- }
- }
- void Done(int rt, LL lz) {
- LL x = num[rt][0];
- LL y = num[rt][1];
- x /= lz;
- y /= lz;
- num[rt][0] = min(x, y);
- num[rt][1] = max(x, y);
- update_lazy(rt, lz);
- }
- void push_down(int rt) {
- if(lazy[rt] != 1) {
- Done(rt << 1, lazy[rt]);
- Done(rt << 1 | 1, lazy[rt]);
- lazy[rt] = 1;
- }
- }
- void build(int l, int r, int rt) {
- lazy[rt] = 1;
- if(l == r) {
- scanf("%I64d", &num[rt][0]);
- num[rt][1] = num[rt][0];
- return ;
- }
- int m = (l + r) >> 1;
- build(l, m, rt << 1);
- build(m + 1, r, rt << 1 | 1);
- push_up(rt);
- }
- void update(int L, int R, LL k, int l, int r, int rt) {
- if(L <= l && r <= R) {
- Done(rt, k);
- return ;
- }
- push_down(rt);
- int m = (l + r) >> 1;
- if(L <= m) {
- update(L, R, k, l, m, rt << 1);
- }
- if(m < R) {
- update(L, R, k, m + 1, r, rt << 1 | 1);
- }
- push_up(rt);
- }
- LL query(int L, int R, int l, int r, int rt) {
- if(L <= l && r <= R) {
- return num[rt][1];
- }
- int m = (l + r) >> 1;
- LL ret = -INF;
- if(L <= m) {
- ret = max(ret, query(L, R, l, m, rt << 1));
- }
- if(m < R) {
- ret = max(ret, query(L, R, m + 1, r, rt << 1 | 1));
- }
- return ret;
- }
- int main() {
- #ifdef LOCAL
- freopen("test.txt", "r", stdin);
- #endif // LOCAL
- ios::sync_with_stdio(false);
- while(scanf("%d%d", &n, &m) != EOF) {
- build(1, n, 1);
- for(int i = 0; i < m; ++i) {
- scanf("%d", &command);
- if(command == 1) {
- scanf("%d%d%I64d", &x, &y, &k);
- update(x, y, k, 1, n, 1);
- } else {
- scanf("%d%d", &x, &y);
- printf("%I64d\n", query(x, y, 1, n, 1));
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement