QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#661808#8038. Hammer to FallShiroRinneTL 223ms45036kbC++201.8kb2024-10-20 18:18:092024-10-20 18:18:10

Judging History

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

  • [2024-10-20 18:18:10]
  • 评测
  • 测评结果:TL
  • 用时:223ms
  • 内存:45036kb
  • [2024-10-20 18:18:09]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int ll

using ll = long long;

constexpr int N = 2e5 + 10;
constexpr int mod = 998244353;
constexpr ll inf = 1e18;

using namespace std;

void solve(){
	int n, m, q;
	cin >> n >> m >> q;

	vector<vector<pair<int, ll>>> G(n + 1);
	vector<int> a(n + 1), d(n + 1);
	map<pair<int, int>, int> val;
	map<pair<int, int>, int> rw;
	for (int i = 1; i <= n; ++i) cin >> a[i];

	int B = sqrt(n);
	for (int i = 1; i <= m; ++i) {
		int u, v; ll w;
		cin >> u >> v >> w;
		d[u]++;
		d[v]++;
		G[u].push_back({v, w});
		G[v].push_back({u, w});
		val[{u, v}] = val[{v, u}] = w;
		rw[{u, v}] = rw[{v, u}] = w;
 	}

	vector<int> b(q);
	for (int i = 0; i < q; ++i) cin >> b[i];
	reverse(b.begin(), b.end());
	
	vector<int> sbpoint;
	for (int i = 1; i <= n; ++i) {
		if (d[i] > B) {
			sbpoint.push_back(i);
		}
 	}

 	vector<int> vis(n + 1);
	vector<ll> dp(n + 1, 0);

	vector<multiset<ll>> st(n + 1);  

	for (auto u : sbpoint) {
		for (auto [v, w] : G[u]) {
			st[u].insert(w);
		}
	}

	for (auto u : b) {
		vis[u] = 1;
		dp[u] = inf;
		if (d[u] <= B) {
			for (auto [v, w]: G[u]) {
				dp[u] = min(dp[v] + w, dp[u]);
			}
		}else {
			dp[u] = *st[u].begin();  
		}
		for (auto v : sbpoint) {
			if (val.count({v, u})) {
				st[v].extract(val[{v, u}]); 
			}
		}
		for (auto v : sbpoint) {
			if (val.count({v, u})) {
				int w = rw[{v, u}];
				st[v].insert(w + dp[u]);
				val[{v, u}] = w + dp[u];
			}
		}
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		ans = (ans + (1ll * dp[i] * a[i]) % mod) % mod;
	}
	cout << ans << endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while(t--) solve();
    return 0;
}	

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

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: 3560kb

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: 3652kb

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: 48ms
memory: 3848kb

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: 223ms
memory: 45036kb

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
Time Limit Exceeded

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:


result: