답안 #410497

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410497 2021-05-22T19:50:11 Z duality Dragon 2 (JOI17_dragon2) C++11
60 / 100
2114 ms 262148 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#define x first
#define y second
const double PI = acos(-1.0);

pii BB;
struct angle {
    pii p;
    char c;
    angle(double a) {
        assert(a == PI);
        p = BB,c = 1;
    }
    angle(pii a,pii b) {
        if ((LLI) a.x*b.y < (LLI) a.y*b.x) {
            if (b != BB) a.x *= -1,a.y *= -1;
            c = 0,p = a;
        }
        else {
            if (b == BB) a.x *= -1,a.y *= -1;
            c = 1,p = a;
        }
    }
    bool operator<(const angle &o) const {
        if (c == o.c) return (LLI) p.x*o.p.y > (LLI) p.y*o.p.x;
        else return c < o.c;
    }
    angle operator+(double d) {
        angle n = *this;
        d /= PI;
        n.c += round(d);
        return n;
    }
    angle operator-(double d) {
        angle n = *this;
        d /= PI;
        n.c -= round(d);
        return n;
    }
};
vpii pos[30000];
vector<pair<angle,angle> > pos2[30000];
struct event { angle x,l,r; int i; };
bool comp(event a,event b) {
    return a.x < b.x;
}
vector<event> events[30000][3];
int bit[90001];
int ans[100000];
vector<angle> poss;
int main() {
    int i;
    int N,M,Q;
    int A,B,C,F,G;
    pii a,b;
    scanf("%d %d",&N,&M);
    for (i = 0; i < N; i++) scanf("%d %d %d",&A,&B,&C),pos[C-1].pb(mp(A,B));
    scanf("%d %d %d %d",&a.x,&a.y,&b.x,&b.y);

    int j;
    BB = mp(b.x-a.x,b.y-a.y);
    for (i = 0; i < N; i++) {
        for (j = 0; j < pos[i].size(); j++) {
            angle a1 = angle(mp(pos[i][j].x-a.x,pos[i][j].y-a.y),mp(b.x-a.x,b.y-a.y));
            angle a2 = angle(mp(pos[i][j].x-b.x,pos[i][j].y-b.y),mp(a.x-b.x,a.y-b.y));
            /*double a1 = atan2(pos[i][j].y-a.y,pos[i][j].x-a.x)-atan2(b.y-a.y,b.x-a.x);
            if (a1 < 0) a1 += 2*PI;
            double a2 = atan2(pos[i][j].y-b.y,pos[i][j].x-b.x)-atan2(a.y-b.y,a.x-b.x);
            if (a2 < 0) a2 += 2*PI;
            pos2[i].pb(mp(angle(a1),angle(a2)));*/
            pos2[i].pb(mp(a1,a2));
        }
    }

    scanf("%d",&Q);
    for (i = 0; i < Q; i++) {
        scanf("%d %d",&F,&G),F--,G--;
        if (pos[F].size() < pos[G].size()) {
            for (j = 0; j < pos2[F].size(); j++) {
                if (pos2[F][j].x < angle(PI)) {
                    events[G][0].pb((event){pos2[F][j].x-PI,pos2[F][j].y,pos2[F][j].y+PI,-(i+1)});
                    events[G][0].pb((event){pos2[F][j].x,pos2[F][j].y,pos2[F][j].y+PI,i+1});
                }
                else {
                    events[G][0].pb((event){pos2[F][j].x,pos2[F][j].y-PI,pos2[F][j].y,-(i+1)});
                    events[G][0].pb((event){pos2[F][j].x+PI,pos2[F][j].y-PI,pos2[F][j].y,i+1});
                }
            }
        }
        else {
            for (j = 0; j < pos2[G].size(); j++) {
                if (pos2[G][j].x < angle(PI)) {
                    events[F][0].pb((event){pos2[G][j].x,pos2[G][j].y-PI,pos2[G][j].y,-(i+1)});
                    events[F][0].pb((event){pos2[G][j].x+PI,pos2[G][j].y-PI,pos2[G][j].y,i+1});
                    events[F][2].pb((event){pos2[G][j].x-PI,pos2[G][j].y,pos2[G][j].y+PI,-(i+1)});
                    events[F][2].pb((event){pos2[G][j].x,pos2[G][j].y,pos2[G][j].y+PI,i+1});
                }
                else {
                    events[F][0].pb((event){pos2[G][j].x-PI,pos2[G][j].y,pos2[G][j].y+PI,-(i+1)});
                    events[F][0].pb((event){pos2[G][j].x,pos2[G][j].y,pos2[G][j].y+PI,i+1});
                    events[F][1].pb((event){pos2[G][j].x,pos2[G][j].y-PI,pos2[G][j].y,-(i+1)});
                    events[F][1].pb((event){pos2[G][j].x+PI,pos2[G][j].y-PI,pos2[G][j].y,i+1});
                }
            }
        }
    }

    int t,k,l;
    for (i = 0; i < N; i++) {
        for (t = 0; t < 3; t++) {
            vector<event> &ee = events[i][t];
            for (j = 0; j < pos2[i].size(); j++) {
                if ((t == 1) && (angle(PI) < pos2[i][j].x)) continue;
                if ((t == 2) && (pos2[i][j].x < angle(PI))) continue;
                for (k = -1; k <= 1; k++) {
                    poss.pb(pos2[i][j].y+2*PI*k);
                    for (l = -1; l <= 1; l++) ee.pb((event){pos2[i][j].x+2*PI*k,pos2[i][j].y+2*PI*l,pos2[i][j].y+2*PI*l,0});
                }
            }
            sort(poss.begin(),poss.end());
            sort(ee.begin(),ee.end(),comp);
            for (j = 0; j < ee.size(); j++) {
                if (ee[j].i == 0) {
                    int p = lower_bound(poss.begin(),poss.end(),ee[j].l)-poss.begin();
                    for (k = p+1; k <= poss.size(); k += k & (-k)) bit[k]++;
                }
                else if (ee[j].i > 0) {
                    int l = lower_bound(poss.begin(),poss.end(),ee[j].l)-poss.begin();
                    int r = upper_bound(poss.begin(),poss.end(),ee[j].r)-poss.begin()-1;
                    if (l <= r) {
                        for (k = r+1; k > 0; k -= k & (-k)) ans[ee[j].i-1] += bit[k];
                        for (k = l; k > 0; k -= k & (-k)) ans[ee[j].i-1] -= bit[k];
                    }
                }
                else {
                    int l = lower_bound(poss.begin(),poss.end(),ee[j].l)-poss.begin();
                    int r = upper_bound(poss.begin(),poss.end(),ee[j].r)-poss.begin()-1;
                    if (l <= r) {
                        for (k = r+1; k > 0; k -= k & (-k)) ans[-ee[j].i-1] -= bit[k];
                        for (k = l; k > 0; k -= k & (-k)) ans[-ee[j].i-1] += bit[k];
                    }
                }
            }
            fill(bit,bit+poss.size()+1,0);
            ee.clear(),poss.clear();
        }
    }
    for (i = 0; i < Q; i++) printf("%d\n",ans[i]);

    return 0;
}

Compilation message

dragon2.cpp: In function 'int main()':
dragon2.cpp:118:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |         for (j = 0; j < pos[i].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~
dragon2.cpp:134:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<angle, angle> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  134 |             for (j = 0; j < pos2[F].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~
dragon2.cpp:146:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<angle, angle> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  146 |             for (j = 0; j < pos2[G].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~
dragon2.cpp:167:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<angle, angle> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  167 |             for (j = 0; j < pos2[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~
dragon2.cpp:177:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  177 |             for (j = 0; j < ee.size(); j++) {
      |                         ~~^~~~~~~~~~~
dragon2.cpp:180:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<angle>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  180 |                     for (k = p+1; k <= poss.size(); k += k & (-k)) bit[k]++;
      |                                   ~~^~~~~~~~~~~~~~
dragon2.cpp:111:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
dragon2.cpp:112:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |     for (i = 0; i < N; i++) scanf("%d %d %d",&A,&B,&C),pos[C-1].pb(mp(A,B));
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:113:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |     scanf("%d %d %d %d",&a.x,&a.y,&b.x,&b.y);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:130:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |     scanf("%d",&Q);
      |     ~~~~~^~~~~~~~~
dragon2.cpp:132:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  132 |         scanf("%d %d",&F,&G),F--,G--;
      |         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 7232 KB Output is correct
2 Correct 42 ms 8596 KB Output is correct
3 Correct 163 ms 25608 KB Output is correct
4 Correct 232 ms 42136 KB Output is correct
5 Correct 115 ms 17724 KB Output is correct
6 Correct 15 ms 8108 KB Output is correct
7 Correct 14 ms 8176 KB Output is correct
8 Correct 28 ms 6980 KB Output is correct
9 Correct 26 ms 6924 KB Output is correct
10 Correct 27 ms 7144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 321 ms 35408 KB Output is correct
2 Correct 483 ms 50144 KB Output is correct
3 Correct 251 ms 34204 KB Output is correct
4 Correct 169 ms 35652 KB Output is correct
5 Correct 107 ms 42096 KB Output is correct
6 Correct 289 ms 39388 KB Output is correct
7 Correct 304 ms 39456 KB Output is correct
8 Correct 320 ms 38264 KB Output is correct
9 Correct 266 ms 36992 KB Output is correct
10 Correct 274 ms 39360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 7232 KB Output is correct
2 Correct 42 ms 8596 KB Output is correct
3 Correct 163 ms 25608 KB Output is correct
4 Correct 232 ms 42136 KB Output is correct
5 Correct 115 ms 17724 KB Output is correct
6 Correct 15 ms 8108 KB Output is correct
7 Correct 14 ms 8176 KB Output is correct
8 Correct 28 ms 6980 KB Output is correct
9 Correct 26 ms 6924 KB Output is correct
10 Correct 27 ms 7144 KB Output is correct
11 Correct 321 ms 35408 KB Output is correct
12 Correct 483 ms 50144 KB Output is correct
13 Correct 251 ms 34204 KB Output is correct
14 Correct 169 ms 35652 KB Output is correct
15 Correct 107 ms 42096 KB Output is correct
16 Correct 289 ms 39388 KB Output is correct
17 Correct 304 ms 39456 KB Output is correct
18 Correct 320 ms 38264 KB Output is correct
19 Correct 266 ms 36992 KB Output is correct
20 Correct 274 ms 39360 KB Output is correct
21 Correct 320 ms 35288 KB Output is correct
22 Correct 502 ms 48440 KB Output is correct
23 Correct 2114 ms 233176 KB Output is correct
24 Runtime error 299 ms 262148 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -