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 "monster.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
map<pair<int,int>,int>mp;
bool query(int a, int b) {
if(mp.find({a, b})!=mp.end()) return mp[{a, b}];
if(Query(a, b)) {
mp[{a, b}]=1;
mp[{b, a}]=0;
} else {
mp[{b, a}]=1;
mp[{a, b}]=0;
}
return mp[{a, b}];
}
bool pyt(int a, int b) {
if(abs(a-b)==1) return a<b;
return a>b;
}
vector<int>cd(vector<int>T) {
if(T.size()==1) return T;
vector<int>A, B;
rep(i, T.size()/2) A.pb(T[i]);
for(int i=T.size()/2; i<T.size(); ++i) B.pb(T[i]);
A=cd(A);
B=cd(B);
int l1=0, l2=0;
vector<int>P;
while(l1<A.size() && l2<B.size()) {
if(query(A[l1], B[l2])==false) P.pb(A[l1++]);
else P.pb(B[l2++]);
}
while(l1<A.size()) P.pb(A[l1++]);
while(l2<B.size()) P.pb(B[l2++]);
return P;
}
vector<int>rev(vector<int>T) {
int n=T.size();
rep(i, n) {
int x=n;
for(int j=i+2; j<n; ++j) {
if(query(T[j-2], T[j])==false) {
x=j;
break;
}
}
reverse(T.begin()+i, T.begin()+x);
i=x-1;
}
return T;
}
vector<int>Solve(int n) {
vector<int>T(n);
rep(i, n) T[i]=i;
T=cd(T);
vector<int>A, B, C, D;
rep(i, n-1) A.pb(T[i+1]);
rep(i, n-1) B.pb(T[i]);
rep(i, n-2) C.pb(T[i+1]);
rep(i, n) D.pb(T[i]);
A=rev(A);
B=rev(B);
C=rev(C);
D=rev(D);
vector<int>Ap(n), Bp(n), Cp(n), Dp(n);
rep(i, n-1) Ap[A[i]]=i+1;
rep(i, n-1) Bp[B[i]]=i;
Bp[T[n-1]]=n-1;
rep(i, n-2) Cp[C[i]]=i+1;
Cp[T[n-1]]=n-1;
rep(i, n) Dp[D[i]]=i;
if(query(T[0], T[2])==pyt(Ap[T[0]], Ap[T[2]])) return Ap;
if(query(T[n-3], T[n-1])==pyt(Bp[T[n-3]], Bp[T[n-1]])) return Bp;
if(query(T[0], T[2])==pyt(Cp[T[0]], Cp[T[2]]) && query(T[n-3], T[n-1])==pyt(Cp[T[n-3]], Cp[T[n-1]])) return Cp;
return Dp;
}
Compilation message (stderr)
monster.cpp: In function 'std::vector<int> cd(std::vector<int>)':
monster.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
monster.cpp:28:3: note: in expansion of macro 'rep'
28 | rep(i, T.size()/2) A.pb(T[i]);
| ^~~
monster.cpp:29:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=T.size()/2; i<T.size(); ++i) B.pb(T[i]);
| ~^~~~~~~~~
monster.cpp:34:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | while(l1<A.size() && l2<B.size()) {
| ~~^~~~~~~~~
monster.cpp:34:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | while(l1<A.size() && l2<B.size()) {
| ~~^~~~~~~~~
monster.cpp:38:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | while(l1<A.size()) P.pb(A[l1++]);
| ~~^~~~~~~~~
monster.cpp:39:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | while(l2<B.size()) P.pb(B[l2++]);
| ~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |