QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#58473 | #1173. Knowledge Is... | vme50 | WA | 3ms | 7868kb | C++14 | 1.1kb | 2022-10-26 16:45:40 | 2022-10-26 16:46:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define N 300005
int n,m,ps[N],ans[N];
struct Range
{
int l,r,id;
bool operator < (Range t) const
{return l==t.l?r<t.r:l<t.l;}
}a[N];
struct Node
{
int x,id;
bool operator < (Node t) const
{return x==t.x?id<t.id:x<t.x;}
};set<Node> z1,z2;
int main()
{
scanf("%d %d",&n,&m);
for(int i=1;i<=n;++i)
scanf("%d %d",&a[i].l,&a[i].r),a[i].id=i;
for(int i=1,l,r,id;i<=n;++i)
{
l=a[i].l;r=a[i].r;id=a[i].id;
set<Node>::iterator it;
if(!z1.empty())
{
it=z1.lower_bound((Node) {l,0});
if(it!=z1.begin())
{
--it;ps[id]=it->id;z1.erase(it);
z2.insert((Node) {r,id});continue;
}
}
if(!z2.empty())
{
it=z2.begin();
if(r>it->x)
{
ps[id]=ps[it->id];ps[it->id]=0;
z1.insert(*it);z2.erase(it);
z2.insert((Node) {r,id});continue;
}
}z1.insert((Node) {r,id});
}
for(int i=1;i<=n;++i) if(ps[i])
ans[i]=ans[ps[i]]=++ans[0];
for(int i=1;i<=n;++i) if(!ans[i]) ans[i]=++ans[0];
for(int i=1;i<=n;++i)
printf("%d ",ans[i]<=m?ans[i]:0);return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 5828kb
input:
7 5 9 10 7 9 3 4 9 10 2 6 8 9 5 8
output:
3 4 1 1 2 2 5
result:
ok answer = 7
Test #2:
score: 0
Accepted
time: 3ms
memory: 7868kb
input:
2 2 1 2 3 4
output:
1 1
result:
ok answer = 2
Test #3:
score: 0
Accepted
time: 0ms
memory: 5816kb
input:
2 1 1 2 2 3
output:
1 0
result:
ok answer = 1
Test #4:
score: 0
Accepted
time: 2ms
memory: 5868kb
input:
1 1 4 26
output:
1
result:
ok answer = 1
Test #5:
score: -100
Wrong Answer
time: 3ms
memory: 5788kb
input:
500 258 1 3 3 5 2 4 3 5 4 5 4 5 1 4 1 2 3 5 2 5 2 5 4 5 4 5 4 5 2 3 1 4 1 4 1 4 4 5 4 5 2 3 4 5 3 5 3 5 1 5 1 4 2 5 1 5 3 5 3 4 4 5 2 3 3 5 3 5 4 5 2 3 1 5 1 5 2 3 2 3 3 4 3 5 3 4 1 3 1 2 1 5 4 5 2 3 2 4 1 3 4 5 4 5 4 5 1 3 3 5 4 5 3 5 1 5 1 2 1 2 3 5 3 5 4 5 3 4 3 5 2 3 2 5 2 4 2 5 3 5 2 3 1 5 4 5 ...
output:
1 114 115 116 1 117 118 2 2 119 120 121 122 123 3 124 125 126 3 127 4 4 128 129 130 131 132 133 134 135 136 5 137 138 5 18 139 140 14 9 141 142 143 6 10 144 6 8 145 7 7 8 9 11 10 11 146 147 13 12 12 13 14 148 149 17 150 151 152 153 15 154 15 155 156 16 16 157 158 17 18 159 21 20 19 19 20 160 161 21 ...
result:
wrong answer Interval intersecting