QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#758352#9569. Subwayucup-team173#WA 31ms329852kbC++204.3kb2024-11-17 17:59:122024-11-17 17:59:12

Judging History

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

  • [2024-11-17 17:59:12]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:329852kb
  • [2024-11-17 17:59:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll

const int maxn = 4e5 + 10;
struct dt {
    ll k, b;
    dt(ll ak = 0, ll ab = 0) : k(ak), b(ab) {}
    ll get(ll x) {
        return 1ll * k * x + b;
    }
} tr[maxn * 50];
int ls[maxn * 50];
int rs[maxn * 50];
int cnt;
int root[maxn];
void ins(int& i, int l, int r, dt nt) {
    if (i == 0) {
        i = ++cnt;
        tr[i] = nt;
        return;
    }
    if (tr[i].get(l) >= nt.get(l) && tr[i].get(r) >= nt.get(r)) {
        tr[i] = nt;
        return;
    }
    if (tr[i].get(l) <= nt.get(l) && tr[i].get(r) <= nt.get(r)) {
        return;
    }
    int mid = l + r >> 1;
    if (tr[i].get(l) > nt.get(l) || tr[i].get(mid) > nt.get(mid)) {
        ins(ls[i], l, mid, nt);
    }
    if (tr[i].get(mid + 1) > nt.get(mid + 1) || tr[i].get(r) > nt.get(r)) {
        ins(rs[i], mid + 1, r, nt);
    }
    return;
}

ll ask(int i, int l, int r, int x) {
    if (i == 0) return 1e18;
    ll ans = tr[i].get(x);
    if (l == r) return ans;
    int mid = l + r >> 1;
    if (x <= mid)
        ans = min(ans, ask(ls[i], l, mid, x));
    else
        ans = min(ans, ask(rs[i], mid + 1, r, x));
    return ans;
}
void modify(int rt, int k, int b) {
    // insert kx + b into rt
    ins(root[rt], 1, 1e6, dt(k, b));
}
ll query(int rt, int x) {
    // get f(x) on rt
    return ask(root[rt], 1, 1e6, x);
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(k + 1), b(k + 1);
    for (int i = 1; i <= k; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= k; i++) {
        cin >> b[i];
    }
    vector<vector<int>> pass(n + 1); // node id
    vector<int> cur_pass(n + 1);
    int totid = 0;
    constexpr int N = 400100;
    vector<pair<int, int>> bel(N, {-1, -1}); // <path id, node id>
    vector<pair<int, int>> G(N, {-1, -1});
    for(int i = 1; i <= k; i++) {
        int p, x, w;
        cin >> p >> x;
        pass[x].push_back(totid);
        bel[totid] = {i, x};
        totid++;
        for(int j = 2; j <= p; j++) {
            cin >> w >> x;
            if(j > 1) G[totid - 1] = {totid, w};
            pass[x].push_back(totid);
            bel[totid] = {i, x};
            totid++;
        }
    }
    for(int i = 1; i <= n; i++) {
        sort(pass[i].begin(), pass[i].end(), [&](int p, int q) {
            return a[p] < a[q];
        });
    }
    constexpr ll inf = 1e18;
    vector<ll> dis(totid, inf);
    priority_queue<array<ll, 2>> pq; // <dis, x, type>
    for(auto id : pass[1]) {
        pq.push({dis[id] = 0, id});
    }
    modify(1, 0, 0);
    cur_pass[1] = pass[1].size();
    vector<int> vis(totid);
    while(pq.size()) {
        auto [d, x] = pq.top(); pq.pop();
        d = -d;
        if(vis[x]) continue;
        vis[x] = 1;
        auto [path_id, node_id] = bel[x];
        modify(node_id, b[path_id], d);
        while(cur_pass[node_id] < pass[node_id].size() && vis[pass[node_id][cur_pass[node_id]]]) {
            cur_pass[node_id]++;
        }
        if(cur_pass[node_id] < pass[node_id].size()) {
            int y = pass[node_id][cur_pass[node_id]];
            auto [y_path, y_node] = bel[y];
            auto res = query(node_id, a[y_path]);
            if(dis[y] > res) {
                dis[y] = res;
                pq.push({-dis[y], y});
            }
        }
        auto [y, w] = G[x];
        if(y != -1 && dis[y] > d + w) {
            dis[y] = d + w;
            pq.push({-dis[y], y});
        }
    }
    vector<ll> ans(n + 1, inf);
    for(int i = 1; i <= n; i++) {
        for(int j : pass[i]) {
            ans[i] = min(ans[i], dis[j]);
        }
    }
    for(int i = 2; i <= n; i++) {
        cout << ans[i] << " \n"[i == n];
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}
/*
6 3
1 5 1
5 5 1
3 1 2 2 3 3
3 5 1 2 1 4
3 3 4 5 4 6
insert 1 5 0
insert 2 5 -2
y = 4    path = 2
query 2 5   23
insert 3 5 -1
y = 6    path = 3
query 3 1   4
insert 3 1 -4
y = 2    path = 3
query 3 1   -3
insert 5 1 0
y = 3    path = 5
query 5 3342445   3342445
insert 6 1 -4
insert 2 5 -23
insert 4 5 22
insert 5 5 -3342445
dis: 0 2 -3 3342445 -3342444 -22 4 0 4
-3342444 -3 -22 0 4

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 28ms
memory: 328864kb

input:

6 3
1 5 1
5 5 1
3 1 2 2 3 3
3 5 1 2 1 4
3 3 4 5 4 6

output:

2 5 21 14 18

result:

ok 5 number(s): "2 5 21 14 18"

Test #2:

score: 0
Accepted
time: 12ms
memory: 328276kb

input:

6 3
1 5 1
5 5 1
5 1 2 2 100 3 100 6 1 4
5 1 100 2 4 3 100 5 1 4
2 3 1 5

output:

2 31 43 37 136

result:

ok 5 number(s): "2 31 43 37 136"

Test #3:

score: 0
Accepted
time: 24ms
memory: 328492kb

input:

5 9
278281 70119 511791 834898 25300 63487 609134 236836 394497
835557 287345 579404 879128 636344 306393 569430 152565 47119
2 3 823004250 4
2 1 25427550 3
2 1 15849621 3
2 1 701911826 5
3 5 679672631 3 907176714 2
2 1 817370554 2
2 3 697987914 2
2 4 873900795 2
2 1 814305954 5

output:

817370554 15849621 80811085745 701911826

result:

ok 4 number(s): "817370554 15849621 80811085745 701911826"

Test #4:

score: 0
Accepted
time: 12ms
memory: 329260kb

input:

5 10
436148 103565 528276 212202 680282 92724 609031 560815 80390 406327
546832 581372 731920 348686 791433 98906 112247 118131 361076 724950
4 1 213029090 4 415633732 5 581145231 3
2 4 306227294 2
2 1 713116112 4
2 3 99672714 5
2 3 975143846 1
5 4 249118026 5 689334413 1 597093740 2 553624319 3
3 4...

output:

597093740 765908995 213029090 628662822

result:

ok 4 number(s): "597093740 765908995 213029090 628662822"

Test #5:

score: 0
Accepted
time: 11ms
memory: 329852kb

input:

3 5
696710 837216 390019 431068 960618
589388 829806 692481 154511 282620
2 1 711629163 3
2 1 781784306 3
2 1 686636041 3
2 3 794790206 2
2 1 844212542 2

output:

844212542 686636041

result:

ok 2 number(s): "844212542 686636041"

Test #6:

score: 0
Accepted
time: 15ms
memory: 328844kb

input:

3 8
344877 101098 328614 735002 476606 635558 573861 261083
964379 333960 25186 276560 258996 683650 765559 582374
2 3 838262394 1
2 2 863940316 3
2 2 476918371 3
3 3 320092619 1 400754003 2
3 3 150885055 2 90507792 1
2 3 190275693 2
2 2 600234969 3
2 2 679446528 3

output:

400754003 29224357199

result:

ok 2 number(s): "400754003 29224357199"

Test #7:

score: -100
Wrong Answer
time: 31ms
memory: 328564kb

input:

50 52
895514 29433 851800 887860 340384 95967 506578 666268 850660 602220 717255 242039 34055 752012 248567 170469 505996 823344 143369 390858 112988 892365 15368 617804 351619 557340 788960 990487 283825 272924 24678 130649 341049 980236 558990 254726 682005 963825 953074 603477 706464 340694 23541...

output:

632126151 479346918 492618840 3695787776 22624579200 174047740 416387993526 21429733469 71021529023 203893499 522142321620 977566721 279122223 30345963113 804573598 73397618725 6389037892 224856032596 416404080694 75356833904 69909552850 4504114918 13173874327 1104455938 278587376156 270759151017 22...

result:

wrong answer 9th numbers differ - expected: '15831777447', found: '71021529023'