QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#875641#9569. SubwayAndyqian7RE 0ms0kbC++262.5kb2025-01-30 00:21:592025-01-30 00:22:01

Judging History

This is the latest submission verdict.

  • [2025-01-30 00:22:01]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2025-01-30 00:21:59]
  • Submitted

answer

#include <bits/stdc++.h>
#define pii pair<int, int>
#define int long long
#define rep(i, s, e) for (int i = s; i <= e; i++)
using namespace std;
const int N = 4e5 + 10;
int n, k, a[N], b[N], p[N], d[N], belong[N], line[N], t, stp[N], vis[N], dis[N];
pii nxt[N];
vector<int> w[N], v[N];
deque<int> hull[N];
inline double slope(int x, int y)
{
    if (b[line[x]] == b[line[y]])
        return 1e18 * (dis[x] > dis[y]);
    if (dis[x] == dis[y])
        return 1e18 * (b[line[x]] > b[line[y]]);
    return -1.0 * (b[line[x]] - b[line[y]]) / (dis[x] - dis[y]);
}
int cal(int x, int y)
{
    return dis[x] + a[line[y]] * b[line[x]];
}
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> k;
    memset(d, 0x7f, sizeof d);
    rep(i, 1, k) cin >> a[i];
    rep(i, 1, k) cin >> b[i];
    rep(i, 1, k)
    {
        cin >> p[i];
        int w, x;
        rep(j, 1, p[i] - 1)
        {
            cin >> x >> w;
            v[x].push_back(++t);
            belong[t] = x;
            line[t] = i;
            nxt[t] = {t + 1, w};
        }
        cin >> x;
        v[x].push_back(++t);
        belong[t] = x;
        line[t] = i;
    }
    for (int i = 1; i <= n; i++)
    {
        sort(v[i].begin(), v[i].end(), [](int x, int y)
             { return a[line[x]] < a[line[y]]; });
    }
    priority_queue<pii, vector<pii>, greater<pii>> Q;
    for (int x : v[1])
    {
        Q.push({0, x});
    }
    while (Q.size())
    {
        int x = Q.top().second;
        int tmp = Q.top().first;
        Q.pop();
        if (vis[x])
            continue;
        vis[x] = 1;
        dis[x] = tmp;
        d[belong[x]] = min(d[belong[x]], dis[x]);
        Q.pop();
        int station = belong[x];
        auto &hul = hull[station];
        while (hul.size() >= 2 && slope(hul[hul.size() - 2], hul.back() < slope(hul.back(), x)))
            hul.pop_back();
        hul.push_back(x);
        while (stp[station] < v[station].size() && vis[v[station][stp[station]]])
            stp[station]++;
        if (stp[station] < v[station].size())
        {
            int y = v[station][stp[station]];
            while (hul.size() >= 2 && cal(hul[0], y) > cal(hul[1], y))
                hul.pop_front();
            Q.push({cal(hul[0], y), y});
        }
        if (nxt[x].first)
        {
            Q.push({dis[x] + nxt[x].second, nxt[x].first});
        }
    }
    for (int i = 2; i <= n; i++)
    {
        cout << d[i] << " ";
    }
}

详细

Test #1:

score: 0
Runtime Error

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:


result: