Submission #240621

# Submission time Handle Problem Language Result Execution time Memory
240621 2020-06-20T09:46:10 Z osaaateiasavtnl Dragon 2 (JOI17_dragon2) C++14
100 / 100
698 ms 9724 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int N = 30007;
struct Point {
    int x, y, c;
    Point operator - (Point p) {
        return {x - p.x, y - p.y};
    }   
    Point operator + (Point p) {
        return {x + p.x, y + p.y};
    }   
    int operator *(Point p) {
        return x * p.y - y * p.x;
    }   
} a[N];  
int sign(int x) {
    if (x < 0)
        return -1;
    else if (x == 0)
        return 0;
    else
        return 1;
}   

vector <Point> cA[N][2], cB[N][2];
vector <Point> al[N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i].x >> a[i].y >> a[i].c;
    }   
    Point A, B;
    cin >> A.x >> A.y;
    cin >> B.x >> B.y;

    auto half = [&](Point p) {
        int ans = (p - A) * (B - A) > 0;
        return ans;
    };     

    for (int i = 1; i <= n; ++i) {
        cA[a[i].c][half(a[i])].app(a[i]);
        cB[a[i].c][half(a[i])].app(a[i]);
        al[a[i].c].app(a[i]);
    }   

    auto compA = [&](Point a, Point b) {
        return (a - A) * (b - A) > 0;
    };
    auto compB = [&](Point a, Point b) {
        return (a - B) * (b - B) > 0;
    };

    for (int i = 1; i <= m; ++i) {
        for (int j = 0; j < 2; ++j) {
            sort(all(cA[i][j]), compA);
            sort(all(cB[i][j]), compB);
        }   
    }   

    int q;
    cin >> q;
    while (q--) {
        int c1, c2;
        cin >> c1 >> c2;
        
        int ans = 0;
        if (al[c2].size() < al[c1].size()) {

            swap(c1, c2);
            for (auto a : al[c1]) {
                int t = half(a);

                {
                int l = -1, r = cA[c2][t^1].size();
                auto sim = A + (A - a);
                while (l < r - 1) {
                    int m = (l + r) >> 1;
                    if (compA(cA[c2][t^1][m], sim))
                        l = m;
                    else
                        r = m;
                }
                if ((A - a) * (B - a) > 0) {   
                    ans -= r;
                }
                else {
                    ans += r;
                }   
                }

                {
                int l = -1, r = cB[c2][t^1].size();
                auto sim = B + (B - a);
                while (l < r - 1) {
                    int m = (l + r) >> 1;
                    if (compB(cB[c2][t^1][m], sim)) 
                        l = m;
                    else
                        r = m;
                }   
                if ((A - a) * (B - a) > 0) {   
                    ans += r;
                }
                else {
                    ans -= r;
                }   
                }

                if ((A - a) * (B - a) > 0) {
                    for (auto b : cA[c2][t]) {
                        if (compA(a, b) && compB(b, a)) {
                            ++ans;
                        }   
                    }   
                }   
                else {
                    for (auto b : cA[c2][t]) {
                        if (compA(b, a) && compB(a, b)) {
                            ++ans;
                        }   
                    }   
                }

            }
        }
        else {
            for (auto a : al[c1]) {
                int t = half(a);
     
                {
                int l = -1, r = cA[c2][t^1].size();
                auto sim = A + (A - a);
                while (l < r - 1) {
                    int m = (l + r) >> 1;
                    if (compA(cA[c2][t^1][m], sim))
                        l = m;
                    else
                        r = m;
                }
                if ((A - a) * (B - a) > 0) {   
                    ans -= r;
                }
                else {
                    ans += r;
                }   
                }
     
                {
                int l = -1, r = cB[c2][t^1].size();
                auto sim = B + (B - a);
                while (l < r - 1) {
                    int m = (l + r) >> 1;
                    if (compB(cB[c2][t^1][m], sim)) 
                        l = m;
                    else
                        r = m;
                }   
                if ((A - a) * (B - a) > 0) {   
                    ans += r;
                }
                else {
                    ans -= r;
                }   
                } 
                if ((A - a) * (B - a) > 0) {
                    for (auto b : cA[c2][t]) {
                        if (compA(b, a) && compB(a, b)) {
                            ++ans;
                        }   
                    }   
                }   
                else {
                    for (auto b : cA[c2][t]) {
                        if (compA(a, b) && compB(b, a)) {
                            ++ans;
                        }   
                    }   
                }   
            }
        }   

        cout << ans << endl;
    }   
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4224 KB Output is correct
2 Correct 15 ms 4224 KB Output is correct
3 Correct 26 ms 4324 KB Output is correct
4 Correct 47 ms 4472 KB Output is correct
5 Correct 37 ms 4480 KB Output is correct
6 Correct 8 ms 4224 KB Output is correct
7 Correct 9 ms 4224 KB Output is correct
8 Correct 8 ms 4224 KB Output is correct
9 Correct 10 ms 4224 KB Output is correct
10 Correct 8 ms 4224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 275 ms 7272 KB Output is correct
2 Correct 534 ms 7928 KB Output is correct
3 Correct 48 ms 7936 KB Output is correct
4 Correct 25 ms 7808 KB Output is correct
5 Correct 36 ms 7424 KB Output is correct
6 Correct 475 ms 6984 KB Output is correct
7 Correct 457 ms 6988 KB Output is correct
8 Correct 26 ms 6876 KB Output is correct
9 Correct 298 ms 7092 KB Output is correct
10 Correct 20 ms 6760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4224 KB Output is correct
2 Correct 15 ms 4224 KB Output is correct
3 Correct 26 ms 4324 KB Output is correct
4 Correct 47 ms 4472 KB Output is correct
5 Correct 37 ms 4480 KB Output is correct
6 Correct 8 ms 4224 KB Output is correct
7 Correct 9 ms 4224 KB Output is correct
8 Correct 8 ms 4224 KB Output is correct
9 Correct 10 ms 4224 KB Output is correct
10 Correct 8 ms 4224 KB Output is correct
11 Correct 275 ms 7272 KB Output is correct
12 Correct 534 ms 7928 KB Output is correct
13 Correct 48 ms 7936 KB Output is correct
14 Correct 25 ms 7808 KB Output is correct
15 Correct 36 ms 7424 KB Output is correct
16 Correct 475 ms 6984 KB Output is correct
17 Correct 457 ms 6988 KB Output is correct
18 Correct 26 ms 6876 KB Output is correct
19 Correct 298 ms 7092 KB Output is correct
20 Correct 20 ms 6760 KB Output is correct
21 Correct 267 ms 7396 KB Output is correct
22 Correct 539 ms 7800 KB Output is correct
23 Correct 698 ms 8180 KB Output is correct
24 Correct 412 ms 8184 KB Output is correct
25 Correct 72 ms 7800 KB Output is correct
26 Correct 72 ms 7672 KB Output is correct
27 Correct 30 ms 7424 KB Output is correct
28 Correct 30 ms 7424 KB Output is correct
29 Correct 463 ms 7852 KB Output is correct
30 Correct 65 ms 8876 KB Output is correct
31 Correct 61 ms 9140 KB Output is correct
32 Correct 69 ms 9592 KB Output is correct
33 Correct 348 ms 9724 KB Output is correct
34 Correct 72 ms 9592 KB Output is correct
35 Correct 64 ms 9336 KB Output is correct
36 Correct 72 ms 9336 KB Output is correct
37 Correct 75 ms 9592 KB Output is correct
38 Correct 496 ms 9720 KB Output is correct
39 Correct 355 ms 9336 KB Output is correct
40 Correct 320 ms 9592 KB Output is correct
41 Correct 451 ms 9080 KB Output is correct
42 Correct 484 ms 9080 KB Output is correct
43 Correct 389 ms 9336 KB Output is correct
44 Correct 314 ms 7988 KB Output is correct
45 Correct 203 ms 8064 KB Output is correct
46 Correct 144 ms 8568 KB Output is correct
47 Correct 395 ms 8248 KB Output is correct
48 Correct 157 ms 8184 KB Output is correct
49 Correct 126 ms 8064 KB Output is correct