#include <bits/stdc++.h>
#include "trilib.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
map<ll,bool> ans_map;
bool ask(int a, int b, int c)
{
ll x = a+1e5*(ll)b+1e10*(ll)c;
if(ans_map.find(x) != ans_map.end()) return ans_map[x];
ans_map[x] = is_clockwise(a,b,c);
return ans_map[x];
}
bool comp(int a, int b)
{
return !ask(1,a,b);
}
vi get_hull(vi p, int a, int b)
{
sort(all(p),comp);
vi ans = {a,b};
forall(it,p)
{
while(true)
{
int p1 = ans[siz(ans)-2];
int p2 = ans[siz(ans)-1];
if(!ask(p1,p2,it)) break;
else ans.pop_back();
}
ans.pb(it);
}
vi ans2;
rep2(i,2,siz(ans)-1) ans2.pb(ans[i]);
return ans2;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//random_start();
int n = get_n();
vi p1;
vi p2;
rep2(i,3,n)
{
if(!ask(1,2,i)) p1.pb(i);
else p2.pb(i);
}
p1 = get_hull(p1,1,2);
p2 = get_hull(p2,2,1);
p1.pb(1);
vi pom = {2};
forall(it,p1) pom.pb(it);
p1 = pom;
if(siz(p2) == 0)
{
give_answer(siz(p1));
return 0;
}
int p1_l = 0;
int p1_r = siz(p1)-1;
int p2_l = 0;
int p2_r = siz(p2)-1;
while(true)
{
bool c1 = ask(p2[p2_r],p1[p1_l],(p1_l != p1_r ? p1[p1_l+1] : p2[p2_r]));
bool c2 = ask((p2_r != p2_l ? p2[p2_r-1] : p1[p1_r]),p2[p2_r],p1[p1_l]);
if(!c1 && !c2) break;
if(c1) p1_l++;
else p2_r--;
}
while(true)
{
bool c1 = ask(p2[p2_l],p1[p1_r],(p1_l != p1_r ? p1[p1_r-1] : p2[p2_r]));
bool c2 = ask((p2_l != p2_r ? p2[p2_l+1] : p1[p1_l]),p2[p2_l],p1[p1_r]);
if(c1 && c2) break;
if(!c1) p1_r--;
else p2_l++;
}
give_answer(p1_r-p1_l+p2_r-p2_l+2);
}
| # | 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... |