QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#317872#8038. Hammer to FallBreakPlusRE 9ms16548kbC++143.9kb2024-01-29 20:57:502024-01-29 20:57:50

Judging History

你现在查看的是最新测评结果

  • [2024-01-30 14:24:05]
  • hack成功,自动添加数据
  • (/hack/528)
  • [2024-01-29 20:57:50]
  • 评测
  • 测评结果:RE
  • 用时:9ms
  • 内存:16548kb
  • [2024-01-29 20:57:50]
  • 提交

answer

/* Author: BreakPlus */
#include<bits/stdc++.h>
using namespace std; typedef long long ll; typedef pair<ll,ll> P; typedef pair<pair<ll,ll>,ll> P3; typedef pair<pair<ll,ll>,pair<ll,ll> >P4;
#define mkp make_pair
#define fi first
#define se second
#define popcnt __builtin_popcount
#define pb emplace_back
const ll mod=998244353; const ll maxn=500005;

inline ll read(){ ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*f; }
inline ll lowbit(ll x){ return x&-x; }
struct Bit{
	ll c[maxn], _x[maxn], _w[maxn], tp=0;
	void update(ll x,ll w){ _x[++tp]=x, _w[tp]=w; while(x<maxn) c[x]+=w, x+=lowbit(x);} void update2(ll x,ll w){ while(x<maxn) c[x]+=w, x+=lowbit(x);}
	ll query(ll x){ ll res=0; while(x) res+=c[x], x-=lowbit(x); return res; }
	void clear(){ for(ll i=1;i<=tp;i++) update2(_x[i], -_w[i]); tp=0;} void fclear(){ tp=0; memset(c, 0, sizeof(c)); }
}bit;

inline ll maxx(ll a,ll b){ return a>b?a:b; } inline ll minn(ll a,ll b){ return a<b?a:b; }
inline void chkmax(ll &a,ll b){ a = maxx(a, b); } inline void chkmin(ll &a,ll b){ a = minn(a, b); }
inline void _Add(ll &a,ll b){ a+=b; if(a>=mod) a-=mod; } inline void _Minus(ll &a,ll b){ a-=b; if(a<0) a+=mod; }
inline ll Add(ll a,ll b){ a+=b; if(a>=mod) a-=mod; return a; } inline ll Minus(ll a,ll b){ a-=b; if(a<0) a+=mod; return a; }

inline ll qpow(ll a,ll b){ ll ans=1, base=a; while(b){ if(b&1) ans=1ll*ans*base%mod; base=1ll*base*base%mod; b>>=1; } return ans; }
struct Comb{
    ll fac[maxn], inv[maxn];
    Comb(){ fac[0]=1; for(ll i=1;i<=maxn-5;i++) fac[i]=1ll*fac[i-1]*i%mod; inv[maxn-5]=qpow(fac[maxn-5],mod-2); for(ll i=maxn-6;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod; }
    ll C(ll a,ll b){ if(a<0 || b<0 || a<b) return 0; return 1ll*fac[a]*inv[b]%mod*inv[a-b]%mod; }
}comb;
ll Fac(ll x){return comb.fac[x];} ll iFac(ll x){return comb.inv[x];} ll Inv(ll x){return qpow(x, mod-2);}
/*--------------head------------------*/
void init(){

}
const ll B=1400;
ll n,m,q,a[100005],b[100005];
vector<P>E[100005],G[100005];
ll dp[100005], lst[1405], id[100005], cnt, ind[1405];
priority_queue<ll,vector<ll>,greater<ll> >add[1405], del[1405];
void remain(ll i, ll w){
    for(auto p: G[i]){
        del[p.fi].push(dp[i]+p.se);
    }
    dp[i]=w;
    for(auto p: G[i]){
        add[p.fi].push(dp[i]+p.se);
    }
}
void solve(){
    n=read(), m=read(), q=read();
    for(ll i=1;i<=n;i++) a[i]=read();
    for(ll i=1;i<=m;i++){
        ll u=read(), v=read(), w=read();
        E[u].pb(v, w); E[v].pb(u, w); ind[u]++; ind[v]++;
    }
    for(ll i=1;i<=q;i++) b[i]=read();
    for(ll i=1;i<=n;i++) {
        if(ind[i] >= B){
            lst[++cnt] = i, id[i] = cnt;
        }
    }
    for(ll i=1;i<=n;i++){
        for(auto p: E[i]){
            if(id[p.fi]) G[i].pb(p);
        }
    }
    for(ll i=1;i<=n;i++) dp[i] = 0;
    for(ll i=1;i<=n;i++)
        for(auto p: G[i]) add[p.fi].push(p.se);
    for(ll i=q;i>=1;i--){
        if(ind[b[i]] >= B){
            while(!add[b[i]].empty() && !del[b[i]].empty() && add[b[i]].top() == del[b[i]].top()) add[b[i]].pop(), del[b[i]].pop();
            remain(b[i], add[b[i]].top());
        }else {
            ll val = 1e18;
            for(auto p: E[b[i]])
                chkmin(val, dp[p.fi] + p.se);
            remain(b[i], val);
        }
    }
    ll ans = 0;
    for(ll i=1;i<=n;i++)
        _Add(ans, a[i] * (dp[i] % mod) % mod);
    printf("%lld\n", ans);
}
//#define FastIO
//#define OIcontest
int main(){
    #ifdef OIcontest
        freopen(".in","r",stdin); freopen(".out","w",stdout); 
    #endif
    #ifdef FastIO
        ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    #endif
    init();
    ll T=1;
    while(T--) solve();
    return 0;
}
/*
Input1 Text Copied:


Answer1 Text Copied:


Input2 Text Copied:


Answer2 Text Copied:
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 9ms
memory: 16360kb

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: 6ms
memory: 16360kb

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: 4ms
memory: 16548kb

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: 6ms
memory: 16536kb

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: -100
Runtime Error

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:


result: