1. 程式人生 > 其它 >107序列操作(字尾最大值)

107序列操作(字尾最大值)

 1 /**\
 2 記錄操作1的最後一次出現的地方,(前面操作都沒有用),
 3 然後對比他的下一次操作二的最大值(這裡處理一個字尾最大值即可)
 4 \**/
 5 #include <bits/stdc++.h>
 6 using namespace std;
 7 #define fi first
 8 #define se second
 9 #define go continue
10 #define int long long
11 #define PII pair<int, int>
12 #define sf(x) scanf("%lld",&x)
13
#define ytz int _; sf(_); while(_--) 14 #define fory(i,a,b) for(int i = a; i <= b; ++i) 15 #define forl(i,a,b) for(int i = a; i >= b; --i) 16 #define debug(a) cout << #a << " = " << a <<endl; 17 const int N = 1e6 + 9; 18 int n, q; 19 int last[N], val[N], s[N], a[N]; 20 signed main()
21 { 22 int cmp = -1e18; 23 sf(n), sf(q); 24 fory(i, 1, n) sf(a[i]), val[i] = a[i]; 25 fory(i, 1, q) 26 { 27 int op; 28 sf(op); 29 if(op == 1) 30 { 31 int x, y; 32 sf(x), sf(y); 33 last[x] = i; 34 val[x] = y;
35 } 36 else 37 { 38 sf(s[i]); 39 cmp = max(cmp,s[i]); 40 } 41 } 42 for(int i = q; i >= 1; --i) s[i] = max(s[i], s[i + 1]); 43 44 fory(i, 1, n) 45 { 46 if(last[i] == 0) 47 { 48 a[i] = max(a[i], cmp); 49 } 50 else 51 { 52 a[i] = max(val[i], s[last[i] + 1]); 53 } 54 } 55 fory(i, 1, n) printf("%lld ", a[i]); 56 return 0; 57 }