Submission #951029

#TimeUsernameProblemLanguageResultExecution timeMemory
951029qwe1rt1yuiop1Toxic Gene (NOI23_toxic)C++17
58.15 / 100
8 ms604 KiB
#include "toxic.h" using namespace std; #include <bits/stdc++.h> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() mt19937 rng(75329); vector<int> v, p, p_; string ans; int n0; void ac(int x, char c) { assert(ans[x] == '0'); x = p[x]; answer_type(x, c); x = p_[x]; ans[x] = c; } int qry() { for (int &i : v) i = p[i]; int ret = query_sample(v); for (int &i : v) i = p_[i]; return ret; } int qry1(int l, int r) { assert(l <= r); v.clear(); for (int i = l; i <= r; ++i) v.emplace_back(i); return qry(); } void qry2() { int cnt = sz(v) - 1; for (int i = 0; i < cnt; ++i) for (int j = 0; j < ((1 << i) - 1); ++j) v.emplace_back(v[i]); int tmp = sz(v); assert(tmp == (tmp & (-tmp))); int ret = qry(); // --ret; for (int i = 0; i < cnt; ++i) if (ret >> i & 1) ac(v[i], 'S'); else ac(v[i], 'R'); } void determine_type(int n) { p.clear(); for (int i = 1; i <= n; ++i) p.emplace_back(i); shuffle(all(p), rng); p.emplace_back(0); reverse(all(p)); p_.assign(n + 1, 0); for (int i = 1; i <= n; ++i) p_[p[i]] = i; n0 = n; ans.assign(n + 1, '0'); vector<int> t; t.emplace_back(0); int nxt = 1; while (nxt <= n) { int l = nxt, r = min(n, l + 7); if (qry1(l, r) == r - l + 1) { nxt = r + 1; continue; } while (l < r) { int mid = (l + r) >> 1; if (qry1(l, mid) != mid - l + 1) r = mid; else l = mid + 1; } t.emplace_back(l); ac(l, 'T'); nxt = l + 1; } vector<int> r; for (int i = 1; i <= n; ++i) if (ans[i] == '0') r.emplace_back(i); while (!r.empty()) { v.clear(); while (!r.empty() && sz(v) < 8) v.emplace_back(r.back()), r.pop_back(); v.emplace_back(t.back()); qry2(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...