QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#735138 | #8038. Hammer to Fall | water_tomato | WA | 817ms | 88032kb | C++14 | 2.7kb | 2024-11-11 17:43:10 | 2024-11-11 17:43:11 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define pi pair<int,int>
using namespace std;
const int N=5e5+5;
struct node{
int to,nxt,w;
}e[N];
int head[N],cnt;
void add(int u,int v,int w){
e[++cnt]={v,head[u],w};
head[u]=cnt;
}
int n,q,m;
int a[N],b[N],val[N];
set<pi> s[N];
int du[N];
int LIM=100;
bool heavy[N];
vector<pi> l_edge[N],path,EDGE[N];
vector<int> heavy_nodes;
const int mod=998244353;
map<pi,int> dis;
void Nth_element(int u,int l,int r,int k){
if(l==r) return;
int rd=l+rand()%(r-l);
swap(EDGE[u][rd],EDGE[u][l]);
int key=val[EDGE[u][l].second];
pi ori=EDGE[u][l];
int i=l,j=r;
while(i<j){
while(i<j && val[EDGE[u][j].second] >=key) j--;
EDGE[u][i]=EDGE[u][j];
while(i<j && val[EDGE[u][i].second] <key) i++;
EDGE[u][j]=EDGE[u][i];
}
EDGE[u][i]=ori;
if(i==k-1) return;
else if(i>k-1) Nth_element(u,l,i-1,k);
else Nth_element(u,i+1,r,k);
}
void update_heavy(){
for(auto u:heavy_nodes){
Nth_element(u,0,EDGE[u].size()-1,LIM+1);
}
}
signed main(){
scanf("%lld%lld%lld",&n,&m,&q);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(int i=1,u,v,w;i<=m;i++){
scanf("%lld%lld%lld",&u,&v,&w);
du[u]++;du[v]++;
add(u,v,w);add(v,u,w);
EDGE[u].push_back({w,v});EDGE[v].push_back({w,u});
dis[{u,v}]=dis[{v,u}]=w;
}
for(int i=1;i<=n;i++){
if(du[i]>=LIM){
heavy[i]=1;
heavy_nodes.push_back(i);
// printf("!%d\n",i);
}
}
for(int i=1;i<=q;i++) scanf("%lld",&b[i]);
for(int j=q;j>=1;j--){
int u=b[j];
if(j%LIM==0) update_heavy();
int minv=-1,minn=1e18;
if(heavy[u]){
for(int i=0;i<=min(LIM,(int)EDGE[u].size()-1);i++){
pi x=EDGE[u][i];
if(x.first+val[x.second]<minn){
minn=x.first+val[x.second];
minv=x.second;
}
}
path.push_back({u,minv});
}
else{
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if(e[i].w+val[v]<minn){
minn=e[i].w+val[v];
minv=v;
}
}
path.push_back({u,minv});
}
val[u]=minn;
}
long long ans=0;
for(int i=path.size()-1;i>=0;i--){
int u=path[i].first,v=path[i].second;
ans=(ans+a[u]*dis[{u,v}])%mod;
a[v]=(a[v]+a[u])%mod;a[u]=0;
// printf("! %d %d\n",path[i].first,path[i].second);
}
printf("%lld\n",ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 61516kb
input:
3 2 2 1 1 1 2 3 10 1 2 1 3 2
output:
12
result:
ok single line: '12'
Test #2:
score: 0
Accepted
time: 0ms
memory: 62320kb
input:
2 1 10 5000 5000 1 2 10000 1 2 2 1 2 2 1 1 1 2
output:
550000000
result:
ok single line: '550000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 62052kb
input:
10 10 10 5 14 99 14 18 4 58 39 48 60 2 4 4 6 9 56 10 8 34 7 5 96 1 3 26 3 7 92 6 8 4 5 1 72 7 6 39 7 2 93 8 8 9 10 2 2 5 9 2 3
output:
8810
result:
ok single line: '8810'
Test #4:
score: 0
Accepted
time: 7ms
memory: 61776kb
input:
100 500 10000 89 61 65 85 89 2 32 97 13 70 29 86 68 74 84 64 54 39 26 84 56 95 73 11 70 26 60 40 84 58 68 33 65 71 55 2 11 71 49 85 14 59 38 11 60 8 81 78 27 32 52 49 35 94 62 72 64 50 12 45 77 74 92 67 92 38 81 39 12 29 60 70 53 33 25 60 7 83 4 85 47 32 13 58 85 86 44 68 44 1 81 62 97 7 66 62 5 16 ...
output:
609241
result:
ok single line: '609241'
Test #5:
score: 0
Accepted
time: 171ms
memory: 88032kb
input:
100000 100000 100000 134299012 740620432 241626312 533601686 901212368 274154852 46613593 72208460 685661661 930069933 934386896 140544225 900179749 8735320 54649110 922673925 450551589 517879800 773426781 410723403 783459037 344315202 75310230 122339501 113898579 646500753 18238713 119326471 969272...
output:
641103242
result:
ok single line: '641103242'
Test #6:
score: -100
Wrong Answer
time: 817ms
memory: 84972kb
input:
448 100000 100000 411038009 847809848 901622409 143987890 230747977 330204397 58948994 635255827 124637955 446506876 693363517 282765360 687916399 598850473 404480258 958197468 332242997 7338874 321860348 37384562 440321061 434694843 935461053 803393359 852456369 428568442 233194935 663299156 907095...
output:
662096481
result:
wrong answer 1st lines differ - expected: '571525504', found: '662096481'