QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#688405#8038. Hammer to FallLuckyblockTL 28ms14196kbC++202.3kb2024-10-30 08:35:242024-10-30 08:35:25

Judging History

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

  • [2024-10-30 08:35:25]
  • 评测
  • 测评结果:TL
  • 用时:28ms
  • 内存:14196kb
  • [2024-10-30 08:35:24]
  • 提交

answer

//
/*
By:Luckyblock
*/
#include <bits/stdc++.h>
#define LL long long
const int kN = 2e5 + 10;
const LL kInf = 1e18 + 2077;
const LL p = 998244353;
//=============================================================
int n, m, q;
LL a[kN], b[kN];

struct Edge {
  int v, w;
  bool operator < (const Edge sec_) const {
    return v < sec_.v;
  }
};
std::vector<Edge> edge[kN];
int du_lim;

struct Node {
  LL f;
  int v, w, tag;
  bool operator < (const Node sec_) const {
    return f < sec_.f;
  }
};
LL f[kN];
std::vector<Node> s[kN];
int nowtime, time_lim, tag[kN];
std::vector<int> upded;
//=============================================================
void rebuild() {
  upded.clear();
  for (int i = 1; i <= n; ++ i) {
    if ((int) edge[i].size() <= du_lim) continue;
    s[i].clear();
    for (auto [v, w]: edge[i]) s[i].push_back((Node) {f[v] + w, v, w, tag[v]});
  }
}
void update(int u_) {
  ++ tag[u_];
  upded.push_back(u_);
  f[u_] = kInf;

  if ((int) edge[u_].size() <= du_lim) {
    for (auto [v, w]: edge[u_]) f[u_] = std::min(f[u_], f[v] + w);
    return ;
  }
  std::nth_element(s[u_].begin(), s[u_].begin() + du_lim + 1, s[u_].end());
  for (int i = 0; i <= du_lim; ++ i) {
    int v = s[u_][i].v, tt = s[u_][i].tag; LL ff = s[u_][i].f;
    if (tt == tag[v]) f[u_] = std::min(f[u_], ff);
  }
  for (auto v: upded) {
    auto it = std::lower_bound(edge[u_].begin(), edge[u_].end(), (Edge) {v, 0});
    if (it == edge[u_].end() || it->v != v) continue;
    f[u_] = std::min(f[u_], f[v] + it->w);
  }
}
//=============================================================
int main() {
  //freopen("1.txt", "r", stdin);
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n >> m >> q;
  for (int i = 1; i <= n; ++ i) std::cin >> a[i];
  for (int i = 1; i <= m; ++ i) {
    int u, v, w; std::cin >> u >> v >> w;
    edge[u].push_back((Edge) {v, w});
    edge[v].push_back((Edge) {u, w});
  }
  for (int i = 1; i <= n; ++ i) std::sort(edge[i].begin(), edge[i].end());
  for (int i = 1; i <= q; ++ i) std::cin >> b[i];

  du_lim = time_lim = sqrt(m);
  rebuild();
  for (int i = q; i; -- i) {
    if (++ nowtime == time_lim) rebuild();
    update(b[i]);
  }
  LL ans = 0;
  for (int i = 1; i <= n; ++ i) (ans += f[i] * a[i] % p) %= p;
  std::cout << ans << "\n";
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5652kb

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

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: 1ms
memory: 7632kb

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: 2ms
memory: 5836kb

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: 28ms
memory: 14196kb

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: