This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include "library.h"
#include<bits/stdc++.h>
using namespace std;
//#define int long long
//#define endl '\n'
void Solve(int n){
vector<vector<int>> inter;
vector<int> m(n,0);
int input;
for(int i=0;i<n;i++){
m[i]=1;
input=Query(m);
if(input!=i+1){
break;
}
inter.push_back({i});
}
for(int k=inter.size();k<n;k++){
int low=0,high=inter.size()-1;
low--,high++;
while(high-low>1){
int mid=((high-low)>>1)+low;
fill(m.begin(),m.end(),0);
m[k]=1;
for(int i=0;i<=mid;i++){
for(int x:inter[i]){
m[x]=1;
}
}
input=Query(m);
if(input<mid+2){
high=mid;
}
else{
low=mid;
}
}
if(high==inter.size()){
inter.push_back({k});
continue;
}
fill(m.begin(),m.end(),0);
m[k]=1,m[inter[high][0]]=1;
input=Query(m);
if(input==1){
inter[high].insert(inter[high].begin(),k);
}
else{
inter[high].push_back(k);
}
int l=high;
if(l<inter.size()-1){
low=l+1,high=inter.size()-1;
low--,high++;
while(high-low>1){
int mid=((high-low)>>1)+low;
fill(m.begin(),m.end(),0);
m[k]=1;
for(int i=l+1;i<=mid;i++){
for(int x:inter[i]){
m[x]=1;
}
}
input=Query(m);
if(input<mid-l+1){
high=mid;
}
else{
low=mid;
}
}
if(high<inter.size()){
fill(m.begin(),m.end(),0);
m[k]=1;
m[inter[high][0]]=1;
input=Query(m);
vector<int> temp;
if(inter[l][0]==k){
if(input==1){
for(int i=inter[high].size()-1;i>=0;i--){
temp.push_back(inter[high][i]);
}
for(int x:inter[l]){
temp.push_back(x);
}
}
else{
for(int x:inter[high]){
temp.push_back(x);
}
for(int x:inter[l]){
temp.push_back(x);
}
}
}
else{
if(input==1){
for(int x:inter[l]){
temp.push_back(x);
}
for(int x:inter[high]){
temp.push_back(x);
}
}
else{
for(int x:inter[l]){
temp.push_back(x);
}
for(int i=inter[high].size()-1;i>=0;i--){
temp.push_back(inter[high][i]);
}
}
}
inter[high]=temp;
auto it=inter.begin()+l;
inter.erase(it);
}
}
}
vector<int> ans=inter[0];
for(int i=0;i<ans.size();i++){
ans[i]++;
}
Answer(ans);
}
Compilation message (stderr)
library.cpp: In function 'void Solve(int)':
library.cpp:40:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if(high==inter.size()){
| ~~~~^~~~~~~~~~~~~~
library.cpp:54:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | if(l<inter.size()-1){
| ~^~~~~~~~~~~~~~~
library.cpp:74:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | if(high<inter.size()){
| ~~~~^~~~~~~~~~~~~
library.cpp:123:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
123 | for(int i=0;i<ans.size();i++){
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |