ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#205089 | #3646. 调分 | Zxc200611 | 100 | 766ms | 8024kb | C++11 | 1.8kb | 2024-06-23 10:04:43 | 2024-06-23 13:02:34 |
answer
/*
有一些区间 [l,r]。
可以决定一个数组 v[1...n]。
一个 i 的贡献为 [v[i]>=l[i]] + [v[i]>=r[i]]。
但是有 m 条限制:v[i]>=a[j] 的数量小于等于 c[j]。
可以直接求出最后的 v 的集合。
然后就是一个最大权匹配。网络流是不是 60pts?
考虑贪心。
2 不劣于 1+1,于是尽量贡献 2。
按 l 从右到左贪心,如果存在可用的 v>=r,就取最小的一个这样的 v。
然后按 l 从右往左贪心,如果存在可用的 v>=l,就取最小的一个这样的 v。
感觉很对。
*/
#include<bits/stdc++.h>
using namespace std;
struct Interval
{
int l,r;
};
struct Constraint
{
int x,c; // v>=x <=c 个
};
int n,m;
Interval itv[110000];
Constraint cst[110000];
int v[110000];
multiset<int> val;
bool usd[110000];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(int i=1,rb;i<=n;i++)
{
cin>>rb>>itv[i].l>>itv[i].r;
itv[i].r++;
}
for(int i=1;i<=m;i++)
cin>>cst[i].x>>cst[i].c;
cst[++m]=(Constraint){1,n};
cst[++m]=(Constraint){(int)1.1e9,0};
sort(cst+1,cst+m+1,[&](Constraint a,Constraint b){return a.x!=b.x?a.x<b.x:a.c<b.c;});
for(int i=1,c=0;i<=m;i++)
{
while(n-c>cst[i].c)
v[++c]=cst[i].x-1;
}
// cout<<"v : ";
for(int i=1;i<=n;i++)
{
val.insert(v[i]);
// cout<<v[i]<<" ";
}
// cout<<endl;
sort(itv+1,itv+n+1,[&](Interval a,Interval b){return a.l!=b.l?a.l<b.l:a.r<b.r;});
int ans=0;
for(int i=n;i>=1;i--)
{
set<int>::iterator it=val.lower_bound(itv[i].r);
if(it==val.end())
continue;
ans+=2,usd[i]=1;
val.erase(it);
}
for(int i=n;i>=1;i--)
{
if(usd[i])
continue;
set<int>::iterator it=val.lower_bound(itv[i].l);
if(it==val.end())
continue;
ans+=1;
val.erase(it);
}
cout<<ans-n<<endl;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 1288kb
input:
15 20 845403345 390609697 980384063 186743724 104990508 963496192 263966340 55953443 787815158 16843...
output:
11
result:
ok single line: '11'
Test #2:
score: 5
Accepted
time: 1ms
memory: 1284kb
input:
15 20 710914207 97234432 738264088 42243279 26728414 621680880 162908406 61586483 185903807 39356031...
output:
8
result:
ok single line: '8'
Test #3:
score: 5
Accepted
time: 0ms
memory: 1292kb
input:
15 20 700412807 672433278 902231896 862757701 298427492 916841742 374302689 72499348 943626637 99857...
output:
11
result:
ok single line: '11'
Test #4:
score: 5
Accepted
time: 0ms
memory: 1288kb
input:
15 20 293265775 187997853 409823298 5464414 1343941 440699330 960988144 265922201 963233253 94420468...
output:
8
result:
ok single line: '8'
Test #5:
score: 5
Accepted
time: 0ms
memory: 1292kb
input:
15 20 461991159 231524604 559439691 5940502 5556321 345367655 903635605 249803497 922750941 22099036...
output:
13
result:
ok single line: '13'
Test #6:
score: 5
Accepted
time: 0ms
memory: 1300kb
input:
200 20 526801273 451267596 669703900 117452796 52230219 581138048 986865963 924965003 996753167 3894...
output:
180
result:
ok single line: '180'
Test #7:
score: 5
Accepted
time: 0ms
memory: 1300kb
input:
200 20 697923362 12116150 916555730 164808860 137308876 177851204 848793719 656245263 936591222 2852...
output:
180
result:
ok single line: '180'
Test #8:
score: 5
Accepted
time: 0ms
memory: 1300kb
input:
200 20 161787269 2568546 247988992 585198193 135846344 900057943 616735835 226367000 704675057 61717...
output:
171
result:
ok single line: '171'
Test #9:
score: 5
Accepted
time: 1ms
memory: 1300kb
input:
200 200 657239333 380683702 843825391 528714786 13173880 984499662 475669898 456612694 833254921 494...
output:
140
result:
ok single line: '140'
Test #10:
score: 5
Accepted
time: 0ms
memory: 1300kb
input:
200 200 909293380 560881903 968880531 971017373 170045342 974022370 65272918 29942253 432191198 6343...
output:
119
result:
ok single line: '119'
Test #11:
score: 5
Accepted
time: 0ms
memory: 1300kb
input:
200 200 939041723 556876806 957997424 697350341 455737278 746435146 445674199 362307255 658553145 14...
output:
174
result:
ok single line: '174'
Test #12:
score: 5
Accepted
time: 0ms
memory: 1300kb
input:
200 200 797241149 541897259 988623827 286876319 100634468 629979548 706691378 249253522 768355649 53...
output:
158
result:
ok single line: '158'
Test #13:
score: 5
Accepted
time: 82ms
memory: 8020kb
input:
100000 100000 113998910 1 427605660 605845930 1 705422321 151459006 1 883297089 387565910 1 76233795...
output:
80577
result:
ok single line: '80577'
Test #14:
score: 5
Accepted
time: 83ms
memory: 8024kb
input:
100000 100000 254892569 1 447083628 483853444 1 731264529 334949412 1 349769789 990131147 1 99641344...
output:
91658
result:
ok single line: '91658'
Test #15:
score: 5
Accepted
time: 105ms
memory: 8020kb
input:
100000 100000 681865203 340942769 927067423 862581764 707438427 956358388 116698514 8707590 75316147...
output:
91886
result:
ok single line: '91886'
Test #16:
score: 5
Accepted
time: 95ms
memory: 8024kb
input:
100000 100000 261331494 48983905 881868750 781830534 695641946 888787608 53260475 3830725 603231233 ...
output:
61713
result:
ok single line: '61713'
Test #17:
score: 5
Accepted
time: 104ms
memory: 8020kb
input:
100000 100000 293506655 235651927 491497166 438822357 265156420 853923925 751934202 175188320 797954...
output:
87719
result:
ok single line: '87719'
Test #18:
score: 5
Accepted
time: 101ms
memory: 8024kb
input:
100000 100000 842554959 79038413 923174446 409500140 348943344 708184830 167573117 117904906 7803893...
output:
80630
result:
ok single line: '80630'
Test #19:
score: 5
Accepted
time: 107ms
memory: 8024kb
input:
100000 100000 228364413 22596352 445742699 624348298 29932170 795936020 608997744 551190379 83387823...
output:
92773
result:
ok single line: '92773'
Test #20:
score: 5
Accepted
time: 87ms
memory: 8020kb
input:
100000 100000 482819933 162045322 954408191 299330487 19663334 576950439 84528908 37965318 245372349...
output:
93410
result:
ok single line: '93410'
Extra Test:
score: 0
Extra Test Passed