zoukankan      html  css  js  c++  java
  • A. Knight Tournament SET的应用

    A. Knight Tournament
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.

    As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tournament (it was a weekend, after all). Now you are really curious about the results of the tournament. This time the tournament in Berland went as follows:

    • There are n knights participating in the tournament. Each knight was assigned his unique number — an integer from 1 to n.
    • The tournament consisted of m fights, in the i-th fight the knights that were still in the game with numbers at least li and at most rihave fought for the right to continue taking part in the tournament.
    • After the i-th fight among all participants of the fight only one knight won — the knight number xi, he continued participating in the tournament. Other knights left the tournament.
    • The winner of the last (the m-th) fight (the knight number xm) became the winner of the tournament.

    You fished out all the information about the fights from your friends. Now for each knight you want to know the name of the knight he was conquered by. We think that the knight number b was conquered by the knight number a, if there was a fight with both of these knights present and the winner was the knight number a.

    Write the code that calculates for each knight, the name of the knight that beat him.

    Input

    The first line contains two integers nm (2 ≤ n ≤ 3·105; 1 ≤ m ≤ 3·105) — the number of knights and the number of fights. Each of the following m lines contains three integers li, ri, xi (1 ≤ li < ri ≤ nli ≤ xi ≤ ri) — the description of the i-th fight.

    It is guaranteed that the input is correct and matches the problem statement. It is guaranteed that at least two knights took part in each battle.

    Output

    Print n integers. If the i-th knight lost, then the i-th number should equal the number of the knight that beat the knight number i. If the i-th knight is the winner, then the i-th number must equal 0.

    Sample test(s)
    input
    4 3
    1 2 1
    1 3 3
    1 4 4
    output
    3 1 4 0 
    input
    8 4
    3 5 4
    3 7 6
    2 8 8
    1 8 1
    output
    0 8 4 6 4 8 6 1 
    Note

    Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won.

    /*
     * Author: 
     * Created Time:  2013/11/7 20:07:35
     * File Name: D.cpp
     * solve: D.cpp
     */
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    #include<string>
    #include<map>
    #include<stack>
    #include<set>
    #include<iostream>
    #include<vector>
    #include<queue>
    //ios_base::sync_with_stdio(false);
    //#pragma comment(linker, "/STACK:1024000000,1024000000")
    
    using namespace std;
    #define sz(v) ((int)(v).size())
    #define rep(i, a, b) for (int i = (a); i < (b); ++i)
    #define repf(i, a, b) for (int i = (a); i <= (b); ++i)
    #define repd(i, a, b) for (int i = (a); i >= (b); --i)
    #define clr(x) memset(x,0,sizeof(x))
    #define clrs( x , y ) memset(x,y,sizeof(x))
    #define out(x) printf(#x" %d
    ", x)
    #define sqr(x) ((x) * (x))
    typedef long long LL;
    
    const int INF = 1000000000;
    const double eps = 1e-8;
    const int maxn = 300010;
    
    int sgn(const double &x) {  return (x > eps) - (x < -eps); }
    
    set<int> Left;
    vector<int> temp;
    int p[maxn];
    int main() 
    {
        //freopen("in.txt","r",stdin);
        int n,m;
        while(scanf("%d%d",&n,&m)==2)
        {
            Left.clear();
            repf(i,1,n)
                Left.insert(i);
            clr(p);
            repf(i,1,m)
            {
                int a,b,c;
                scanf("%d%d%d",&a,&b,&c);
                set<int> :: iterator it  = Left.lower_bound(a);
    
                for(;*it<=b && it != Left.end();it++)
                {
                    if(*it != c)
                    {
                        p[*it] = c;
                        temp.push_back(*it);
                    }
                }
                rep(j,0,temp.size())
                    Left.erase(temp[j]);
                temp.clear();
            }
    
            repf(i,1,n)
                if(p[i] == i)
                    p[i] = 0;
            cout<<p[1];
            repf(i,2,n)
                printf(" %d",p[i]);
            cout<<endl;
        }
        return 0;
    }
  • 相关阅读:
    多线程之缓存一致性协议
    Redis基础入门-linux安装
    Linux 上传文件rz 命令提示 -bash: rz: command not found 问题解决办法
    面试题之十亿条记录,怎么获取出现最多的前十个
    设计模式之工厂设计模式
    设计模式之单例设计模式
    数据结构之红黑树
    Eclipse使用Maven创建web3.0项目
    Eclipse创建Maven工程报错
    Oracle中的commit详解
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3413162.html
Copyright © 2011-2022 走看看