QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661484#8038. Hammer to FallLuckyblockWA 3ms18164kbC++202.3kb2024-10-20 16:27:292024-10-20 16:27:30

Judging History

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

  • [2024-10-20 16:27:30]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:18164kb
  • [2024-10-20 16:27:29]
  • 提交

answer

//
/*
By:Luckyblock
*/
#include <bits/stdc++.h>
#define LL long long
#define pr std::pair
#define pii std::pair<int,int>
#define mp std::make_pair
const LL kInf = 1e18 + 2077;
const int kN = 2e5 + 10;
const LL p = 998244353;
//=============================================================
int n, m, q, a[kN], target[kN];
std::vector<pii> edge[kN];
int lim, du[kN], type[kN];

int nowtime, tag[kN];
struct node {
  LL val;
  int v, w, tim;
  bool operator < (const node& sec_) const {
    return val < sec_.val;
    // if (val != sec_.val) return val < sec_.val;
    // if (tim != sec_.tim) return tim < sec_.tim;
    // return w < sec_.w;
  }
};
std::set<node> s[kN];
int out[kN];
LL val[kN], cost[kN];
//=============================================================
void init() {
  lim = sqrt(m);
  for (int i = 1; i <= n; ++ i) {
    if (du[i] > lim) {
      type[i] = 1;
      for (auto [v, w]: edge[i]) s[i].insert((node) {w, v, w, 0});
    }
  }
}
void solve() {
  for (int i = q; i; -- i) {
    int u = target[i], o, c;
    LL minval = kInf;
    if (type[u]) {
      auto top = *s[u].begin();
      while (tag[top.v] != top.tim) {
        s[u].erase(s[u].begin());
        s[u].insert((node) {val[top.v] + top.w, top.v, top.w, tag[top.v]});
        top = *s[u].begin();
      }
      minval = top.val, o = top.v, c = top.w;
    } else {
      for (auto [v, w]: edge[u]) {
        if (val[v] + w < minval) {
          minval = val[v] + w, o = v, c = w;
        }
      }
    }
    out[i] = o, cost[i] = c;
    val[u] += minval, tag[u] = ++ nowtime;
  }
}
//=============================================================
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(mp(v, w));
    edge[v].push_back(mp(u, w));
    ++ du[u], ++ du[v];
  }
  for (int i = 1; i <= q; ++ i) std::cin >> target[i];
  init(), solve();

  LL ans = 0;
  for (int i = 1; i <= q; ++ i) {
    int u = target[i];
    ans = (ans + 1ll * a[u] % p * cost[i] % p) % p;
    a[out[i]] = (a[out[i]] + a[u]) % p; 
    a[u] = 0;
  }
  std::cout << ans << "\n";
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 15920kb

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

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: 3ms
memory: 17968kb

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: 0ms
memory: 18164kb

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:

8635612

result:

wrong answer 1st lines differ - expected: '609241', found: '8635612'