// ~ Be Name Khoda ~ //
#include "monster.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int maxn = 1e6 + 10;
const int maxn5 = 1e3 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e18;
namespace {
int a[maxn5], cnt[maxn5], done[maxn5][maxn5], mx[maxn5];
vector <int> av;
bool assk(int a, int b){
if(done[a][b] == -1){
done[a][b] = Query(a, b);
done[b][a] = done[a][b] ^ 1;
}
return done[a][b];
}
void inser(int id, int val){
vector <int> tmp;
for(int i = 0; i < av.size(); i++){
if(tmp.size() == id)
tmp.pb(val);
tmp.pb(av[i]);
}
if(tmp.size() == id)
tmp.pb(val);
av.clear();
for(auto u : tmp)
av.pb(u);
}
bool cmp(int i, int j){return cnt[i] < cnt[j] || (cnt[i] == cnt[j] && assk(i, j));}
} // namespace
std::vector<int> Solve(int n) {
std::vector<int> ret(n);
memset(done, -1, sizeof done);
if(n < 10){
for(int i = 1; i < n; i++){
int lo = -1, hi = i;
while(hi - lo > 1){
int mid = (lo + hi) >> 1;
if(assk(a[mid], i))
hi = mid;
else
lo = mid;
}
cnt[i] = lo + 1;
for(int j = hi; j < i; j++)
cnt[a[j]]++;
for(int j = max(0, lo - 3); j < lo; j++) if(!assk(i, a[j])){
cnt[a[j]]++;
cnt[i]--;
////cout << "ha? " << i << ' ' << j << ' ' << a[j] << endl;
}
for(int j = hi + 1; j < min(i, hi + 4); j++) if(assk(i, a[j])){
cnt[a[j]]--;
cnt[i]++;
}
////cout << "* " << i << ' ' << lo << ' ' << hi << ' ' << cnt[i] << ' ' << cnt[0] << endl;
a[i] = i;
sort(a, a + i + 1, cmp);
}
/*
for(int i = 0; i < n; i++)
//cout << a[i] << ' ' << cnt[a[i]] << endl;
//cout << endl;
//*/
for (int i = 0; i < n; i++)
ret[a[i]] = i;
return ret;
}
av.pb(0);
for(int i = 1; i < n; i++){
int lo = -1, hi = av.size();
while(hi - lo > 1){
int mid = (lo + hi) >> 1;
if(assk(av[mid], i))
hi = mid;
else
lo = mid;
////cout << "hmm " << i << ' ' << lo << ' ' << hi << endl;
}
inser(hi, i);
}
/*
for(auto u : av)
cout << u << ' ';
cout << endl;
//*/
for(int i = 1; i < n; i++)
assert(assk(av[i], av[i - 1]));
int id = 2;
while(id < n && assk(av[0], av[id]))
id++;
bool was2 = false, was3 = false;
int mxid = 0;
mx[0] = true;
if(id < n){
if(id >= 4){
if(!assk(av[1], av[id - 1]))
id--;
}
else if(id == 2){
was2 = true;
}
else{
was3 = true;
}
}
int st = 0;
if(was3){
mxid = 3;
was3 = false;
id = 5;
while(id < n && assk(av[3], av[id]))
id++;
if(id >= 7){
if(!assk(av[4], av[id - 1]))
id--;
if(!assk(av[0], av[id - 1])){
mx[0] = mx[2] = true;
}
}
else if(id == 5){
st = 3;
was2 = true;
was3 = true;
}
else{
int st = 3;
if(assk(av[0], av[st + 0])){
mx[0] = mx[3] = mx[4] = true;
mxid = 4;
}
else if(assk(av[0], av[st + 1])){
mx[0] = mx[3] = mx[5] = true;
mxid = 5;
}
else if(assk(av[0], av[st + 2])){
mx[0] = mx[3] = true;
mxid = 3;
}
else if(assk(av[1], av[st + 0])){
mx[0] = mx[1] = mx[3] = mx[4] = true;
mxid = 4;
}
else if(assk(av[1], av[st + 1])){
mx[0] = mx[1] = mx[3] = mx[5] = true;
mxid = 5;
}
else if(assk(av[1], av[st + 2])){
mx[0] = mx[1] = mx[3] = true;
mxid = 3;
}
else if(assk(av[2], av[st + 0])){
mx[0] = mx[2] = mx[3] = mx[4] = true;
mxid = 4;
}
else if(assk(av[2], av[st + 1])){
mx[0] = mx[2] = mx[3] = mx[5] = true;
mxid = 5;
}
else{ // if(assk(av[1], av[st + 2]))
mx[0] = mx[2] = mx[3] = true;
mxid = 3;
}
}
}
mx[id] = true;
int last = id;
id++;
while(id < n){
//cout << "**** " << id << ' ' << mxid << endl;
if(assk(av[mxid], av[id])){
if(was2){
//cout << "here " << was3 << ' ' << st << endl;
if(assk(av[1 + st], av[id])){ // 1 x ..
mx[st] = mx[1 + st] = true;
mx[st + 2] = false;
mxid = st + 1;
}
else{ // 2 1 x ..
mx[st] = mx[2 + st] = true;
mx[st + 1] = false;
mxid = st + 2;
}
//cout << mx[st] << ' ' << mx[st + 1] << ' ' << mx[st + 2] << endl;
was2 = false;
if(was3){
if(mx[st + 1]){
if(assk(av[0], av[st]))
mx[0] = true;
else{
mx[0] = mx[1] = true;
}
}
else{
if(assk(av[0], av[4]))
mx[0] = true;
else if(assk(av[1], av[4]))
mx[0] = mx[1] = true;
else
mx[0] = mx[2] = true;
}
was3 = false;
}
}
else{
mxid = last;
}
//cout << "ha? " << id << ' ' << last << endl;
last = id + 1;
mx[id + 1] = true;
id += 2;
continue;
}
id++;
}
last = 0;
for(int i = 1; i < n; i++){
if(mx[i]){
//cout << i << ' ' << mx[i] << endl;
reverse(av.begin() + last, av.begin() + i);
last = i;
}
}
reverse(av.begin() + last, av.end());
for(int i = 0; i < n; i++)
ret[av[i]] = i;
return ret;
}
Compilation message
monster.cpp: In function 'void {anonymous}::inser(int, int)':
monster.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i = 0; i < av.size(); i++){
| ~~^~~~~~~~~~~
monster.cpp:42:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
42 | if(tmp.size() == id)
| ~~~~~~~~~~~^~~~~
monster.cpp:46:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
46 | if(tmp.size() == id)
| ~~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4176 KB |
Output is correct |
2 |
Correct |
2 ms |
4300 KB |
Output is correct |
3 |
Correct |
2 ms |
4176 KB |
Output is correct |
4 |
Correct |
2 ms |
4304 KB |
Output is correct |
5 |
Correct |
2 ms |
4176 KB |
Output is correct |
6 |
Correct |
2 ms |
4304 KB |
Output is correct |
7 |
Correct |
2 ms |
4300 KB |
Output is correct |
8 |
Correct |
2 ms |
4176 KB |
Output is correct |
9 |
Correct |
2 ms |
4176 KB |
Output is correct |
10 |
Correct |
2 ms |
4176 KB |
Output is correct |
11 |
Correct |
2 ms |
4176 KB |
Output is correct |
12 |
Correct |
2 ms |
4176 KB |
Output is correct |
13 |
Correct |
2 ms |
4176 KB |
Output is correct |
14 |
Correct |
2 ms |
4176 KB |
Output is correct |
15 |
Correct |
2 ms |
4176 KB |
Output is correct |
16 |
Incorrect |
8 ms |
4304 KB |
Wrong Answer [3] |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4176 KB |
Output is correct |
2 |
Correct |
2 ms |
4300 KB |
Output is correct |
3 |
Correct |
2 ms |
4176 KB |
Output is correct |
4 |
Correct |
2 ms |
4304 KB |
Output is correct |
5 |
Correct |
2 ms |
4176 KB |
Output is correct |
6 |
Correct |
2 ms |
4304 KB |
Output is correct |
7 |
Correct |
2 ms |
4300 KB |
Output is correct |
8 |
Correct |
2 ms |
4176 KB |
Output is correct |
9 |
Correct |
2 ms |
4176 KB |
Output is correct |
10 |
Correct |
2 ms |
4176 KB |
Output is correct |
11 |
Correct |
2 ms |
4176 KB |
Output is correct |
12 |
Correct |
2 ms |
4176 KB |
Output is correct |
13 |
Correct |
2 ms |
4176 KB |
Output is correct |
14 |
Correct |
2 ms |
4176 KB |
Output is correct |
15 |
Correct |
2 ms |
4176 KB |
Output is correct |
16 |
Incorrect |
8 ms |
4304 KB |
Wrong Answer [3] |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
81 ms |
4288 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |