Codeforces Round #207 (Div. 2)C
读错题意了。。线段树延迟标记
白刷这么多线段树
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 using namespace std; 8 #define N 300010 9 int s[N<<2],la[N<<2]; 10 struct node 11 { 12 int l,r,d; 13 }q[N]; 14 void update(int a,int b,int p,int l,int r,int w) 15 { 16 if(a<=l&&b>=r) 17 { 18 s[w] = p; 19 return ; 20 } 21 if(s[w]) 22 { 23 s[w<<1] = s[w<<1|1] = s[w]; 24 s[w] = 0; 25 } 26 int m = (l+r)>>1; 27 if(a<=m) 28 update(a,b,p,l,m,w<<1); 29 if(b>m) 30 update(a,b,p,m+1,r,w<<1|1); 31 } 32 int query(int k,int l,int r,int w) 33 { 34 if(l==r) 35 return s[w]; 36 if(s[w]) 37 s[w<<1] = s[w<<1|1] = s[w]; 38 int m = (l+r)>>1; 39 if(k<=m) 40 return query(k,l,m,w<<1); 41 else 42 return query(k,m+1,r,w<<1|1); 43 } 44 int main() 45 { 46 int i,n,m; 47 int a,b,c; 48 scanf("%d%d",&n,&m); 49 for(i = 1; i <= m ;i++) 50 { 51 scanf("%d%d%d",&q[i].l,&q[i].r,&q[i].d); 52 } 53 for(i = m ; i >= 1; i--) 54 { 55 a = q[i].l;b = q[i].r; c = q[i].d; 56 if(a!=c) 57 update(a,c-1,c,1,n,1); 58 if(b!=c) 59 update(c+1,b,c,1,n,1); 60 } 61 for(i = 1; i < n ; i++) 62 printf("%d ",query(i,1,n,1)); 63 printf("%d\n",query(n,1,n,1)); 64 return 0; 65 }