QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#460863 | #5036. 卑鄙的下毒人 | Kevin5307 | 10 | 101ms | 41020kb | C++23 | 2.6kb | 2024-07-02 12:14:19 | 2024-07-02 12:14:20 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) greverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n;
int l[300300],r[300300];
ll w[300300];
ll dp[500500];
int lst[500500];
int choose[500500];
ll dist[500500];
int inque[500500];
vector<pair<int,ll>> G[500500];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int k;
cin>>n>>n>>k;
for(int i=1;i<=n;i++)
cin>>l[i]>>r[i]>>w[i];
vector<pii> vec;
for(int i=1;i<=n;i++)
vec.pb(l[i],i);
srt(vec);
int p=0;
memset(dp,-inf,sizeof(dp));
dp[0]=0;
for(int i=0;i<=500000;i++)
{
if(dp[i]>dp[i+1])
{
dp[i+1]=dp[i];
lst[i+1]=-1;
}
while(p<sz(vec)&&vec[p].first==i+1)
{
if(dp[i]+w[vec[p].second]>dp[r[vec[p].second]])
{
dp[r[vec[p].second]]=dp[i]+w[vec[p].second];
lst[r[vec[p].second]]=vec[p].second;
}
p++;
}
}
ll ans=dp[500000];
int cur=500000;
while(cur)
{
if(lst[cur]==-1)
{
G[cur].pb(cur-1,0);
cur--;
}
else
{
choose[lst[cur]]=1;
cur=l[lst[cur]]-1;
}
}
for(int i=2;i<=k;i++)
{
memset(dist,-inf,sizeof(dist));
for(int i=0;i<=500000;i++)
G[i].clear();
priority_queue<pair<ll,int>> pq;
pq.emplace(0,0);
dist[0]=0;
for(int i=1;i<=500000;i++)
G[i-1].pb(i,0);
for(int i=1;i<=n;i++)
if(!choose[i])
G[l[i]-1].pb(r[i],i);
else
G[r[i]].pb(l[i]-1,i);
while(!pq.empty())
{
ll d=pq.top().first;
int x=pq.top().second;
pq.pop();
if(dist[x]!=d) continue;
for(auto pr:G[x])
{
ll edge;
if(!pr.second) edge=0;
else if(choose[pr.second]) edge=-w[pr.second];
else edge=w[pr.second];
ll nd=edge+dp[x]-dp[pr.first]+dist[x];
if(nd>dist[pr.first])
{
lst[pr.first]=pr.second;
dist[pr.first]=nd;
pq.emplace(nd,pr.first);
}
}
}
int nd=500000;
while(nd)
{
int val=lst[nd];
if(val)
{
nd=l[val]+r[val]-1-nd;
choose[val]^=1;
}
else
nd--;
}
ans+=dp[500000]-dp[0]+dist[500000];
}
cout<<ans<<endl;
return 0;
}
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 52ms
memory: 40608kb
input:
7 20 5 3 4 1 1 1 1 2 7 1 3 7 1 2 2 1 3 7 1 4 6 1 7 7 1 5 5 1 1 6 1 3 4 1 1 4 1 3 6 1 3 3 1 2 5 1 1 1 1 5 5 1 1 1 1 6 7 1 2 2 1
output:
15
result:
ok "15"
Test #2:
score: 10
Accepted
time: 43ms
memory: 40612kb
input:
12 20 5 5 5 1 8 12 1 4 10 1 10 12 1 2 11 1 3 6 1 6 12 1 1 10 1 4 9 1 7 10 1 4 12 1 2 10 1 1 12 1 4 5 1 4 9 1 7 9 1 3 9 1 10 11 1 6 12 1 4 10 1
output:
10
result:
ok "10"
Test #3:
score: 10
Accepted
time: 51ms
memory: 40732kb
input:
7 20 5 2 7 1 6 6 1 3 6 1 3 3 1 2 5 1 6 6 1 2 6 1 2 7 1 4 6 1 3 3 1 2 2 1 5 5 1 1 4 1 1 5 1 2 5 1 4 4 1 2 7 1 3 4 1 2 4 1 1 2 1
output:
12
result:
ok "12"
Test #4:
score: 10
Accepted
time: 43ms
memory: 40608kb
input:
11 20 5 1 8 1 1 10 1 10 11 1 7 11 1 3 10 1 3 8 1 1 8 1 4 5 1 4 5 1 1 7 1 3 4 1 3 7 1 5 6 1 2 6 1 4 9 1 4 10 1 4 4 1 1 11 1 7 10 1 4 8 1
output:
9
result:
ok "9"
Test #5:
score: 10
Accepted
time: 39ms
memory: 40616kb
input:
8 20 5 6 7 1 4 5 1 1 7 1 3 7 1 1 6 1 3 8 1 1 1 1 2 2 1 1 7 1 3 4 1 6 6 1 1 7 1 1 1 1 1 3 1 4 4 1 8 8 1 3 4 1 1 6 1 6 6 1 2 8 1
output:
13
result:
ok "13"
Test #6:
score: 10
Accepted
time: 11ms
memory: 36952kb
input:
20 20 1 3 14 1 1 17 1 3 18 1 14 20 1 15 17 1 9 17 1 10 12 1 6 20 1 11 16 1 3 17 1 1 2 1 6 19 1 17 18 1 4 18 1 4 9 1 3 7 1 4 13 1 17 19 1 7 12 1 10 14 1
output:
4
result:
ok "4"
Test #7:
score: 10
Accepted
time: 15ms
memory: 40820kb
input:
20 20 2 10 20 1 8 9 1 1 8 1 12 17 1 3 20 1 7 18 1 6 10 1 3 5 1 5 9 1 3 6 1 1 3 1 2 6 1 9 11 1 2 11 1 3 15 1 1 7 1 5 7 1 6 11 1 15 18 1 8 10 1
output:
7
result:
ok "7"
Test #8:
score: 10
Accepted
time: 32ms
memory: 40860kb
input:
20 20 3 3 16 1 6 17 1 8 17 1 11 19 1 5 7 1 3 13 1 16 19 1 6 8 1 3 14 1 7 10 1 6 13 1 1 5 1 4 20 1 16 16 1 8 17 1 7 19 1 12 16 1 5 14 1 10 18 1 10 16 1
output:
7
result:
ok "7"
Test #9:
score: 10
Accepted
time: 46ms
memory: 40720kb
input:
20 20 4 8 19 1 15 19 1 10 20 1 5 11 1 1 2 1 12 15 1 5 7 1 10 14 1 3 6 1 13 19 1 5 10 1 6 7 1 7 7 1 1 19 1 9 16 1 3 16 1 1 2 1 4 20 1 15 16 1 7 11 1
output:
12
result:
ok "12"
Test #10:
score: 10
Accepted
time: 54ms
memory: 40840kb
input:
20 20 5 10 18 1 5 9 1 1 17 1 12 19 1 12 13 1 11 17 1 7 10 1 2 10 1 8 13 1 4 6 1 12 13 1 13 13 1 14 20 1 1 9 1 19 19 1 5 8 1 16 16 1 1 6 1 5 16 1 2 4 1
output:
15
result:
ok "15"
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 101ms
memory: 41020kb
input:
1794 5000 5 419 430 46802829 1071 1140 167141363 1154 1554 366136993 735 1265 152210166 387 1104 646459531 1073 1637 525871859 1340 1729 44303243 1221 1574 588158235 91 478 922877048 1117 1268 460323230 315 1103 378106915 272 1071 784282054 1147 1469 220209516 281 375 514585737 677 1031 231082599 55...
output:
133829822304
result:
wrong answer 1st words differ - expected: '136716114929', found: '133829822304'
Subtask #3:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 61ms
memory: 32416kb
input:
322675 500000 1 162058 177924 125740423 72321 188693 51206015 73706 159883 238256306 223634 241332 292316893 8164 94217 879196279 232892 319246 624760769 67688 195525 319652781 70831 92026 394982900 68675 156743 598333126 107804 308096 843245966 57077 248406 291662171 12794 193657 560389007 105560 2...
output:
240868487651
result:
wrong answer 1st words differ - expected: '480886198651', found: '240868487651'
Subtask #4:
score: 0
Time Limit Exceeded
Test #51:
score: 0
Time Limit Exceeded
input:
194181 500000 5 22921 38709 1 103611 130117 1 33044 135246 1 25161 106036 1 13484 183424 1 129622 133239 1 103905 105727 1 8418 141108 1 5951 145648 1 61392 105830 1 139975 149309 1 47361 59947 1 91598 172246 1 32303 43094 1 72490 170121 1 68502 168603 1 56051 91019 1 106112 129606 1 70776 177996 1 ...
output:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #66:
score: 0
Time Limit Exceeded
input:
265199 500000 5 51732 151507 196279569 1147 251097 325871693 79410 120618 539045634 209514 221950 912376813 44813 147573 616444800 53619 134328 533306546 94940 108466 186490362 42483 236958 489649490 127349 167018 943263893 103970 193784 202963780 197001 221033 210521750 5815 113674 152090319 129972...