# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
994898 |
2024-06-08T08:17:50 Z |
Dzadzo |
Library (JOI18_library) |
C++14 |
|
0 ms |
0 KB |
#include <bits/stdc++.h>
#include "library.h"
#define ll long long
#define pb push_back
#define S second
#define F first
#define pii pair<int,int>
#define vi vector <int>
#define vvi vector <vi>
#define vvvi vector <vvi>
#define vp vector <pii>
#define vvp vector <vp>
#define vb vector <bool>
#define vvb vector <vb>;
#define INF INT_MAX
#define MOD 1000000007
#define MAXN 100000
using namespace std;
map <vi,int >MP;
/*int Query(const vi &v){
if (!MP[v]){
for (int x:v)cout<<x;cout<<"\n";
cin>>MP[v];
}
return MP[v];
}
void Answer(const vi &v){
cout<<"ANS";
for (int x:v)cout<<x<<" ";
}*/
vvi arr;
int N;
int get(int l,int r,int idx1,int idx2){
vi M(N);
for (int i=l;i<=r;i++){
for (int x:arr[i])M[x-1]=1;
}
if(idx1)M[idx1-1]=1;
if(idx2)M[idx2-1]=1;
int cnt=0;
for (int x:M)cnt+=x;
if (cnt==1 || cnt=n)return 1;
if (MP[M])return MP[M];
return MP[M]=Query(M);
}
void Solve(int n){
N=n;
arr.pb({1});
int res=1;
for (int i=2;i<=n;i++){
// cout<<i<<"\n";
int val=get(0,arr.size()-1,i,0);
if (val==res+1){
// cout<<"AQ1\n";
arr.pb({i});
res++;
}else if (val==res){
// cout<<"AQ2\n";
int ind=-1;
for (int bit=9;bit>=0;bit--){
if (ind+(1<<bit)>=arr.size())continue;
if (get(0,ind+(1<<bit),i,0)>get(0,ind+(1<<bit),0,0))ind+=(1<<bit);
}
ind++;//aq aris i
// cout<<ind<<"---"<<arr[ind][0]<<"\n";
if (get(0,-1,arr[ind][0],i)==1){
// cout<<"MARJVNIV\n";
arr[ind].insert(arr[ind].begin(),i);
}else{
// cout<<"MARCXNIV\n";
arr[ind].pb(i);
}
}else if (val==res-1){
// cout<<"AQ3\n";
int ind1=-1;
for (int bit=9;bit>=0;bit--){
if (ind1+(1<<bit)>=arr.size())continue;
if (get(0,ind1+(1<<bit),i,0)>get(0,ind1+(1<<bit),0,0))ind1+=(1<<bit);
}
ind1++;//aq aris i
int ind2=-1;
for (int bit=9;bit>=0;bit--){
if (ind2+(1<<bit)>=arr.size())continue;
if (get(0,ind2+(1<<bit),i,0)>=get(0,ind2+(1<<bit),0,0))ind2+=(1<<bit);
}
ind2++;// ind1-s aertianebs amastan
vi newarr;
if (get(0,-1,arr[ind1][0],i)==1){
// cout<<"MARJVNIV\n";
for (int x:arr[ind2])newarr.pb(x);
if (get(0,-1,arr[ind2][0],i)==1)reverse(newarr.begin(),newarr.end());
newarr.pb(i);
for (int x:arr[ind1])newarr.pb(x);
}else{
// cout<<"MARCXNIV\n";
for (int x:arr[ind1])newarr.pb(x);
if (get(0,-1,arr[ind2][0],i)==2)reverse(arr[ind2].begin(),arr[ind2].end());
newarr.pb(i);
for (int x:arr[ind2])newarr.pb(x);
}
vvi NEWarr;
for (int i=0;i<arr.size();i++){
if (i==ind1 || i==ind2)continue;
NEWarr.pb(arr[i]);
}
NEWarr.pb(newarr);
arr=NEWarr;
res--;
}
}
Answer(arr[0]);
}
/*signed main(){
int c;
cin>>c;
Solve(c);
}*/
Compilation message
library.cpp: In function 'int get(int, int, int, int)':
library.cpp:42:20: error: 'n' was not declared in this scope
42 | if (cnt==1 || cnt=n)return 1;
| ^
library.cpp: In function 'void Solve(int)':
library.cpp:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | if (ind+(1<<bit)>=arr.size())continue;
| ~~~~~~~~~~~~^~~~~~~~~~~~
library.cpp:77:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | if (ind1+(1<<bit)>=arr.size())continue;
| ~~~~~~~~~~~~~^~~~~~~~~~~~
library.cpp:84:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | if (ind2+(1<<bit)>=arr.size())continue;
| ~~~~~~~~~~~~~^~~~~~~~~~~~
library.cpp:103:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for (int i=0;i<arr.size();i++){
| ~^~~~~~~~~~~