#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(170306);
void determine_type(ll n)
{
vector <char> ans(n+1, 0);
vector <ll> idx(n);
iota(idx.begin(), idx.end(), 1);
shuffle(idx.begin(), idx.end(), rng);
ll len=8, toxic=0, cnt=30;
auto queryran=[&](ll l, ll r)
{
vector <ll> ask;
for (ll i=l; i<=r; i++)
ask.pb(idx[i]);
return query_sample(ask);
};
vector <ll> ask1;
while (sz(idx) && cnt)
{
vector <ll> left;
for (ll i=0; i<8 && sz(idx); i++)
left.pb(idx.back()), idx.pop_back();
vector <ll> ask;
for (ll j=0; j<sz(left); j++)
for (ll k=0; k<1<<j; k++)
ask.pb(left[j]);
ll x=query_sample(ask);
if (x==ask.size())
{
for (ll i:left) ask1.pb(i);
continue;
}
vector <ll> left1;
for (ll j=0; j<sz(left); j++)
{
if (x&1<<j) ans[left[j]]='S';
else left1.pb(left[j]);
}
ll p=0, en=sz(left1)-1;
auto queryran=[&](ll l, ll r)
{
vector <ll> ask;
for (ll i=l; i<=r; i++)
ask.pb(left1[i]);
vector <ll> id;
for (ll k=0; k<len; k++)
{
if (!sz(ask1)) break;
id.pb(ask1.back()), ask1.pop_back();
for (ll h=0; h<1<<k; h++)
ask.pb(id.back());
}
ll x=query_sample(ask);
if (x==sz(ask))
{
for (ll i:id) ask1.pb(i);
return true;
}
for (ll i=0; i<sz(id); i++)
{
if (x&1<<i) ans[id[i]]='S';
else ans[id[i]]='R';
}
return false;
};
ll lo=0, hi=en;
while (hi>lo)
{
ll mid=(lo+hi)/2;
bool res=queryran(lo, mid);
if (res) lo=mid+1;
else hi=mid;
}
ans[left1[lo]]='T', cnt--, toxic=left1[lo];
for (ll j=0; j<lo; j++) ans[left1[j]]='R';
for (ll j=lo+1; j<sz(left1); j++) idx.pb(left1[j]);
}
idx.clear();
for (ll i=1; i<=n; i++)
if (!ans[i]) idx.pb(i);
shuffle(idx.begin(), idx.end(), rng);
for (ll i=0; i<sz(idx); i+=len)
{
vector <ll> ask; ask.pb(toxic);
for (ll j=i; j<sz(idx) && j<i+len; j++)
for (ll k=0; k<1<<(j-i); k++)
ask.pb(idx[j]);
ll x=query_sample(ask);
for (ll j=i; j<sz(idx) && j<i+len; j++)
{
if (x&1<<(j-i)) ans[idx[j]]='S';
else ans[idx[j]]='R';
}
}
for (ll i=1; i<=n; i++)
answer_type(i, ans[i]);
}
Compilation message
toxic.cpp: In function 'void determine_type(int)':
toxic.cpp:39:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if (x==ask.size())
| ~^~~~~~~~~~~~
toxic.cpp:50:12: warning: unused variable 'p' [-Wunused-variable]
50 | ll p=0, en=sz(left1)-1;
| ^
toxic.cpp:21:10: warning: variable 'queryran' set but not used [-Wunused-but-set-variable]
21 | auto queryran=[&](ll l, ll r)
| ^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
9 ms |
516 KB |
Output is correct |
3 |
Correct |
9 ms |
512 KB |
Output is correct |
4 |
Correct |
10 ms |
348 KB |
Output is correct |
5 |
Correct |
10 ms |
344 KB |
Output is correct |
6 |
Correct |
11 ms |
512 KB |
Output is correct |
7 |
Correct |
10 ms |
348 KB |
Output is correct |
8 |
Correct |
10 ms |
508 KB |
Output is correct |
9 |
Correct |
11 ms |
348 KB |
Output is correct |
10 |
Correct |
10 ms |
508 KB |
Output is correct |
11 |
Correct |
8 ms |
348 KB |
Output is correct |
12 |
Correct |
10 ms |
348 KB |
Output is correct |
13 |
Correct |
10 ms |
508 KB |
Output is correct |
14 |
Correct |
8 ms |
348 KB |
Output is correct |
15 |
Correct |
14 ms |
348 KB |
Output is correct |
16 |
Correct |
13 ms |
348 KB |
Output is correct |
17 |
Correct |
10 ms |
348 KB |
Output is correct |
18 |
Correct |
10 ms |
348 KB |
Output is correct |
19 |
Correct |
10 ms |
348 KB |
Output is correct |
20 |
Correct |
9 ms |
348 KB |
Output is correct |
21 |
Correct |
8 ms |
348 KB |
Output is correct |
22 |
Correct |
7 ms |
348 KB |
Output is correct |
23 |
Correct |
6 ms |
348 KB |
Output is correct |
24 |
Correct |
10 ms |
508 KB |
Output is correct |
25 |
Correct |
10 ms |
348 KB |
Output is correct |
26 |
Correct |
10 ms |
344 KB |
Output is correct |
27 |
Correct |
11 ms |
348 KB |
Output is correct |
28 |
Correct |
8 ms |
348 KB |
Output is correct |
29 |
Correct |
10 ms |
348 KB |
Output is correct |
30 |
Partially correct |
10 ms |
508 KB |
Partially correct |
31 |
Correct |
10 ms |
348 KB |
Output is correct |
32 |
Correct |
9 ms |
512 KB |
Output is correct |
33 |
Correct |
8 ms |
512 KB |
Output is correct |
34 |
Correct |
10 ms |
348 KB |
Output is correct |
35 |
Correct |
10 ms |
348 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |