Submission #586979

# Submission time Handle Problem Language Result Execution time Memory
586979 2022-07-01T07:13:30 Z 반딧불(#8396) Mixture (BOI20_mixture) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef TEST
typedef long long ll;
#else
typedef __int128 ll;
#endif

struct vector2{
    ll x, y;
    vector2(){}
    vector2(ll x, ll y): x(x), y(y){}

    vector2 operator-()const{
        return vector2(-x, -y);
    }

    vector2 operator-(const vector2 &r)const{
        return vector2(x-r.x, y-r.y);
    }

    ll cross(vector2 r)const{
        return x*r.y - y*r.x;
    }

    bool operator<(const vector2 &r)const{
        if((make_pair(y, x) > make_pair(ll(0), ll(0))) ^ (make_pair(r.y, r.x) > make_pair(ll(0), ll(0)))){
            return make_pair(y, x) > make_pair(ll(0), ll(0));
        }
        return (vector2(0, 0) - *this).cross(r - *this) < 0;
    }

    bool operator==(const vector2 &r)const{
        return x==r.x && y==r.y;
    }
};

ll ccw(vector2 a, vector2 b){
    return a.cross(b);
}

ll ccw(vector2 a, vector2 b, vector2 c){
    return (b-a).cross(c-a);
}

vector2 calc(ll A, ll B, ll C, ll x, ll y, ll z){
    C += A+B, z += x+y;
    A*=z, B*=z, x*=C, y*=C;
    x-=A, y-=B;
    ll g = abs(__gcd(x, y));
    if(g) x/=g, y/=g;
    return vector2(x, y);
}

ll A, B, C;
int n;
vector2 arr[100002];
int arrCnt;

/// ans=1 ���
int oneCnt;

/// ans=2 ���
map<vector2, ll> twoMp;
ll twoCnt;

/// ans=3 ���
map<vector2, int> threeMp;
bool threeCnt;

void addPoint(){
    ll x, y, z;
    scanf("%lld %lld %lld", &x, &y, &z);
    int i = ++arrCnt;
    arr[i] = calc(A, B, C, x, y, z);

    /// ans=1 update
    if(arr[i] == vector2(0, 0)){
        oneCnt++;
        return;
    }

    /// ans=2 update
    twoMp[arr[i]]++;
    twoCnt += twoMp[-arr[i]];

    /// ans=3 update
    threeMp[arr[i]]++;
//    auto it = threeMp.lower_bound(arr[i]);
}

void delPoint(){
    int i;
    scanf("%d", &i);

    /// ans=1 update
    if(arr[i] == vector2(0, 0)){
        oneCnt--;
        return;
    }

    /// ans=2 update
    twoCnt -= twoMp[-arr[i]];
    twoMp[arr[i]]--;

    /// ans=3 update
    threeMp[arr[i]]--;
    if(!threeMp[arr[i]]) threeMp.erase(arr[i]);
}

bool calc3(){
    vector2 prv;
    if(threeMp.size() <= 2) return false;
    for(auto it = threeMp.begin(); it != threeMp.end(); ++it){
        if(it == threeMp.begin()){
            prv = it->first;
            continue;
        }
        if(ccw(prv, vector2(0, 0), it->first) >= 0) return false;
        prv = it->first;
    }
    if(ccw(prv, vector2(0, 0), threeMp.begin()->first) >= 0) return false;
    return true;
}

void print(){
    if(oneCnt) puts("1");
    else if(twoCnt) puts("2");
    else if(calc3()) puts("3");
    else puts("0");
}

int main(){
    scanf("%lld %lld %lld %d", &A, &B, &C, &n);
    for(int i=1; i<=n; i++){
        char c;
        scanf(" %c", &c);
        if(c=='A') addPoint();
        else delPoint();
        print();
    }
}

Compilation message

Mixture.cpp: In function 'vector2 calc(ll, ll, ll, ll, ll, ll)':
Mixture.cpp:52:27: error: call of overloaded 'abs(__int128)' is ambiguous
   52 |     ll g = abs(__gcd(x, y));
      |                           ^
In file included from /usr/include/c++/10/bits/std_abs.h:38,
                 from /usr/include/c++/10/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Mixture.cpp:1:
/usr/include/stdlib.h:840:12: note: candidate: 'int abs(int)'
  840 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
In file included from /usr/include/c++/10/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Mixture.cpp:1:
/usr/include/c++/10/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/10/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/10/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/10/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/10/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
Mixture.cpp: In function 'void addPoint()':
Mixture.cpp:75:15: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'll*' {aka '__int128*'} [-Wformat=]
   75 |     scanf("%lld %lld %lld", &x, &y, &z);
      |            ~~~^             ~~
      |               |             |
      |               |             ll* {aka __int128*}
      |               long long int*
Mixture.cpp:75:20: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type 'll*' {aka '__int128*'} [-Wformat=]
   75 |     scanf("%lld %lld %lld", &x, &y, &z);
      |                 ~~~^            ~~
      |                    |            |
      |                    |            ll* {aka __int128*}
      |                    long long int*
Mixture.cpp:75:25: warning: format '%lld' expects argument of type 'long long int*', but argument 4 has type 'll*' {aka '__int128*'} [-Wformat=]
   75 |     scanf("%lld %lld %lld", &x, &y, &z);
      |                      ~~~^           ~~
      |                         |           |
      |                         |           ll* {aka __int128*}
      |                         long long int*
Mixture.cpp: In function 'int main()':
Mixture.cpp:136:15: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'll*' {aka '__int128*'} [-Wformat=]
  136 |     scanf("%lld %lld %lld %d", &A, &B, &C, &n);
      |            ~~~^                ~~
      |               |                |
      |               long long int*   ll* {aka __int128*}
Mixture.cpp:136:20: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type 'll*' {aka '__int128*'} [-Wformat=]
  136 |     scanf("%lld %lld %lld %d", &A, &B, &C, &n);
      |                 ~~~^               ~~
      |                    |               |
      |                    long long int*  ll* {aka __int128*}
Mixture.cpp:136:25: warning: format '%lld' expects argument of type 'long long int*', but argument 4 has type 'll*' {aka '__int128*'} [-Wformat=]
  136 |     scanf("%lld %lld %lld %d", &A, &B, &C, &n);
      |                      ~~~^              ~~
      |                         |              |
      |                         long long int* ll* {aka __int128*}
Mixture.cpp: In function 'void addPoint()':
Mixture.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |     scanf("%lld %lld %lld", &x, &y, &z);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mixture.cpp: In function 'void delPoint()':
Mixture.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |     scanf("%d", &i);
      |     ~~~~~^~~~~~~~~~
Mixture.cpp: In function 'int main()':
Mixture.cpp:136:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  136 |     scanf("%lld %lld %lld %d", &A, &B, &C, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mixture.cpp:139:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  139 |         scanf(" %c", &c);
      |         ~~~~~^~~~~~~~~~~