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 }
标签:后缀,max,最大值,long,int,fory,107,define 来源: https://www.cnblogs.com/-ytz/p/15965458.html