Submission #681152

#TimeUsernameProblemLanguageResultExecution timeMemory
681152sysiaTriangles (CEOI18_tri)C++17
0 / 100
1 ms468 KiB
//Sylwia Sapkowska
#include <bits/stdc++.h>
#include "trilib.h"
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;

void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long
typedef pair<int, int> T;
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;
/*
Solution:
Creating convex hull requires 3 steps:
a) finding a point which lies on convex hull - ?? queries
b) angular sort with respect to the point from a) - O(n log n) queries
c) finding actual convex hull - O(n) queries

--At most one point not on the convex hull -> if we choose two different points, then one of them certainly lies on the
convex hull.
--Let's sort points with respect to some random point. Then this point lies on the convex hull iff first or last point of the sorted list creates a side with that random point (we can check how many points lie on which side of that line).
*/

mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
int p(int a, int b){return a+rng()%(b-a+1);}

int cw(int a, int b, int c){
    if (a == b || b == c || a == c) assert(false);
    return is_clockwise(a, b, c) ? 1 : -1;
}

void solve(){
    int n = get_n();
    //just use 1 and 2 to divide
    vector<vector<int>>parts(2), hull(2);
    parts[0].emplace_back(2);
    parts[1].emplace_back(2);
    for (int i = 3; i<=n; i++) parts[cw(1, 2, i) == 1 ? 1 : 0].emplace_back(i);
    for (int rep = 0; rep < 2; rep++){
        stable_sort(parts[rep].begin(), parts[rep].end(), [&](auto x, auto y){return cw(1, x, y) == 1;});
        for (auto x: parts[rep]){
            while ((int)hull[rep].size() >= 2 && cw(hull[rep].end()[-2], hull[rep].end()[-1], x) == -1) hull[rep].pop_back();
            hull[rep].emplace_back(x);
        }
        if (rep) reverse(hull[rep].begin(), hull[rep].end());
        hull[rep].insert(hull[rep].begin(), 1);
        // for (auto x: hull[rep]) cout << x << " ";
        // cout << "\n";
    }
    // now we have a heart and we want to merge it
    for (int rep = 0; rep < 2; rep++){
        hull[rep].pop_back();
        while (1){
            bool any = 0;
            if (hull[0].size() >= 2 && cw(hull[0].end()[-2], hull[0].end()[-1], hull[1].end()[-1]) == -1) {
                hull[0].pop_back();
                any = 1;
            }
            if (hull[1].size() >= 2 && cw(hull[0].end()[-1], hull[1].end()[-1], hull[1].end()[-2]) == -1) {
                hull[1].pop_back();
                any = 1;
            }
            if (!any) break;
        }
        for (int i = 0; i<2; i++) reverse(hull[i].begin(), hull[i].end());
        hull[0].swap(hull[1]);
    }
    // for (int rep = 0; rep < 2; rep++){
    //     for (auto x: hull[rep]) cout << x << " ";
    //     cout << "\n";
    // }
    int ans = (int)hull[0].size() + (int)hull[1].size();
    // cout << ans << "\n";
    give_answer(ans);
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}
#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...