Submission #600161

# Submission time Handle Problem Language Result Execution time Memory
600161 2022-07-20T13:50:55 Z OttoTheDino Mixture (BOI20_mixture) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
    using namespace std;
     
    #define rep(i,s,e)                  for (int i = s; i <= e; ++i)
    #define rrep(i,s,e)                 for (int i = s; i >= e; --i)
    #define pb                          push_back
    #define pf                          push_front
    #define fi                          first
    #define se                          second
    #define all(a)                      a.begin(), a.end()
    #define len(a)                      (int)a.size()
    typedef long long ll;
    typedef pair<int, int> ii;
    typedef pair<ll, ll> pll;
    typedef vector<ii> vii;
    typedef vector<int> vi;
    typedef vector<double> vd;
    typedef vector<string> vs;
    typedef vector<ll> vll;
     
    const double eps = 1e-8, pi = acos(-1);
    const int mx = 1e5;
     
    bool eq (double a, double b) {
        return abs(a-b)<=5*eps;
    }
     
    double ang[mx+1] = {};
    int bud[mx+1] = {}, b = 0;
    set<pair<double,int>> st2;
     
    void do_two (int id) {
        double poss[5] = {fmod(ang[id]+pi+eps,2*pi),
                          
                            ang[id]+pi-eps,
                          fmod(ang[id]+pi-eps,2*pi),
                            fmod(ang[id]+pi,2*pi)+eps,
                            fmod(ang[id]+pi,2*pi)-eps};
     
        rep (i,0,3) {
            double pos = poss[i];
            auto it = st2.lower_bound({pos, 0});
            if (it!=st2.end() && eq((*it).fi,pos)) {
                bud[id] = (*it).se;
                bud[(*it).se] = id;
                st2.erase(it);
                b++;
                return;
            }
        }
     
        st2.insert({ang[id], id});
    }
     
    int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);
     
        double S, P, G; cin >> S >> P >> G;
     
        double X = S/(S+P+G), Y = P/(S+P+G);
     
        int n; cin >>n;
     
        int id = 1, a=0, p[n+1] = {};
        multiset<double> st3; 
     
        rep (i,1,n) {
            char tp; cin >> tp;
            if (tp=='A') {
                double Si, Pi, Gi;
                cin >> Si >> Pi >> Gi;
                double x = Si/(Si+Pi+Gi), y = Pi/(Si+Pi+Gi);
                if (eq(X,x) && eq(Y,y)) {
                    a++;
                    p[id] = 1;
                }
                else {
                    ang[id] = fmod(pi+atan2(y-Y, x-X),2*pi);
                    st3.insert(ang[id]);
                    do_two(id);
                }
                ++id;
            }
            else {
                int x; cin >> x;
                st3.erase(ang[x]);
                a -= p[x];
                if (bud[x]) {
                    b--;
                    bud[bud[x]] = 0;
                    do_two(bud[x]);
                    bud[x] = 0;
                }
            }
     
            bool c = 0;
            if (len(st3)>2) {
                double un = (*st3.begin());
                double dos = (*--st3.upper_bound(un+pi));
                double tres = (*--st3.upper_bound(dos+pi));
                if (max(dos-un,max(tres-dos,2*pi+un-tres))<=pi) c = 1; 
            }
     
     
            if (a) cout << "1\n";
            else if (b) cout << "2\n";
            else if (c) cout << "3\n";
            else cout << "0\n";
        }
     
        return 0;
    }
    const double eps = 1e-8, pi = acos(-1);
    const int mx = 1e5;
     
    bool eq (double a, double b) {
        return abs(a-b)<=5*eps;
    }
     
    double ang[mx+1] = {};
    int bud[mx+1] = {}, b = 0;
    set<pair<double,int>> st2;
     
    void do_two (int id) {
        double poss[5] = {fmod(ang[id]+pi+eps,2*pi),
                          
                            fmod(ang[id]+pi,2*pi),
                          fmod(ang[id]+pi-eps,2*pi),
                            fmod(ang[id]+pi,2*pi)+eps,
                            fmod(ang[id]+pi,2*pi)-eps};
     
        rep (i,0,3) {
            double pos = poss[i];
            auto it = st2.lower_bound({pos, 0});
            if (it!=st2.end() && eq((*it).fi,pos)) {
                bud[id] = (*it).se;
                bud[(*it).se] = id;
                st2.erase(it);
                b++;
                return;
            }
        }
     
        st2.insert({ang[id], id});
    }
     
    int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);
     
        double S, P, G; cin >> S >> P >> G;
     
        double X = S/(S+P+G), Y = P/(S+P+G);
     
        int n; cin >>n;
     
        int id = 1, a=0, p[n+1] = {};
        multiset<double> st3; 
     
        rep (i,1,n) {
            char tp; cin >> tp;
            if (tp=='A') {
                double Si, Pi, Gi;
                cin >> Si >> Pi >> Gi;
                double x = Si/(Si+Pi+Gi), y = Pi/(Si+Pi+Gi);
                if (eq(X,x) && eq(Y,y)) {
                    a++;
                    p[id] = 1;
                }
                else {
                    ang[id] = fmod(pi+atan2(y-Y, x-X),2*pi);
                    st3.insert(ang[id]);
                    do_two(id);
                }
                ++id;
            }
            else {
                int x; cin >> x;
                st3.erase(ang[x]);
                a -= p[x];
                if (bud[x]) {
                    b--;
                    bud[bud[x]] = 0;
                    do_two(bud[x]);
                    bud[x] = 0;
                }
            }
     
            bool c = 0;
            if (len(st3)>2) {
                double un = (*st3.begin());
                double dos = (*--st3.upper_bound(un+pi));
                double tres = (*--st3.upper_bound(dos+pi));
                if (max(dos-un,max(tres-dos,2*pi+un-tres))<=pi) c = 1; 
            }
     
     
            if (a) cout << "1\n";
            else if (b) cout << "2\n";
            else if (c) cout << "3\n";
            else cout << "0\n";
        }
     
        return 0;
    }

Compilation message

Mixture.cpp:114:18: error: redefinition of 'const double eps'
  114 |     const double eps = 1e-8, pi = acos(-1);
      |                  ^~~
Mixture.cpp:21:18: note: 'const double eps' previously defined here
   21 |     const double eps = 1e-8, pi = acos(-1);
      |                  ^~~
Mixture.cpp:114:30: error: redefinition of 'const double pi'
  114 |     const double eps = 1e-8, pi = acos(-1);
      |                              ^~
Mixture.cpp:21:30: note: 'const double pi' previously defined here
   21 |     const double eps = 1e-8, pi = acos(-1);
      |                              ^~
Mixture.cpp:115:15: error: redefinition of 'const int mx'
  115 |     const int mx = 1e5;
      |               ^~
Mixture.cpp:22:15: note: 'const int mx' previously defined here
   22 |     const int mx = 1e5;
      |               ^~
Mixture.cpp:117:10: error: redefinition of 'bool eq(double, double)'
  117 |     bool eq (double a, double b) {
      |          ^~
Mixture.cpp:24:10: note: 'bool eq(double, double)' previously defined here
   24 |     bool eq (double a, double b) {
      |          ^~
Mixture.cpp:121:12: error: redefinition of 'double ang [100001]'
  121 |     double ang[mx+1] = {};
      |            ^~~
Mixture.cpp:28:12: note: 'double ang [100001]' previously defined here
   28 |     double ang[mx+1] = {};
      |            ^~~
Mixture.cpp:122:9: error: redefinition of 'int bud [100001]'
  122 |     int bud[mx+1] = {}, b = 0;
      |         ^~~
Mixture.cpp:29:9: note: 'int bud [100001]' previously defined here
   29 |     int bud[mx+1] = {}, b = 0;
      |         ^~~
Mixture.cpp:122:25: error: redefinition of 'int b'
  122 |     int bud[mx+1] = {}, b = 0;
      |                         ^
Mixture.cpp:29:25: note: 'int b' previously defined here
   29 |     int bud[mx+1] = {}, b = 0;
      |                         ^
Mixture.cpp:123:27: error: redefinition of 'std::set<std::pair<double, int> > st2'
  123 |     set<pair<double,int>> st2;
      |                           ^~~
Mixture.cpp:30:27: note: 'std::set<std::pair<double, int> > st2' previously declared here
   30 |     set<pair<double,int>> st2;
      |                           ^~~
Mixture.cpp:125:10: error: redefinition of 'void do_two(int)'
  125 |     void do_two (int id) {
      |          ^~~~~~
Mixture.cpp:32:10: note: 'void do_two(int)' previously defined here
   32 |     void do_two (int id) {
      |          ^~~~~~
Mixture.cpp:148:9: error: redefinition of 'int main()'
  148 |     int main() {
      |         ^~~~
Mixture.cpp:55:9: note: 'int main()' previously defined here
   55 |     int main() {
      |         ^~~~