codeforces 356 A. Knight Tournament (线段树lazy标记,倒序处理)
[题目链接](http://codeforces.com/problemset/problem/356/A) 题意:现在有N个骑士进行M轮PK...现在告诉这M轮是谁站在台上...其将l~r所存在的骑士都打败..而若一个骑士被打败..就出局了..也就是不存在了...请输出每个骑士是被哪个骑士打败的(最后的胜利者输出0)...保证有解..
思路:由于先前被打败的骑士直接就退场了。。。所以如果不做判断。。那么之后胜利的骑士会干扰之前的结果。。。
可以在pushdown的时候加判断。。。
不过我觉得比较好的做法是。。。倒序处理。。。。
倒序处理。。。后处理的直接覆盖先处理的结果。。。因为后处理的在之前。。优先级更高。。。被覆盖掉的骑士其实应该是退场的。。。
倒序处理就避免了判断的问题。。。完美。。。
/* ***********************************************
Author :111qqz
Created Time :Wed 07 Sep 2016 02:13:55 AM CST
File Name :code/cf/problem/356A.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6const int N=3E5+7;
7int n,m;
8struct node
9{
10 int l,r,x;
11}q[N];
12int lazy[N<<2];
13void PushDown( int rt)
14{
15 if (lazy[rt])
16 lazy[rt<<1]=lazy[rt<<1|1]=lazy[rt];
17 lazy[rt] = 0;
18}
19void update(int L,int R,int sc,int l,int r,int rt)
20{
21 if (L<=l&&r<=R)
22 {
23 lazy[rt] = sc;
24 return;
25 }
26 PushDown(rt);
27 int m = (l+r)>>1;
28 if (L<=m) update(L,R,sc,lson);
29 if (R>=m+1) update(L,R,sc,rson);
1}
2int query(int p,int l,int r,int rt)
3{
4 if (l==r) return lazy[rt];
5 PushDown(rt);
6 int m = (l+r)>>1;
7 if (p<=m) query(p,lson);
8 else query(p,rson);
9}
1int main()
2{
3 #ifndef ONLINE_JUDGE
4 freopen("code/in.txt","r",stdin);
5 #endif
6 ios::sync_with_stdio(false);
7 cin>>n>>m;
8 for ( int i = 1 ; i <= m ; i++) cin>>q[i].l>>q[i].r>>q[i].x;
9 ms(lazy,0);
1 for ( int i = m ; i >= 1 ; i--)
2 {
3 if (q[i].x>q[i].l) update(q[i].l,q[i].x-1,q[i].x,1,n,1);
4 if (q[i].x<q[i].r) update(q[i].x+1,q[i].r,q[i].x,1,n,1);
5 }
6 for ( int i = 1 ; i <= n ; i++) cout<<query(i,1,n,1)<<" ";
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}