Submission #82930

#TimeUsernameProblemLanguageResultExecution timeMemory
82930SaboonTriangles (CEOI18_tri)C++14
0 / 100
3 ms804 KiB
#include <bits/stdc++.h> #include <trilib.h> #define prime firstv #define alpha second #define PB push_back #define PF push_front #define MP make_pair using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef unsigned long long ull; const int maxn = 4e4 + 100; const int SQRT = 201; int nexsqrt[maxn]; int first = 1; /* int get_n () { int k; cin >> k; return k; } bool is_clockwise (int fi, int se, int th) { cout << fi << " " << se << " " << th << endl; bool k; cin >> k; return k; } void give_answer (int x) { cout << x << endl; } */ int pre[maxn], nex[maxn]; int m = 3; void remove (int fi, int mid, int se) { // cout << "Remove " << fi << " - " << mid << " - " << se << endl; m --; pre[se] = fi; nex[fi] = se; int tmp = nexsqrt[mid], k = SQRT; while (k --) { int tmp2 = nexsqrt[fi]; nexsqrt[fi] = tmp; tmp = tmp2; fi = pre[fi]; } if (mid == first) se = first; } void insert (int fi, int mid, int se) { // cout << "Insert " << fi << " - " << mid << " - " << se << endl; m ++; nex[fi] = mid; nex[mid] = se; pre[se] = mid; pre[mid] = fi; int k = SQRT, tmp = mid; while (k --) { nexsqrt[mid] = nexsqrt[pre[mid]]; mid = pre[mid]; } nexsqrt[mid] = tmp; } int get (int idx) { idx %= m; int tmp = first; while (idx > 0) { if (idx >= SQRT) { tmp = nexsqrt[tmp]; idx -= SQRT; } else { tmp = nex[tmp]; idx --; } } return tmp; } void build_first () { if (is_clockwise (1, 2, 3)) { nex[1] = 2; nex[2] = 3; nex[3] = 1; pre[1] = 3; pre[2] = 1; pre[3] = 2; } else { nex[1] = 3; nex[3] = 2; nex[2] = 1; pre[1] = 2; pre[2] = 3; pre[3] = 1; } for (int i = 1; i <= 3; i++) nexsqrt[i] = i; } int main() { ios::sync_with_stdio(false); int n = get_n (); build_first (); for (int i = 4; i <= n; i++) { int lo = 0, hi = m; while (hi - lo > 1) { int mid = (hi + lo) >> 1; int x = get (lo), y = get (mid); if (!is_clockwise (x, y, i)) hi = mid; else lo = mid; } int x = get (lo), y = get (hi); if (is_clockwise (x, y, i)) continue; insert (get (lo), i, get (hi)); while (!is_clockwise (i, nex[i], nex[nex[i]])) { remove (i, nex[i], nex[nex[i]]); } while (!is_clockwise (pre[pre[i]], pre[i], i)) { remove (pre[pre[i]], pre[i], i); } } give_answer (m); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...