QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#288302 | #1173. Knowledge Is... | Toxic | WA | 1ms | 9912kb | C++14 | 1.5kb | 2023-12-22 14:38:59 | 2023-12-22 14:38:59 |
Judging History
answer
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int N=3e5+5;
struct node
{
int x,y;
friend bool operator < (node p,node q)
{
return p.x<q.x;
}
}a[N];
struct edge
{
int id,val;
friend bool operator < (edge x,edge y)
{
return x.val>y.val;
}
};
int n,m,ak[N],bk[N],pos[N],outp[N];
priority_queue<edge> p,q;
int read()
{
int res,f=1;
char ch;
while((ch=getchar())<'0'||ch>'9')
if(ch=='-')
f=-1;
res=ch^48;
while((ch=getchar())>='0'&&ch<='9')
res=(res<<1)+(res<<3)+(ch^48);
return res*f;
}
int main()
{
int i,x,ans=0,cnt=0;
n=read();m=read();
for(i=1;i<=n;i++)
{
a[i].x=read();a[i].y=read();
}
sort(a+1,a+n+1);
for(i=1;i<=n;i++)
{
if(q.size()&&q.top().val<=a[i].x)
{
p.push((edge){i,a[i].y});
ans++;ak[ans]=q.top().id;bk[ans]=i;
pos[q.top().id]=pos[i]=ans;
q.pop();
}
else
{
if(p.size()&&p.top().val<=a[i].y)
{
q.push(p.top());
bk[pos[i]=pos[p.top().id]]=i;
pos[p.top().id]=0;
p.pop();p.push((edge){i,a[i].y});
}
else
q.push((edge){i,a[i].y});
}
}
if(m+ans>=n)
{
x=m+ans-n;
for(i=1;i<=x;i++)
{
outp[ak[i]]=++cnt;
outp[bk[i]]=++cnt;
}
for(i=x+1;i<=ans;i++)
outp[ak[i]]=outp[bk[i]]=++cnt;
for(i=1;i<=n;i++)
if(!outp[i])
outp[i]=++cnt;
}
else
{
for(i=1;i<=ans;i++)
outp[ak[i]]=outp[bk[i]]=++cnt;
for(i=1;i<=n&&cnt<=m-1;i++)
if(!outp[i])
outp[i]=++cnt;
}
for(i=1;i<=n;i++)
printf("%d ",outp[i]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7872kb
input:
7 5 9 10 7 9 3 4 9 10 2 6 8 9 5 8
output:
3 1 4 5 2 4 3
result:
ok answer = 7
Test #2:
score: 0
Accepted
time: 1ms
memory: 7944kb
input:
2 2 1 2 3 4
output:
1 2
result:
ok answer = 2
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 9912kb
input:
2 1 1 2 2 3
output:
1 1
result:
wrong answer Interval intersecting