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 <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
/*
refs:
https://codeforces.com/blog/entry/91295?#comment-801014
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "monster.h"
namespace {
bool example_variable;
} // namespace
std::vector<int> Solve(int n) {
// std::vector<int> T(N);
// example_variable = Query(0, 1);
// for (int i = 0; i < N; i++) T[i] = (N - 1) - i;
// return T;
vector<int> a(n);
iota(all(a),0);
map<pii,bool> mp;
auto f = [&](int i, int j){
if(mp.count({i,j})) return mp[{i,j}];
bool res = Query(i,j);
mp[{i,j}] = res, mp[{j,i}] = res^1;
return res;
};
auto cmp = [&](int i, int j){
return !f(i,j);
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
shuffle(all(a),rng);
stable_sort(all(a),cmp);
auto win_count = [&](int i){
int ans = 0;
rep(j,n){
if(j != i){
ans += f(i,j);
}
}
return ans;
};
vector<pii> blocks;
int win1 = inf1;
if(n <= 100){
win1 = win_count(a[0]);
}
if(win1 > 1){
blocks.pb({0,2});
for(int i = 3; i < n; ++i){
if(f(a[1],a[i])){
blocks.back().ss++;
}
else{
break;
}
}
}
else{
int win2 = win_count(a[1]);
if(win2 > 1){
blocks.pb({0,0});
}
else{
if(f(a[0],a[1])){
blocks.pb({0,0});
blocks.pb({1,1});
}
else{
blocks.pb({0,1});
}
}
}
int s = blocks.back().ss+1;
for(int i = s; i < n; ++i){
if(f(a[blocks.back().ff],a[i])){
blocks.pb({blocks.back().ss+1,i});
}
}
vector<int> ans(n);
int ptr = 0;
for(auto [l,r] : blocks){
rev(i,r,l){
ans[a[i]] = ptr++;
}
}
return ans;
}
Compilation message (stderr)
monster.cpp:65:6: warning: '{anonymous}::example_variable' defined but not used [-Wunused-variable]
65 | bool example_variable;
| ^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |