Submission #410494

# Submission time Handle Problem Language Result Execution time Memory
410494 2021-05-22T19:48:36 Z duality Dragon 2 (JOI17_dragon2) C++11
60 / 100
2040 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;
    int 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];
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];
            vector<angle> poss;
            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);
        }
    }
    for (i = 0; i < Q; i++) printf("%d\n",ans[i]);

    return 0;
}

Compilation message

dragon2.cpp: In function 'int main()':
dragon2.cpp:117: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]
  117 |         for (j = 0; j < pos[i].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~
dragon2.cpp:133: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]
  133 |             for (j = 0; j < pos2[F].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~
dragon2.cpp:145: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]
  145 |             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:110:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
dragon2.cpp:111:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |     for (i = 0; i < N; i++) scanf("%d %d %d",&A,&B,&C),pos[C-1].pb(mp(A,B));
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~
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 %d %d",&a.x,&a.y,&b.x,&b.y);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:129:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |     scanf("%d",&Q);
      |     ~~~~~^~~~~~~~~
dragon2.cpp:131:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |         scanf("%d %d",&F,&G),F--,G--;
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 7284 KB Output is correct
2 Correct 41 ms 8532 KB Output is correct
3 Correct 159 ms 25672 KB Output is correct
4 Correct 250 ms 43000 KB Output is correct
5 Correct 93 ms 18712 KB Output is correct
6 Correct 13 ms 8140 KB Output is correct
7 Correct 13 ms 8140 KB Output is correct
8 Correct 27 ms 6932 KB Output is correct
9 Correct 25 ms 6832 KB Output is correct
10 Correct 26 ms 7024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 325 ms 35108 KB Output is correct
2 Correct 474 ms 51276 KB Output is correct
3 Correct 250 ms 34768 KB Output is correct
4 Correct 166 ms 36236 KB Output is correct
5 Correct 107 ms 42836 KB Output is correct
6 Correct 312 ms 39532 KB Output is correct
7 Correct 290 ms 39416 KB Output is correct
8 Correct 309 ms 38068 KB Output is correct
9 Correct 250 ms 36568 KB Output is correct
10 Correct 280 ms 39212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 7284 KB Output is correct
2 Correct 41 ms 8532 KB Output is correct
3 Correct 159 ms 25672 KB Output is correct
4 Correct 250 ms 43000 KB Output is correct
5 Correct 93 ms 18712 KB Output is correct
6 Correct 13 ms 8140 KB Output is correct
7 Correct 13 ms 8140 KB Output is correct
8 Correct 27 ms 6932 KB Output is correct
9 Correct 25 ms 6832 KB Output is correct
10 Correct 26 ms 7024 KB Output is correct
11 Correct 325 ms 35108 KB Output is correct
12 Correct 474 ms 51276 KB Output is correct
13 Correct 250 ms 34768 KB Output is correct
14 Correct 166 ms 36236 KB Output is correct
15 Correct 107 ms 42836 KB Output is correct
16 Correct 312 ms 39532 KB Output is correct
17 Correct 290 ms 39416 KB Output is correct
18 Correct 309 ms 38068 KB Output is correct
19 Correct 250 ms 36568 KB Output is correct
20 Correct 280 ms 39212 KB Output is correct
21 Correct 324 ms 34980 KB Output is correct
22 Correct 455 ms 48992 KB Output is correct
23 Correct 2040 ms 233776 KB Output is correct
24 Runtime error 298 ms 262148 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -