QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#735137 | #8038. Hammer to Fall | water_tomato | WA | 83ms | 62868kb | C++14 | 2.7kb | 2024-11-11 17:42:46 | 2024-11-11 17:42:46 |
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=1;
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: 8ms
memory: 62604kb
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: 12ms
memory: 62868kb
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: 7ms
memory: 62116kb
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: -100
Wrong Answer
time: 83ms
memory: 62464kb
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:
702824
result:
wrong answer 1st lines differ - expected: '609241', found: '702824'