QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#639806#8038. Hammer to FallSSL_TJHRE 103ms39000kbC++203.4kb2024-10-13 22:46:032024-10-13 22:46:03

Judging History

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

  • [2024-10-13 22:46:03]
  • 评测
  • 测评结果:RE
  • 用时:103ms
  • 内存:39000kb
  • [2024-10-13 22:46:03]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define mo 998244353

using namespace std;

const int N = 5e5 + 100;
int n, m, q, a[N], le[N], KK, b[N], bdy[N];
vector <int> zt[N], ls[N], rs[N];
struct node {
    int x, to, nxt;
}e[N << 6];
struct rem {
    int x, y, z;
}c[N];
ll f[N];
bool in[N];

bool cmp1(rem x, rem y) {
    if (x.x != y.x) return x.x < y.x;
    if (x.y != y.y) return x.y < y.y;
    return x.z < y.z;
}

void add(int x, int y, int z) {
    e[++KK] = (node){z, y, le[x]}; le[x] = KK;
    // printf("%d %d\n", x, y);
}

void BFS() {
    for (int i = 1; i <= q + n; i++) f[i] = 1000000000000000000ll;
    priority_queue <pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > qs;
    for (int i = q + 1; i <= q + n; i++) {
        f[i] = 0; qs.push(make_pair(0, i));
    }
    while (!qs.empty()) {
        int now = qs.top().second; qs.pop();
        if (in[now] == 1) continue;
        in[now] = 1;
        for (int i = le[now]; i; i = e[i].nxt)
            if (f[e[i].to] > f[now] + e[i].x) {
                f[e[i].to] = f[now] + e[i].x;
                qs.push(make_pair(f[e[i].to], e[i].to));
            }
    }
}

int id(pair <int, int> x) {
    if (x.second <= q) return x.second;
    return x.first + q;
}

int main() {
    scanf("%d %d %d", &n, &m, &q);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= m; i++) {
        scanf("%d %d %d", &c[i].x, &c[i].y, &c[i].z);
        if (c[i].x > c[i].y) swap(c[i].x, c[i].y);
    }
    sort(c + 1, c + m + 1, cmp1);
    for (int i = 1; i <= q; i++) {
        scanf("%d", &b[i]);
        zt[b[i]].push_back(i);
        // id[make_pair(b[i], i)] = i;
    }
    for (int i = 1; i <= n; i++) {
        zt[i].push_back(q + 1);//, id[make_pair(i, q + 1)] = q + i;
        ls[i].clear(); rs[i].clear();
        for (int j = 0; j < zt[i].size(); j++) {
            if (j != zt[i].size() - 1) add(id(make_pair(i, zt[i][j])), id(make_pair(i, zt[i][j + 1])), 0);
            ls[i].push_back(j ? zt[i][j - 1] + 1 : 1);
            rs[i].push_back(zt[i][j]);
            // ls[i][j] = j ? zt[i][j - 1] + 1 : 1;
            // rs[i][j] = zt[i][j];
        }
        ls[i].resize(zt[i].size());
        rs[i].resize(zt[i].size());
    }

    for (int i = 1; i <= m; i++) {
        int x = c[i].x, y = c[i].y, z = c[i].z;
        if (i > 1 && x == c[i - 1].x && y == c[i - 1].y) continue;
        if (zt[x].size() > zt[y].size()) swap(x, y);
        if (zt[x].size() != ls[x].size() || zt[x].size() != rs[x].size()) {printf("%d", x); return 0;}
        if (zt[y].size() != ls[y].size() || zt[y].size() != rs[y].size()) {printf("%d", y); return 0;}
        for (int j = 0; j < zt[x].size(); j++) {
            int pl = lower_bound(rs[y].begin(), rs[y].end(), ls[x][j]) - rs[y].begin();
            if (pl >= 0 && pl < zt[y].size()) add(id(make_pair(x, zt[x][j])), id(make_pair(y, zt[y][pl])), z);
            pl = upper_bound(ls[y].begin(), ls[y].end(), rs[x][j]) - ls[y].begin() - 1;
            if (pl >= 0 && pl < zt[y].size()) add(id(make_pair(y, zt[y][pl])), id(make_pair(x, zt[x][j])), z);
        }
    }

    BFS();

    ll ans = 0;
    for (int i = 1; i <= n; i++) in[i] = 0;
    for (int i = 1; i <= q; i++) {
        if (in[b[i]] == 1) continue;
        in[b[i]] = 1;
        (ans += f[i] % mo * a[b[i]] % mo) %= mo;
        // ans += f[i] * a[b[i]];
    }
    printf("%lld\n", ans);

    return 0;
}

详细

Test #1:

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

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

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

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: 8ms
memory: 14480kb

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: 103ms
memory: 39000kb

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

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: