Submission #886216

#TimeUsernameProblemLanguageResultExecution timeMemory
886216vjudge1Toxic Gene (NOI23_toxic)C++17
45.74 / 100
12 ms544 KiB
#include "toxic.h" #include <bits/stdc++.h> using namespace std; template<typename A, typename B> string to_string(pair<A, B>); string to_string(string S) { return '"' + S + '"'; } string to_string(const char* c) { return to_string(string(c)); } string to_string(bool b) { return (b ? "true" : "false"); } template<size_t T> string to_string(bitset<T> bs) { return bs.to_string(); } string to_string(vector<bool> v) { string res = "{"; for (int i = 0; i < int(v.size()); ++i) { if (int(res.size()) > 1) { res += ", "; } res += to_string(v[i]); } return res + "}"; } template<typename T> string to_string(T v) { string res = "{"; for (auto e : v) { if (int(res.size()) > 1) { res += ", "; } res += to_string(e); } return res + "}"; } template<typename A, typename B> string to_string(pair<A, B> p) { return '(' + to_string(p.first) + ", " + to_string(p.second) + ')'; } void debug_out() { cerr << endl; } template<typename H, typename... T> void debug_out(H head, T... tail) { cerr << " " << to_string(head); debug_out(tail...); } #ifdef DEBUG #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) void(37) #endif mt19937 rng(chrono::steady_clock().now().time_since_epoch().count()); constexpr int B = 8; void determine_type(int N){ vector<int> shuf(N); iota(shuf.begin(), shuf.end(), 1); shuffle(shuf.begin(), shuf.end(), rng); debug(shuf); vector<bool> t(N); auto Q = [&](vector<int> ask) { vector<int> r; for (auto x : ask) { r.push_back(shuf[x]); } return query_sample(r); }; auto Get = [&](int l, int r) { vector<int> ask(r - l + 1); iota(ask.begin(), ask.end(), l); return (Q(ask) != (r - l + 1)); }; auto Answer = [&](int x, char T) { answer_type(shuf[x], T); }; for (int i = 0, r; i < N; i = r) { r = min(N, i + B); int low = i; while (low < r && Get(low, r - 1)) { int high = r - 1; while (low < high) { int mid = (low + high) >> 1; if (Get(low, mid)) { high = mid; } else { low = mid + 1; } } debug(low); t[low] = true; low += 1; } } //debug(t); int toxic = int(max_element(t.begin(), t.end()) - t.begin()); vector<int> non; for (int i = 0; i < N; ++i) { if (!t[i]) { non.push_back(i); } } int s = int(non.size()); int jump = 8; vector<bool> strong(N); for (int i = 0, r; i < s; i = r) { r = min(s, i + jump); vector<int> ask = {toxic}; for (int j = i, sz = 1; j < r; ++j, sz *= 2) { for (int k = 0; k < sz; ++k) { ask.push_back(non[j]); } } debug(ask); int res = Q(ask); debug(ask, res); for (int j = i, b = 0; j < r; ++j, ++b) { if ((res >> b) % 2) { strong[non[j]] = true; } } } for (int i = 0; i < N; ++i) { if (strong[i]) { Answer(i, 'S'); } else if (t[i]) { Answer(i, 'T'); } else { Answer(i, 'R'); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...