【bzoj4143】[AMPPZ2014]The Lawyer

来源:互联网 发布:淘宝图片数据包 编辑:程序博客网 时间:2024/06/05 20:50

这是noip–难度吧。。。。。
把第i天的所有左端点排序,然后upper_bound右端点就行了。
唔。。。。。。。。。。

#include <bits/stdc++.h>using namespace std;#define rep(i,a,b) for(int i=a;i<=b;i++)#define per(i,a,b) for(int i=a;i>=b;i--)#define pii pair<int , int>#define mp make_pairinline int rd() {    char c = getchar();    while (!isdigit(c)) c = getchar() ; int x = c - '0';    while (isdigit(c = getchar())) x = x * 10 + c - '0';    return x;}const int maxn = 500005;set<pii> S[21];int a[maxn] , b[maxn] , d[maxn] , vis[21] , m , n;pii ans[21];void input() {    n = rd() , m = rd();    rep(i , 1 , n) {        a[i] = rd() , b[i] = rd() , d[i] = rd();        S[d[i]].insert(mp(a[i] , i));    }}void solve() {    rep(i , 1 , n) if (!vis[d[i]]) {        set<pii>::iterator iter = S[d[i]].upper_bound(mp(b[i] , n + 1));        if (iter == S[d[i]].end()) continue;        ans[d[i]].first = iter -> second , ans[d[i]].second = i;        vis[d[i]] = 1;    }    rep(i , 1 , m) if (vis[i]) printf("TAK %d %d\n" , ans[i].first , ans[i].second);    else puts("NIE");}int main() {    #ifndef ONLINE_JUDGE//      freopen("data.txt" , "r" , stdin);    #endif    input();    solve();    return 0;}
0 0
原创粉丝点击