답안 #410502

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410502 2021-05-22T19:53:36 Z duality Dragon 2 (JOI17_dragon2) C++11
60 / 100
2001 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;
}
vpii vv[30000];
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()) vv[G].pb(mp(F,i+1));
        else vv[F].pb(mp(G,-(i+1)));
    }

    int t,k,l;
    for (i = 0; i < N; i++) {
        for (j = 0; j < vv[i].size(); j++) {
            if (vv[i][j].second > 0) {
                int t = i,t2 = j;
                F = vv[i][j].first,G = i,i = vv[i][j].second-1;
                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});
                    }
                }
                j = t2,i = t;
            }
            else {
                int t = i,t2 = j;
                G = vv[i][j].first,F = i,i = -vv[i][j].second-1;
                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});
                    }
                }
                j = t2,i = t;
            }
        }
        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:119: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]
  119 |         for (j = 0; j < pos[i].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~
dragon2.cpp:140: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]
  140 |         for (j = 0; j < vv[i].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~
dragon2.cpp:144:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<angle, angle> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  144 |                 for (j = 0; j < pos2[F].size(); j++) {
      |                             ~~^~~~~~~~~~~~~~~~
dragon2.cpp:159:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<angle, angle> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  159 |                 for (j = 0; j < pos2[G].size(); j++) {
      |                             ~~^~~~~~~~~~~~~~~~
dragon2.cpp:178: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]
  178 |             for (j = 0; j < pos2[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~
dragon2.cpp:188:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  188 |             for (j = 0; j < ee.size(); j++) {
      |                         ~~^~~~~~~~~~~
dragon2.cpp:191:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<angle>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  191 |                     for (k = p+1; k <= poss.size(); k += k & (-k)) bit[k]++;
      |                                   ~~^~~~~~~~~~~~~~
dragon2.cpp:112:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
dragon2.cpp:113:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |     for (i = 0; i < N; i++) scanf("%d %d %d",&A,&B,&C),pos[C-1].pb(mp(A,B));
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:114:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |     scanf("%d %d %d %d",&a.x,&a.y,&b.x,&b.y);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:131:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |     scanf("%d",&Q);
      |     ~~~~~^~~~~~~~~
dragon2.cpp:133:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  133 |         scanf("%d %d",&F,&G),F--,G--;
      |         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 7908 KB Output is correct
2 Correct 58 ms 9168 KB Output is correct
3 Correct 153 ms 26236 KB Output is correct
4 Correct 225 ms 42448 KB Output is correct
5 Correct 111 ms 19308 KB Output is correct
6 Correct 13 ms 8688 KB Output is correct
7 Correct 13 ms 8768 KB Output is correct
8 Correct 30 ms 7584 KB Output is correct
9 Correct 25 ms 7512 KB Output is correct
10 Correct 27 ms 7776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 331 ms 36204 KB Output is correct
2 Correct 523 ms 50148 KB Output is correct
3 Correct 238 ms 34860 KB Output is correct
4 Correct 171 ms 36120 KB Output is correct
5 Correct 115 ms 42768 KB Output is correct
6 Correct 293 ms 40100 KB Output is correct
7 Correct 289 ms 40084 KB Output is correct
8 Correct 320 ms 38912 KB Output is correct
9 Correct 260 ms 37612 KB Output is correct
10 Correct 323 ms 40076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 7908 KB Output is correct
2 Correct 58 ms 9168 KB Output is correct
3 Correct 153 ms 26236 KB Output is correct
4 Correct 225 ms 42448 KB Output is correct
5 Correct 111 ms 19308 KB Output is correct
6 Correct 13 ms 8688 KB Output is correct
7 Correct 13 ms 8768 KB Output is correct
8 Correct 30 ms 7584 KB Output is correct
9 Correct 25 ms 7512 KB Output is correct
10 Correct 27 ms 7776 KB Output is correct
11 Correct 331 ms 36204 KB Output is correct
12 Correct 523 ms 50148 KB Output is correct
13 Correct 238 ms 34860 KB Output is correct
14 Correct 171 ms 36120 KB Output is correct
15 Correct 115 ms 42768 KB Output is correct
16 Correct 293 ms 40100 KB Output is correct
17 Correct 289 ms 40084 KB Output is correct
18 Correct 320 ms 38912 KB Output is correct
19 Correct 260 ms 37612 KB Output is correct
20 Correct 323 ms 40076 KB Output is correct
21 Correct 327 ms 37424 KB Output is correct
22 Correct 468 ms 48652 KB Output is correct
23 Correct 2001 ms 228472 KB Output is correct
24 Runtime error 1867 ms 262148 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -