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 "trilib.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
map<tuple<int, int, int>, int> q;
int qry(int a, int b, int c){
int d = a, e = b, f = c;
if(f < d) swap(d, f);
if(e < d) swap(d, e);
if(e < f) swap(e, f);
int dir;
if(a == d) dir = (b == e);
else if(a == e) dir = (b == f);
else dir = (b == d);
if(q.count({d, e, f})){
if(dir) return q[{d, e, f}];
return q[{d, e, f}]^1;
}
int r = is_clockwise(a, b, c);
if(dir) q[{d, e, f}] = r;
else q[{d, e, f}] = r^1;
return r;
}
void qsort(deque<int>& p, deque<int>& t){
if(t.size() == 0) return;
if(t.size() == 1){
p.push_back(t[0]);
return;
}
int x = rand()%t.size();
deque<int> left, right;
for(int i = 0; i < (int)t.size(); i++){
if(i == x) continue;
if(qry(1, t[x], t[i])) right.push_back(t[i]);
else left.push_back(t[i]);
}
qsort(p, left);
p.push_back(t[x]);
qsort(p, right);
}
int main(){
srand(time(0));
cin.tie(0);
ios::sync_with_stdio(0);
int n = get_n();
deque<int> p, t, h(n+1);
for(int i = 2; i <= n; i++) t.push_back(i);
qsort(p, t);
int s = 2;
h[0] = 1, h[1] = p[0];
for(int i = 1; i < n-1; i++){
while(s > 1 && !qry(h[s-2], h[s-1], p[i])) s--;
h[s++] = p[i];
}
int cng = 1;
while(cng){
cng = 0;
while(s > 2 && !qry(h[s-2], h[s-1], h[0])){
s--;
cng = 1;
}
while(s > 2 && !qry(h[s-1], h[0], h[1])){
s--;
h.pop_front();
cng = 1;
}
while(s > 2 && !qry(h[0], h[1], h[2])){
s--;
int temp = h.front();
h.pop_front(), h.pop_front();
h.push_front(temp);
cng = 1;
}
}
give_answer(s);
}
# | 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... |