BZOJ 4143: [AMPPZ2014]The Lawyer( sort )

水题...

序搞出每天的会议有哪些, 然后再按照会议的开始时间和结束时间排序, 最晚开始的和最早结束的会议不是同一场而且最晚开始的时间>最早结束的会议就有可能方案

----------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
  
#define rep(i, n) for(int i = 0; i < n; i++)
#define clr(x, c) memset(x, c, sizeof(x))
  
using namespace std;
 
const int maxn = 500009, maxm = 29;
 
int L[maxn], R[maxn], n, m, _L[maxm], _R[maxn];// [_L[i], _R[i])
 
struct mtg {
int l, r, day, pos;
inline void read(int p) {
scanf("%d%d%d", &l, &r, &day);
pos = ++p;
}
bool operator < (const mtg&t) const {
return day < t.day;
}
} M[maxn];
 
bool cmpL(const int i, const int j) {
return M[i].l > M[j].l;
}
 
bool cmpR(const int i, const int j) {
return M[i].r < M[j].r;
}
 
int main() {
freopen("test.in", "r", stdin);
cin >> n >> m;
rep(i, n) M[i].read(i);
sort(M, M + n);
clr(_L, -1);
rep(i, n) {
mtg*t = M + i;
if(_L[t->day] == -1) _L[t->day] = i;
_R[t->day] = i + 1;
L[i] = R[i] = i;
}
for(int i = 1; i <= m; ++i ) {
sort(L + _L[i], L + _R[i], cmpL);
sort(R + _L[i], R + _R[i], cmpR);
if(R[_L[i]] != L[_L[i]] && M[R[_L[i]]].r < M[L[_L[i]]].l)
   printf("TAK %d %d\n", M[L[_L[i]]].pos, M[R[_L[i]]].pos);
else
   puts("NIE");
}
return 0;
}

  

---------------------------------------------------------------------------- 

4143: [AMPPZ2014]The Lawyer

Time Limit: 10 Sec  Memory Limit: 256 MBSec  Special Judge
Submit: 163  Solved: 123
[Submit][Status][Discuss]

Description

Byteasar要制订m天的会议计划,一共有n场会议,第i场会议开始于第d[i]天的第a[i]秒,结束于第d[i]天的第b[i]秒。
对于每一天,请找出这一天的两场会议i,j,使得它们不冲突,即不存在一个数k同时满足a[i]<=k<=b[i]以及a[j]<=k<=b[j]。

Input

第一行包含两个正整数n,m(2<=n<=500000,1<=m<=20),表示会议的场数和天数。
接下来n行,每行包含三个正整数a[i],b[i],d[i](1<=a[i]<b[i]<=80000000,1<=d[i]<=m),描述一场会议。

Output

输出m行。第i行输出第i天的答案,如果无解,输出NIE,否则输出TAK,然后输出这一天参加的两场会议的编号,
如有多组解,输出任意一组。

Sample Input

6 3
3 5 1
2 4 2
1 8 1
6 7 3
3 5 2
7 12 1

Sample Output

TAK 1 6
NIE
NIE

HINT

Source

 

posted @ 2015-07-19 12:59  JSZX11556  阅读(207)  评论(4编辑  收藏  举报