QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#282316 | #1173. Knowledge Is... | AbioAg | WA | 2ms | 13964kb | C++14 | 2.4kb | 2023-12-11 18:47:32 | 2023-12-11 18:47:32 |
Judging History
answer
// ubsan: undefined
// accoders
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n,m;
struct Seg {
int l, r,id;
friend bool operator<(const Seg &a, const Seg &b) { return a.l < b.l; }
} a[N];
inline int find(int x) {
int l = x, r = n, ans = n + 1;
while (l <= r) {
int mid = l + r >> 1;
if (a[mid].l > a[x].r)
r = mid - 1, ans = mid;
else
l = mid + 1;
}
return ans;
}
int Len[N];
inline bool cmp(int x, int y) { return Len[x] < Len[y]; }
int b[N], vis[N];
int ans, pos;
struct node{
int a,b;
}Ans[N];
inline int check(int x) {
int ans = 0;
pos = x;
memset(vis, 0, sizeof vis);
for (int i = 1; i <= n; i++) {
if (vis[i])
continue;
int j = max(Len[b[i]], pos);
while (vis[j]) j++;
if (j > n)
break;
ans++;
vis[i]=vis[j]=ans;
//cout<<i<<" "<<j<<" "<<ans<<endl;
pos = j;
}
return ans;
}
inline int solve() {
int l = 1, r = n, ans = 0,pos=0;
while (r - l >= 5) {
int mid = (r - l) / 3;
int lmid = l + mid;
int rmid = r - mid;
if (check(lmid) > check(rmid))
r = rmid - 1;
else
l = lmid + 1;
}
for (int i = l; i <= r; i++){
int val=check(i);
if(val>ans)ans=val,pos=i;
}
return pos;
}
int o[N],p[N];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i].l >> a[i].r,a[i].id=i;
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) Len[i] = find(i), cout;
for (int i = 1; i <= n; i++) b[i] = i;
sort(b + 1, b + 1 + n, cmp);
for(int i=1;i<=n;i++){
p[b[i]]=i;
}
int pos=solve();
int val=check(pos);
if(val<m){
for(int i=1;i<=n;i++){
if(vis[i]==0){
if(val<m)val++;
else continue;
vis[i]=val;
}
}
}else{
for(int i=1;i<=n;i++){
if(vis[i]>m)vis[i]=0;
}
}
for(int i=1;i<=n;i++){
o[a[i].id]=vis[p[i]];
}
for(int i=1;i<=n;i++)cout<<o[i]<<" ";
}
/*
对于一张有特殊性质的图求最大匹配
左端点排序
每个点都会有一段后缀可以匹配
把每个点可以最后匹配的后缀长度从大到小排一下,
挨个分配应该就好了
不然某个节点可能失配
好像还得三分一下能匹配点的范围,
5
9 13
3 7
9 12
7 10
3 7
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 13828kb
input:
7 5 9 10 7 9 3 4 9 10 2 6 8 9 5 8
output:
3 1 1 4 2 2 3
result:
ok answer = 7
Test #2:
score: 0
Accepted
time: 2ms
memory: 11840kb
input:
2 2 1 2 3 4
output:
1 1
result:
ok answer = 2
Test #3:
score: 0
Accepted
time: 0ms
memory: 13872kb
input:
2 1 1 2 2 3
output:
1 0
result:
ok answer = 1
Test #4:
score: 0
Accepted
time: 0ms
memory: 13936kb
input:
1 1 4 26
output:
1
result:
ok answer = 1
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 13964kb
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:
100 112 107 54 0 0 0 32 56 114 115 137 0 0 75 0 0 0 0 0 40 0 58 59 0 0 100 1 71 63 0 78 65 68 142 63 0 0 64 65 70 61 165 115 29 0 139 66 89 111 151 152 252 47 167 212 171 0 28 10 172 185 0 176 37 60 81 79 78 178 71 25 236 0 0 53 246 46 24 244 243 23 2 7 33 242 32 72 74 238 84 87 29 249 30 31 76 0 33...
result:
wrong answer Interval intersecting