1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| #include <bits/stdc++.h> using namespace std; typedef long long ll; const int NO_OPT = INT_MAX; struct segtree{ int size = 1; vector<int>upv,lowv; void init(int n){ while(size < n)size *= 2; upv.assign(size*2,NO_OPT); lowv.assign(size*2,NO_OPT); } inline int ls(int x){ return (x<<1)|1; } inline int rs(int x){ return (x<<1)+2; } void pushdown(int x,int lx,int rx){ if(rx - lx == 1)return; if(upv[x] != NO_OPT){ upv[ls(x)] = min(upv[x],upv[ls(x)]); upv[rs(x)] = min(upv[x],upv[rs(x)]); if(lowv[ls(x)] != NO_OPT and lowv[ls(x)] > upv[x])lowv[ls(x)] = upv[x]; if(lowv[rs(x)] != NO_OPT and lowv[rs(x)] > upv[x])lowv[rs(x)] = upv[x]; upv[x] = NO_OPT; } if(lowv[x] != NO_OPT){ if(lowv[ls(x)] != NO_OPT)lowv[ls(x)] = max(lowv[ls(x)],lowv[x]); else lowv[ls(x)] = lowv[x]; if(lowv[rs(x)] != NO_OPT)lowv[rs(x)] = max(lowv[rs(x)],lowv[x]); else lowv[rs(x)] = lowv[x]; if(upv[ls(x)] != NO_OPT and upv[ls(x)] < lowv[x])upv[ls(x)] = lowv[x]; if(upv[rs(x)] != NO_OPT and upv[rs(x)] < lowv[x])upv[rs(x)] = lowv[x]; lowv[x] = NO_OPT; } } void up(int l,int r,int v,int x,int lx,int rx){ if(l >= rx or lx >= r)return; pushdown(x,lx,rx); if(l <= lx and rx <= r){ upv[x] = min(upv[x],v); if(lowv[x] != NO_OPT and lowv[x] > v)lowv[x] = v; return; } int m = (lx+rx)/2; up(l,r,v,ls(x),lx,m); up(l,r,v,rs(x),m,rx); return; } void up(int l,int r,int v){ up(l,r,v,0,0,size); } void low(int l,int r,int v,int x,int lx,int rx){ if(l >= rx or lx >= r)return; pushdown(x,lx,rx); if(l <= lx and rx <= r){ if(lowv[x] == NO_OPT or lowv[x] < v)lowv[x] = v; return; } int m = (lx+rx)/2; low(l,r,v,ls(x),lx,m); low(l,r,v,rs(x),m,rx); return; } void low(int l,int r,int v){ low(l,r,v,0,0,size); } int get(int idx,int x,int lx,int rx){ if(idx >= rx)return NO_OPT; pushdown(x,lx,rx); if(rx - lx == 1)return lowv[x]; int m = (lx+rx)/2; if(idx < m)return get(idx,ls(x),lx,m); else return get(idx,rs(x),m,rx); } int get(int idx){ return get(idx,0,0,size); } }; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n,m; cin >> n >> m; segtree seg; seg.init(n+1); while(m--){ int opt,l,r,v; r++; cin >> opt >> l >> r >> v; r++; if(opt == 1)seg.low(l,r,v); else seg.up(l,r,v); } for(int i = 0;i < n;i++){ int ans = seg.get(i); cout << (ans == NO_OPT?0:ans) << '\n'; } return 0; }
|