Submission #78449

#TimeUsernameProblemLanguageResultExecution timeMemory
78449SaboonTriangles (CEOI18_tri)C++14
75 / 100
3054 ms2112 KiB
#include <iostream> #include <queue> #include <bitset> #include <stack> #include <vector> #include <trilib.h> #include <cstring> #include <cmath> #include <unordered_map> #include <map> #include <set> #include <algorithm> #include <iomanip> #define prime first #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; 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]; void remove (int fi, int mid, int se) { pre[se] = fi; nex[fi] = se; first = fi; } void insert (int fi, int mid, int se) { nex[fi] = mid; nex[mid] = se; pre[se] = mid; pre[mid] = fi; } int m = 0, a[maxn]; void refresh () { m = 0; int st = first; while (true) { a[m ++] = st; st = nex[st]; if (st == first) { a[m] = st; return; } } } int main() { ios::sync_with_stdio(false); int n = get_n (); 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; } refresh (); for (int i = 4; i <= n; i++) { int lo = 0, hi = m; while (hi - lo > 1) { int mid = (hi + lo) >> 1; if (!is_clockwise (a[lo], a[mid], i)) hi = mid; else lo = mid; } if (is_clockwise (a[lo], a[hi], i)) continue; insert (a[lo], i, a[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); refresh (); } int cnt = 0, st = first; while (true) { cnt ++; st = nex[st]; if (st == first) break; } give_answer (cnt); }
#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...