1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <vector> 7 #include <queue> 8 9 using namespace std; 10 11 typedef long long LL; 12 const int INF = 2e9; 13 LL max_ans, min_ans; 14 15 struct segtree 16 { 17 static const int TN = 2e5 + 10; 18 struct node 19 { 20 LL maxv, minv, add; 21 } tree[TN<<2]; 22 23 void pushUp(int k) 24 { 25 tree[k].maxv = max(tree[k<<1].maxv, tree[k<<1|1].maxv); 26 tree[k].minv = min(tree[k<<1].minv, tree[k<<1|1].minv); 27 } 28 29 void pushDown(int k) 30 { 31 if(tree[k].add != 0) 32 { 33 tree[k<<1].add += tree[k].add; 34 tree[k<<1].minv += tree[k].add; 35 tree[k<<1].maxv += tree[k].add; 36 37 tree[k<<1|1].add += tree[k].add; 38 tree[k<<1|1].minv += tree[k].add; 39 tree[k<<1|1].maxv += tree[k].add; 40 41 tree[k].add = 0; 42 } 43 44 tree[k<<1].maxv = min(tree[k<<1].maxv, tree[k].maxv); 45 tree[k<<1].maxv = max(tree[k<<1].maxv, tree[k].minv); 46 tree[k<<1].minv = max(tree[k<<1].minv, tree[k].minv); 47 tree[k<<1].minv = min(tree[k<<1].minv, tree[k].maxv); 48 49 tree[k<<1|1].maxv = min(tree[k<<1|1].maxv, tree[k].maxv); 50 tree[k<<1|1].maxv = max(tree[k<<1|1].maxv, tree[k].minv); 51 tree[k<<1|1].minv = max(tree[k<<1|1].minv, tree[k].minv); 52 tree[k<<1|1].minv = min(tree[k<<1|1].minv, tree[k].maxv); 53 } 54 55 void build(int l, int r, int k) 56 { 57 tree[k].add = 0; 58 if(l == r) 59 { 60 scanf("%I64d", &tree[k].maxv); 61 tree[k].minv = tree[k].maxv; 62 return ; 63 } 64 int mid = (l+r)>>1; 65 build(l, mid, k<<1); 66 build(mid+1, r, k<<1|1); 67 pushUp(k); 68 } 69 70 void update(int l, int r, int k, int a, int b, int op, LL c) 71 { 72 if(a > r || b < l) return ; 73 if(a <= l && r <= b) 74 { 75 if(op == 1) 76 { 77 tree[k].add += c; 78 tree[k].maxv += c; 79 tree[k].minv += c; 80 } 81 else if(op == 2) 82 { 83 tree[k].maxv = min(tree[k].maxv, c); 84 tree[k].minv = min(tree[k].minv, c); 85 } 86 else if(op == 3) 87 { 88 tree[k].maxv = max(tree[k].maxv, c); 89 tree[k].minv = max(tree[k].minv, c); 90 } 91 return ; 92 } 93 pushDown(k); 94 int mid = (l+r)>>1; 95 if(a <= mid) 96 update(l, mid, k<<1, a, b, op, c); 97 if(b > mid) 98 update(mid+1, r, k<<1|1, a, b, op, c); 99 pushUp(k); 100 } 101 102 void query(int l, int r, int k, int a, int b) 103 { 104 if(a > r || b < l) return ; 105 if(a <= l && r <= b) 106 { 107 max_ans = max(max_ans, tree[k].maxv); 108 min_ans = min(min_ans, tree[k].minv); 109 return ; 110 } 111 pushDown(k); 112 int mid = (l+r)>>1; 113 if(a <= mid) 114 query(l, mid, k<<1, a, b); 115 if(b > mid) 116 query(mid+1, r, k<<1|1, a, b); 117 pushUp(k); 118 } 119 } T; 120 121 int work() 122 { 123 int n, q, op, l, r; LL c; 124 scanf("%d %d", &n, &q); 125 T.build(1, n, 1); 126 while(q--) 127 { 128 scanf("%d %d %d", &op, &l, &r); 129 if(op != 4) 130 { 131 scanf("%I64d", &c); 132 T.update(1, n, 1, l, r, op, c); 133 } 134 else 135 { 136 max_ans = -INF; 137 min_ans = INF; 138 T.query(1, n, 1, l, r); 139 printf("%I64d %I64d\n", min_ans, max_ans); 140 } 141 } 142 return 0; 143 } 144 145 int main() 146 { 147 int T; 148 149 scanf("%d", &T); 150 151 while(T --) 152 work(); 153 154 return 0; 155 }
时间: 2024-10-25 02:34:24