codeforces 356 A. Knight Tournament (线段树lazy标记,倒序处理)

[题目链接](http://codeforces.com/problemset/problem/356/A) 题意:现在有N个骑士进行M轮PK...现在告诉这M轮是谁站在台上...其将l~r所存在的骑士都打败..而若一个骑士被打败..就出局了..也就是不存在了...请输出每个骑士是被哪个骑士打败的(最后的胜利者输出0)...保证有解..

思路:由于先前被打败的骑士直接就退场了。。。所以如果不做判断。。那么之后胜利的骑士会干扰之前的结果。。。

可以在pushdown的时候加判断。。。

不过我觉得比较好的做法是。。。倒序处理。。。。

倒序处理。。。后处理的直接覆盖先处理的结果。。。因为后处理的在之前。。优先级更高。。。被覆盖掉的骑士其实应该是退场的。。。

倒序处理就避免了判断的问题。。。完美。。。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :Wed 07 Sep 2016 02:13:55 AM CST
 4File Name :code/cf/problem/356A.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=3E5+7;
34int n,m;
35struct node
36{
37    int l,r,x;
38}q[N];
39int lazy[N<<2];
40void PushDown( int rt)
41{
42    if (lazy[rt])
43	lazy[rt<<1]=lazy[rt<<1|1]=lazy[rt];
44    lazy[rt] = 0;
45}
46void update(int L,int R,int sc,int l,int r,int rt)
47{
48    if (L<=l&&r<=R)
49    {
50	lazy[rt] = sc;
51	return;
52    }
53    PushDown(rt);
54    int m = (l+r)>>1;
55    if (L<=m) update(L,R,sc,lson);
56    if (R>=m+1) update(L,R,sc,rson);
57
58}
59int query(int p,int l,int r,int rt)
60{
61    if (l==r) return lazy[rt];
62    PushDown(rt);
63    int m = (l+r)>>1;
64    if (p<=m) query(p,lson);
65    else query(p,rson);
66}
67
68int main()
69{
70	#ifndef  ONLINE_JUDGE 
71	freopen("code/in.txt","r",stdin);
72  #endif
73	ios::sync_with_stdio(false);
74	cin>>n>>m;
75	for ( int i = 1 ; i <= m ; i++) cin>>q[i].l>>q[i].r>>q[i].x;
76	ms(lazy,0);
77
78	for ( int i = m ; i >= 1 ; i--)
79	{
80	    if (q[i].x>q[i].l) update(q[i].l,q[i].x-1,q[i].x,1,n,1);
81	    if (q[i].x<q[i].r) update(q[i].x+1,q[i].r,q[i].x,1,n,1);
82	}
83	for ( int i = 1 ; i <= n ; i++) cout<<query(i,1,n,1)<<" ";
84
85  #ifndef ONLINE_JUDGE  
86  fclose(stdin);
87  #endif
88    return 0;
89}