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 <vector>
#include "messy.h"
#include<bits/stdc++.h>
using namespace std;
bool confirm[300005];
int pp[300005];
void add(int a, int b,int n) { // [a, b)
if(a >= b)return;
int mid = (a + b) / 2;
string temp;
for(int i=0;i<n;i++)temp += '1';
for(int i=a;i<=b;i++)temp[i] = '0';
for(int i=a;i<=mid;i++)
{
temp[i] = '1';
add_element(temp);
// cout<<a<<" "<<b<<" "<<temp<<endl;
temp[i] = '0';
}
add(a,mid,n);
add(mid+1,b,n);
}
bool used[300005];
int go[300005];
void find(int l,int r,int n,vector<int> v)
{
//cout<<"l : "<<l<<" r : "<<r<<endl;
if(l > r)return;
if(l == r)
{
for(int i=0;i<n;i++)used[i] = false;
for(int i=0;i<v.size();i++)used[v[i]] = true;
for(int i=0;i<n;i++)if(used[i] == false)go[l] = i;
return;
}
string temp;
for(int i=0;i<n;i++)temp += '0';
for(int i=0;i<v.size();i++)temp[v[i]] = '1';
vector<int> x; // that means the [l,mid];
vector<int> y; // that means the [mid+1,r]
for(int i=0;i<n;i++)
{
if(temp[i] == '1')continue;
temp[i] = '1';
if(check_element(temp) == true)
{
// cout<<"true"<<endl;
x.push_back(i);
}
else
{
// cout<<"false"<<endl;
y.push_back(i);
}
temp[i] = '0';
}
/*cout<<"l : "<<l<<" r : "<<r<<endl;
for(int i=0;i<v.size();i++)cout<<v[i]<<" ";
cout<<endl;
for(int i=0;i<x.size();i++)cout<<x[i]<<" ";
cout<<endl;
for(int i=0;i<y.size();i++)cout<<y[i]<<" ";
cout<<endl;*/
int mid = (l+r) / 2;
for(int i=0;i<y.size();i++)v.push_back(y[i]);
find(l,mid,n,v);
for(int i=0;i<y.size();i++)v.pop_back();
for(int i=0;i<x.size();i++)v.push_back(x[i]);
find(mid+1,r,n,v);
}
std::vector<int> restore_permutation(int n, int w, int r) {
add(0,n-1,n);
compile_set();
vector<int> vv;
find(0,n-1,n,vv);
/*for(int i=0;i<n;i++)cout<<go[i]<<" ";
cout<<endl;*/
vector<int> ans;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)if(go[j] == i)ans.push_back(j);
}
return ans;
}
Compilation message (stderr)
messy.cpp: In function 'void find(int, int, int, std::vector<int>)':
messy.cpp:32:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i=0;i<v.size();i++)used[v[i]] = true;
| ~^~~~~~~~~
messy.cpp:38:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0;i<v.size();i++)temp[v[i]] = '1';
| ~^~~~~~~~~
messy.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i=0;i<y.size();i++)v.push_back(y[i]);
| ~^~~~~~~~~
messy.cpp:67:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i=0;i<y.size();i++)v.pop_back();
| ~^~~~~~~~~
messy.cpp:68:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i=0;i<x.size();i++)v.push_back(x[i]);
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |