QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#770014#7905. Ticket to RideguosounWA 4ms3624kbC++171.8kb2024-11-21 20:17:082024-11-21 20:17:08

Judging History

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

  • [2024-11-21 20:17:08]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3624kb
  • [2024-11-21 20:17:08]
  • 提交

answer

#include <bits/stdc++.h>
using ll = long long;

struct hope {
  int bk;
  ll bkv;
  std::vector<int> fa, nx;
  std::vector<ll> d;
  int find(int u) {
    while (fa[u] != u) u = fa[u] = fa[fa[u]];
    return u;
  }
  hope(ll x) { bk = 0, bkv = x, fa = {0}, nx = {0}, d = {0}; }
  void push_back(ll v) {
    int idx = fa.size();
    fa.push_back(idx);
    if (bkv >= v) {
      fa[idx] = idx - 1;
      nx.push_back(0), d.push_back(0);
      return;
    }
    nx[bk] = idx, d[bk] = v - bkv, bk = idx, bkv = v;
    nx.push_back(idx), d.push_back(0);
  }
  void add(int p, ll v) {
    assert(p < (int)fa.size());
    p = find(p);
    if (p == bk) {
      bkv += v;
      return;
    }
    d[p] -= v;
    while (d[p] <= 0) {
      if (nx[p] == nx[nx[p]]) {
        bkv = bkv - d[p];
        bk = p;
        fa[nx[p]] = nx[p] - 1;
        d[p] = 0, nx[p] = p;
        break;
      }
      d[p] += d[nx[p]];
      fa[nx[p]] = nx[p] - 1;
      nx[p] = nx[nx[p]];
    }
  }
  ll query() { return bkv; }
};


void mian() {
  int n, m;
  std::cin >> n >> m, ++n;
  std::vector<std::vector<std::pair<int, int>>> lf(n + 1);
  while (m--) {
    int l, r, v;
    std::cin >> l >> r >> v;
    lf[r + 1].push_back({l + 1, v});
  }
  std::vector<ll> dp(n + 1, -1e18);
  dp[0] = 0;
  std::vector<ll> ans;
  for (int i = 1; i < n; i++) {
    auto tmp = dp;
    dp.assign(n + 1, -1e18);
    hope h(tmp[0]);
    for (int j = 1; j <= n; j++) {
      for (auto [l, v] : lf[j]) {
        h.add(l - 1, v);
      }
      dp[j] = h.query();
      h.push_back(tmp[j]);
    }
    ans.push_back(dp.back());
  }
  std::reverse(ans.begin(), ans.end());
  for (int i : ans) std::cout << i << ' ';
  std::cout << '\n';
}
int main() { 
  std::cin.tie(0)->sync_with_stdio(0); 
  int t;
  std::cin >> t;
  while (t--) mian();
}
/*
1 2
4 4

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4 3
0 2 3
3 4 2
0 3 1
3 1
1 3 100

output:

2 3 5 6 
0 100 100 

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 4ms
memory: 3608kb

input:

1000
2 9
0 2 396628655
1 2 268792718
0 2 16843338
1 2 717268783
0 1 693319712
0 1 856168102
1 2 407246545
1 2 527268921
0 1 536134606
6 2
2 5 451394766
0 5 695984050
9 7
0 6 73936815
2 9 505041862
4 5 223718927
5 7 179262261
3 5 449258178
0 5 493128
0 3 994723920
6 6
3 5 433389755
2 4 773727734
4 5 ...

output:

2085622420 124704084 
0 0 451394766 451394766 1147378816 1147378816 
223718927 672977105 994723920 1218442847 1668194153 1742130968 1921393229 1921393229 -1868532205 
127680943 773727734 1334798432 -2067510903 -1619322945 -1619322945 
976357580 1594205360 2103791342 -1573328174 -1053392887 -35837921...

result:

wrong answer 1st lines differ - expected: '2085622420 4419671380', found: '2085622420 124704084 '