QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#729505#9569. Subwayucup-team3931#WA 3ms48888kbC++173.9kb2024-11-09 17:14:232024-11-09 17:14:24

Judging History

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

  • [2024-11-09 17:14:24]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:48888kb
  • [2024-11-09 17:14:23]
  • 提交

answer

#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define sz(v) ((int) (v).size())
#define me(f, x) memset(f, x, sizeof(f))
#define mc(f, g) memcpy(f, g, sizeof(g))
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;

using vi = vector<int>;
#endif

using info = pair<LL, int>;

constexpr int N = 4e5 + 9;
constexpr int M = 1e6;
int n, m, a[N], b[N];
int cnt, id[N], to[N], w[N], c[N];
vi lis[N];

LL dis[N];

int rt[N], tot;
info f[N];
int seg[N], lp[N], ls[N], rs[N];
set<int> idx[N];

int eval (int x, int y) {
  return (LL)a[id[y]] * x + dis[y];
}

void up (int p) {
  f[p] = min(f[ls[p]], f[rs[p]]);
  int x = lp[ls[p]], y = lp[rs[p]];
  lp[p] = b[id[x]] < b[id[y]] ? x : y;
  if (lp[p] && seg[p]) {
    f[p] = min(f[p], info(eval(b[id[lp[p]]], seg[p]), lp[p]));
  }
}

void ins (int x, int l, int r, int &p, int y) {
  if (!p) {
    p = ++tot;
  }
  if (l == r) {
    idx[p].insert(y);
    lp[p] = *idx[p].begin();
    f[p] = f[0];
    return;
  }
  int md = (l + r) >> 1;
  x <= md ? ins(x, l, md, ls[p], y) : ins(x, md + 1, r, rs[p], y);
  up(p);
}

void era (int x, int l, int r, int &p, int y) {
  if (l == r) {
    idx[p].erase(y);
    lp[p] = idx[p].empty() ? 0 : *idx[p].begin();
    f[p] = seg[p] && lp[p] ? info(eval(b[id[lp[p]]], seg[p]), lp[p]) : f[0];
    return;
  }
  int md = (l + r) >> 1;
  x <= md ? era(x, l, md, ls[p], y) : era(x, md + 1, r, rs[p], y);
  up(p);
}

void upd (int l, int r, int p, int x) {
  if (!p) {
    return;
  }
  if (!seg[p] || (eval(l, seg[p]) >= eval(l, x) && eval(r, seg[p]) >= eval(r, x))) {
    seg[p] = x;
    up(p);
    return;
  }
  if (eval(l, seg[p]) <= eval(l, x) && eval(r, seg[p]) <= eval(r, x)) {
    return;
  }
  int md = (l + r) >> 1;
  upd(l, md, ls[p], x);
  upd(md + 1, r, rs[p], x);
  up(p);
}

bool vis[N];

set<info> atom;
priority_queue<info, vector<info>, greater<info>> q;

void add (int x) {
  vis[x] = 1;
  if (to[x] != -1) {
    if (dis[to[x]] > dis[x] + w[x]) {
      dis[to[x]] = dis[x] + w[x];
      q.emplace(dis[to[x]], to[x]);
    }
  }
  int o = c[x];
  atom.erase(info(f[rt[o]].first, o));
  upd(1, M, rt[o], x);
  atom.emplace(f[rt[o]].first, o);
}

int main () {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  L (i, 1, m) {
    cin >> b[i];
  }
  L (i, 1, m) {
    cin >> a[i];
  }
  int _n = 0;
  L (i, 1, m) {
    int k, s;
    cin >> k >> s;
    _n += k;
    ++cnt;
    id[cnt] = i;
    c[cnt] = s;
    lis[s].eb(cnt);
    L (j, 1, k - 1) {
      ++cnt;
      to[cnt - 1] = cnt;
      int x;
      cin >> w[cnt - 1] >> x;
      id[cnt] = i;
      c[cnt] = x;
      lis[x].eb(cnt);
    }
    to[cnt] = -1;
  }
  b[0] = 0x3f3f3f3f;
  f[0].first = 0x3f3f3f3f3f3f3f3f;
  L (i, 1, n) {
    for (int x : lis[i]) {
      ins(b[id[x]], 1, M, rt[i], x);
    }
    atom.emplace(f[rt[i]].first, i);
  }
  me(dis, 0x3f);
  for (int x : lis[1]) {
    dis[x] = 0;
    q.emplace(0, x);
  }
  L (i, 1, _n) {
    int u;
    if (sz(q) && atom.begin() -> first > q.top().first) {
      u = q.top().second;
      q.pop();
      if (vis[u]) {
        --i;
        continue;
      }
    } else {
      int o = atom.begin() -> second;
      u = f[rt[o]].second;
      dis[u] = min(dis[u], atom.begin() -> first);
      atom.erase(atom.begin());
      era(b[id[u]], 1, M, rt[o], u);
      atom.emplace(f[rt[o]].first, o);
      if (vis[u]) {
        --i;
        continue;
      }
    }
    add(u);
  }
  L (i, 2, n) {
    LL ans = 0x3f3f3f3f3f3f3f3f;
    for (int x : lis[i]) {
      ans = min(ans, dis[x]);
    }
    cout << ans << " \n"[i == n];
  }
}
// I love WHQ!

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: -100
Wrong Answer
time: 0ms
memory: 46236kb

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:

-1676420531 -1955783103 -1132778853 -721885078

result:

wrong answer 1st numbers differ - expected: '817370554', found: '-1676420531'