AcWing 3248. 公共钥匙盒csp11(2)
原题链接
简单
作者:
YAX_AC
,
2024-11-21 15:30:44
,
所有人可见
,
阅读 5
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 10010;
int n,k;
int q[N];
struct OP
{
int t,type,id;
}op[N*2];
int cmp(OP a,OP b)
{
if(a.t!=b.t) return a.t<b.t;
if(a.type !=b.type) return a.type>b.type;//还钥匙排在后面,type:1取钥匙0还钥匙
return a.id<b.id;
}
int main()
{
cin>>n>>k;
for(int i = 1; i<=n; i++) q[i] = i;
int m = 0;
while(k--)
{
int id,st,len;
cin>>id>>st>>len;
op[m++] = {st,0,id};//type:1取钥匙0还钥匙
op[m++] = {st+len,1,id};
}
sort(op,op+m,cmp);
for(int i = 0; i<m; i++)
{
int id = op[i].id;
if(op[i].type == 0)
{
for(int j = 1; j<=n;j++)
{
if(q[j] == id)//取钥匙
{
q[j] = 0;
break;
}
}
}
else
{
for(int j = 1; j<=n; j++)
{
if(q[j] == 0)//还钥匙
{
q[j] = id;
break;
}
}
}
}
for(int i = 1; i<=n; i++) cout<<q[i]<<' ';
return 0;
}