QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#730315#6561. Fail Fastahsoltan#WA 2ms10484kbC++202.8kb2024-11-09 19:41:362024-11-09 19:41:38

Judging History

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

  • [2024-11-09 19:41:38]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10484kb
  • [2024-11-09 19:41:36]
  • 提交

answer

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

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#ifdef LOCAL
auto operator<<(auto& o, auto x) -> decltype(x.first, o);
auto operator<<(auto& o, auto x) -> decltype(x.end(), o) {
  o << "{";
  for (int i = 0; auto y : x) o << ", " + !i++ * 2 << y;
  return o << "}";
}
auto operator<<(auto& o, auto x) -> decltype(x.first, o) {
  return o << "(" << x.first << ", " << x.second << ")";
}
void __print(auto... x) { ((cerr << x << " "), ...) << endl; }
#define debug(x...) __print("[" #x "]:", x)
#else
#define debug(...) 2137
#endif

using F = pair<ll, ll>;
bool mn(F a, F b) {
  return (__int128)a.first * b.second < (__int128)b.first * a.second;
}
F dawaj(F a, F b) {
  return mn(a, b) ? b : a;
}

mt19937 rng(2137);
struct Node {
  Node *l = 0, *r = 0;
  F val, mx;
  int c = 1, pr;
  Node(F f = F(0, 1)) : val(f), mx(f), pr(rng()) {}
  void pull();
};

int cnt(Node* n) { return n ? n->c : 0; }
void Node::pull() {
  c = cnt(l) + cnt(r) + 1;
  mx = val;
  if (l) mx = dawaj(mx, l->mx);
  if (r) mx = dawaj(mx, r->mx);
}

pair<Node*, Node*> split(Node* n, F f) {
  if (!n) return {};
  if (mn(f, dawaj(n->val, n->l ? n->mx : F(0, 1)))) {
    auto pa = split(n->l, f);
    n->l = pa.second;
    n->pull();
    return {pa.first, n};
  } else {
    auto pa = split(n->r, f);
    n->r = pa.first;
    n->pull();
    return {n, pa.second};
  }
}
Node* merge(Node* l, Node* r) {
  if (!l || !r) return l ?: r;
  if (l->pr > r->pr) {
    l->r = merge(l->r, r);
    l->pull();
    return l;
  } else {
    r->l = merge(l, r->l);
    r->pull();
    return r;
  }
}

const int N = 100100;
int n;
vi adj[N];
Node nd[N];
vi ans;

void licz(Node* u) {
  if (!u) return;
  licz(u->l);
  ans.push_back(u - nd);
  licz(u->r);
}

Node* dfs(int u) {
  Node* ja = 0;
  for (int v : adj[u]) {
    Node* on = dfs(v);
    ans.clear();
    licz(on);
    debug(v, ans);
    if (cnt(on) > cnt(ja)) swap(on, ja);
    ans.clear();
    licz(on);
    for (int x : ans) nd[x].l = nd[x].r = 0, nd[x].pull();
    Node* lew = 0;
    for (int x : ans) {
      auto [l, r] = split(ja, nd[x].val);
      debug(u, x, cnt(l), cnt(r), nd[x].val);
      lew = merge(merge(lew, l), &nd[x]);
      ja = r;
    }
    ja = merge(lew, ja);
  }
  return merge(&nd[u], ja);
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  n++;
  rep(i, 1, n) {
    int c, d;
    string p;
    cin >> c >> p >> d;
    string pp = p.substr(2);
    while (sz(pp) < 6) pp += '0';
    ll x = stoi(pp);
    nd[i].val = {1ll * c * x, 1000000 - x};
    nd[i].mx = nd[i].val;
    adj[d].push_back(i);
  }
  Node* rt = dfs(0);
  ans.clear();
  licz(rt);
  rep(i, 1, sz(ans)) cout << ans[i] << " \n"[i == n - 1];
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 9548kb

input:

4
100 0.5 0
200 0.1 1
10 0.5 2
10 0.9 0

output:

4 1 2 3

result:

ok correct

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 10484kb

input:

4
84 0.716 0
91 0.115 0
19 0.640 1
103 0.455 0

output:

2 4 1 3

result:

wrong answer your plan is not optimal