Submission #997976

# Submission time Handle Problem Language Result Execution time Memory
997976 2024-06-13T07:25:59 Z toan2602 Examination (JOI19_examination) C++14
43 / 100
1178 ms 95260 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long
int n, d = 0, q, x[100005], y[100005], z[100005], cnt[200005];
bool mark[500005], Q[500005];
set<int> s;

struct NODE {
    int x, y, z, idx;
    bool operator < (NODE b) {
        if(x != b.x) return x < b.x;
        else if(y != b.y) return y < b.y;
        else if(z != b.z) return z < b.z;
        else return idx > b.idx;
    }
} node[500005];

int bit[500005];

void update(int pos, int val) {
    while(pos <= d) {
        bit[pos] += val;
        pos += pos & -pos;
    }
}

int get(int pos) {
    int res = 0;
    while(pos > 0) {
        res += bit[pos];
        pos -= pos & -pos;
    }
    return res;
}

int range(int l, int r) {
    return get(r) - get(l-1);
}

void cdq(int l, int r) {
    int mid = (l + r) / 2;
    if(l == r) return;
    cdq(l, mid);
    cdq(mid + 1, r);
    for (int i = mid + 1; i <= r; i++) {
        if(!Q[node[i].idx]) update(node[i].z, 1);
    }
    vector<NODE> v;
    int p1;
    p1 = mid+1;
    for (int i = l; i <= mid; i++) {
        while(p1 <= r && node[p1].y < node[i].y) {
            v.push_back(node[p1]);
            if(!Q[node[p1].idx]) update(node[p1].z, -1);
            p1++;
        }
        v.push_back(node[i]);
        cnt[node[i].idx] += range(node[i].z, d);
    }
    while(p1 <= r) {
        v.push_back(node[p1]);
        if(!Q[node[p1].idx]) update(node[p1].z, -1);
        p1++;
    }
    for (int i = l; i <= r; i++) {
        node[i] = v[i-l];
    }
    return;
}
map<int, int> mp;

signed main() {
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> node[i].x >> node[i].y;
        node[i].z = node[i].x + node[i].y;
        s.insert(node[i].x);
        s.insert(node[i].y);
        s.insert(node[i].z);
        node[i].idx = i;
    }
    for (int i = 1; i <= q; i++) {
        cin >> x[i] >> y[i] >> z[i];
        s.insert(x[i]);
        s.insert(y[i]);
        s.insert(z[i]);
    }
    for (int i: s) mp[i] = ++d;
    for (int i = 1; i <= n; i++) {
        node[i].x = mp[node[i].x];
        node[i].y = mp[node[i].y];
        node[i].z = mp[node[i].z];
        //cout << node[i].x << ' ' << node[i].y << ' ' << node[i].z << '\n';
    }
    for (int i = 1; i <= q; i++) {
        x[i] = mp[x[i]];
        y[i] = mp[y[i]];
        z[i] = mp[z[i]];
        node[i+n] = {x[i], y[i], z[i], i + n};
        Q[i+n] = true;
    }
    sort(node + 1, node + 1 + q + n);
    cdq(1, n+q);
    for (int i = 1; i <= q; i++) {
        cout << cnt[i+n] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 17 ms 9116 KB Output is correct
8 Correct 16 ms 9116 KB Output is correct
9 Correct 16 ms 9064 KB Output is correct
10 Correct 12 ms 8344 KB Output is correct
11 Correct 12 ms 8344 KB Output is correct
12 Correct 5 ms 6960 KB Output is correct
13 Correct 15 ms 8736 KB Output is correct
14 Correct 13 ms 8708 KB Output is correct
15 Correct 14 ms 8732 KB Output is correct
16 Correct 8 ms 7580 KB Output is correct
17 Correct 10 ms 8024 KB Output is correct
18 Correct 5 ms 7064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 518 ms 43904 KB Output is correct
2 Correct 482 ms 43048 KB Output is correct
3 Correct 480 ms 44464 KB Output is correct
4 Correct 372 ms 39752 KB Output is correct
5 Correct 407 ms 40604 KB Output is correct
6 Correct 182 ms 28068 KB Output is correct
7 Correct 460 ms 43760 KB Output is correct
8 Correct 465 ms 44896 KB Output is correct
9 Correct 463 ms 43384 KB Output is correct
10 Correct 316 ms 40012 KB Output is correct
11 Correct 326 ms 38376 KB Output is correct
12 Correct 124 ms 27352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 518 ms 43904 KB Output is correct
2 Correct 482 ms 43048 KB Output is correct
3 Correct 480 ms 44464 KB Output is correct
4 Correct 372 ms 39752 KB Output is correct
5 Correct 407 ms 40604 KB Output is correct
6 Correct 182 ms 28068 KB Output is correct
7 Correct 460 ms 43760 KB Output is correct
8 Correct 465 ms 44896 KB Output is correct
9 Correct 463 ms 43384 KB Output is correct
10 Correct 316 ms 40012 KB Output is correct
11 Correct 326 ms 38376 KB Output is correct
12 Correct 124 ms 27352 KB Output is correct
13 Correct 578 ms 46132 KB Output is correct
14 Correct 524 ms 45660 KB Output is correct
15 Correct 485 ms 43720 KB Output is correct
16 Correct 444 ms 38740 KB Output is correct
17 Correct 402 ms 40076 KB Output is correct
18 Correct 161 ms 28304 KB Output is correct
19 Correct 569 ms 47004 KB Output is correct
20 Correct 573 ms 45744 KB Output is correct
21 Correct 545 ms 45932 KB Output is correct
22 Correct 315 ms 38860 KB Output is correct
23 Correct 326 ms 37596 KB Output is correct
24 Correct 139 ms 27044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 17 ms 9116 KB Output is correct
8 Correct 16 ms 9116 KB Output is correct
9 Correct 16 ms 9064 KB Output is correct
10 Correct 12 ms 8344 KB Output is correct
11 Correct 12 ms 8344 KB Output is correct
12 Correct 5 ms 6960 KB Output is correct
13 Correct 15 ms 8736 KB Output is correct
14 Correct 13 ms 8708 KB Output is correct
15 Correct 14 ms 8732 KB Output is correct
16 Correct 8 ms 7580 KB Output is correct
17 Correct 10 ms 8024 KB Output is correct
18 Correct 5 ms 7064 KB Output is correct
19 Correct 518 ms 43904 KB Output is correct
20 Correct 482 ms 43048 KB Output is correct
21 Correct 480 ms 44464 KB Output is correct
22 Correct 372 ms 39752 KB Output is correct
23 Correct 407 ms 40604 KB Output is correct
24 Correct 182 ms 28068 KB Output is correct
25 Correct 460 ms 43760 KB Output is correct
26 Correct 465 ms 44896 KB Output is correct
27 Correct 463 ms 43384 KB Output is correct
28 Correct 316 ms 40012 KB Output is correct
29 Correct 326 ms 38376 KB Output is correct
30 Correct 124 ms 27352 KB Output is correct
31 Correct 578 ms 46132 KB Output is correct
32 Correct 524 ms 45660 KB Output is correct
33 Correct 485 ms 43720 KB Output is correct
34 Correct 444 ms 38740 KB Output is correct
35 Correct 402 ms 40076 KB Output is correct
36 Correct 161 ms 28304 KB Output is correct
37 Correct 569 ms 47004 KB Output is correct
38 Correct 573 ms 45744 KB Output is correct
39 Correct 545 ms 45932 KB Output is correct
40 Correct 315 ms 38860 KB Output is correct
41 Correct 326 ms 37596 KB Output is correct
42 Correct 139 ms 27044 KB Output is correct
43 Incorrect 1178 ms 95260 KB Output isn't correct
44 Halted 0 ms 0 KB -