Submission #940951

#TimeUsernameProblemLanguageResultExecution timeMemory
940951Tuanlinh123Toxic Gene (NOI23_toxic)C++17
44.19 / 100
6 ms600 KiB
#include "toxic.h" #include<bits/stdc++.h> #define ll int #define pll pair<ll, ll> #define pb push_back #define mp make_pair #define fi first #define se second #define ld long double #define sz(a) ((ll)(a).size()) using namespace std; mt19937_64 rng(11092001); void determine_type(ll n) { ll lo=1, hi=n; auto queryrange=[&](ll l, ll r) { vector <ll> ask(r-l+1); iota(ask.begin(), ask.end(), l); return query_sample(ask); }; while (hi>lo) { ll mid=(lo+hi)/2; if (queryrange(lo, mid)==mid-lo+1) lo=mid+1; else hi=mid; } vector <char> ans(n+1, 0); ans[lo]='T'; ll sum=queryrange(1, n); for (ll i=1; i<=n; i+=8) { if (!sum) break; vector <ll> ask; ask.pb(lo); for (ll j=i; j<=n && j<i+8; j++) for (ll k=0; k<1<<(j-i); k++) ask.pb(j); ll x=query_sample(ask); for (ll j=i; j<=n && j<i+8; j++) if (x&1<<(j-i)) ans[j]='S', sum--; } vector <ll> idx; for (ll i=1; i<=n; i++) if (!ans[i]) idx.pb(i); shuffle(idx.begin(), idx.end(), rng); auto queryran=[&](ll l, ll r) { vector <ll> ask; for (ll i=l; i<r; i++) ask.pb(idx[i]); return query_sample(ask); }; ll len=8; for (ll i=0; i<sz(idx); i+=len) { ll p=i, en=min(sz(idx), i+len); while (1) { if (p==en) break; if (queryran(p, en)) break; ll lo=p, hi=en-1; while (hi>lo) { ll mid=(lo+hi)/2; if (queryran(p, mid+1)) lo=mid+1; else hi=mid; } ans[idx[lo]]='T', p=lo+1; } } for (ll i=1; i<=n; i++) { if (ans[i]==0) answer_type(i, 'R'); else answer_type(i, ans[i]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...