답안 #997970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
997970 2024-06-13T07:23:45 Z toan2602 Examination (JOI19_examination) C++14
43 / 100
1158 ms 96312 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 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';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 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 16 ms 9116 KB Output is correct
8 Correct 16 ms 9076 KB Output is correct
9 Correct 15 ms 9116 KB Output is correct
10 Correct 12 ms 8348 KB Output is correct
11 Correct 12 ms 8344 KB Output is correct
12 Correct 8 ms 6940 KB Output is correct
13 Correct 14 ms 8736 KB Output is correct
14 Correct 14 ms 8676 KB Output is correct
15 Correct 14 ms 8736 KB Output is correct
16 Correct 9 ms 7580 KB Output is correct
17 Correct 10 ms 8004 KB Output is correct
18 Correct 6 ms 6944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 496 ms 42952 KB Output is correct
2 Correct 524 ms 43204 KB Output is correct
3 Correct 528 ms 44180 KB Output is correct
4 Correct 392 ms 40096 KB Output is correct
5 Correct 383 ms 38728 KB Output is correct
6 Correct 159 ms 28592 KB Output is correct
7 Correct 492 ms 42620 KB Output is correct
8 Correct 522 ms 45112 KB Output is correct
9 Correct 451 ms 41856 KB Output is correct
10 Correct 372 ms 38528 KB Output is correct
11 Correct 358 ms 38624 KB Output is correct
12 Correct 132 ms 26584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 496 ms 42952 KB Output is correct
2 Correct 524 ms 43204 KB Output is correct
3 Correct 528 ms 44180 KB Output is correct
4 Correct 392 ms 40096 KB Output is correct
5 Correct 383 ms 38728 KB Output is correct
6 Correct 159 ms 28592 KB Output is correct
7 Correct 492 ms 42620 KB Output is correct
8 Correct 522 ms 45112 KB Output is correct
9 Correct 451 ms 41856 KB Output is correct
10 Correct 372 ms 38528 KB Output is correct
11 Correct 358 ms 38624 KB Output is correct
12 Correct 132 ms 26584 KB Output is correct
13 Correct 588 ms 47372 KB Output is correct
14 Correct 534 ms 45736 KB Output is correct
15 Correct 526 ms 43604 KB Output is correct
16 Correct 442 ms 40236 KB Output is correct
17 Correct 469 ms 39280 KB Output is correct
18 Correct 163 ms 26956 KB Output is correct
19 Correct 643 ms 48000 KB Output is correct
20 Correct 588 ms 45456 KB Output is correct
21 Correct 640 ms 45760 KB Output is correct
22 Correct 364 ms 38192 KB Output is correct
23 Correct 355 ms 37096 KB Output is correct
24 Correct 131 ms 27548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 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 16 ms 9116 KB Output is correct
8 Correct 16 ms 9076 KB Output is correct
9 Correct 15 ms 9116 KB Output is correct
10 Correct 12 ms 8348 KB Output is correct
11 Correct 12 ms 8344 KB Output is correct
12 Correct 8 ms 6940 KB Output is correct
13 Correct 14 ms 8736 KB Output is correct
14 Correct 14 ms 8676 KB Output is correct
15 Correct 14 ms 8736 KB Output is correct
16 Correct 9 ms 7580 KB Output is correct
17 Correct 10 ms 8004 KB Output is correct
18 Correct 6 ms 6944 KB Output is correct
19 Correct 496 ms 42952 KB Output is correct
20 Correct 524 ms 43204 KB Output is correct
21 Correct 528 ms 44180 KB Output is correct
22 Correct 392 ms 40096 KB Output is correct
23 Correct 383 ms 38728 KB Output is correct
24 Correct 159 ms 28592 KB Output is correct
25 Correct 492 ms 42620 KB Output is correct
26 Correct 522 ms 45112 KB Output is correct
27 Correct 451 ms 41856 KB Output is correct
28 Correct 372 ms 38528 KB Output is correct
29 Correct 358 ms 38624 KB Output is correct
30 Correct 132 ms 26584 KB Output is correct
31 Correct 588 ms 47372 KB Output is correct
32 Correct 534 ms 45736 KB Output is correct
33 Correct 526 ms 43604 KB Output is correct
34 Correct 442 ms 40236 KB Output is correct
35 Correct 469 ms 39280 KB Output is correct
36 Correct 163 ms 26956 KB Output is correct
37 Correct 643 ms 48000 KB Output is correct
38 Correct 588 ms 45456 KB Output is correct
39 Correct 640 ms 45760 KB Output is correct
40 Correct 364 ms 38192 KB Output is correct
41 Correct 355 ms 37096 KB Output is correct
42 Correct 131 ms 27548 KB Output is correct
43 Incorrect 1158 ms 96312 KB Output isn't correct
44 Halted 0 ms 0 KB -