답안 #894785

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894785 2023-12-29T02:23:45 Z 12345678 Examination (JOI19_examination) C++17
100 / 100
722 ms 23048 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=2e5+5;

struct point
{
    int x, y, z, i;
    bool operator< (const point &o) const
    {
        if (x==o.x&&y==o.y&&z==o.z) return i<o.i;
        if (x==o.x&&y==o.y) return z>o.z;
        if (x==o.x) return y>o.y;
        return x>o.x;
    }
} p[nx], tmp[nx];

struct fenwick
{
    int d[nx];
    void add(int i, int vl)
    {
        while (i<nx) d[i]+=vl, i+=(i&-i);
    }
    int query(int i)
    {
        int res=0;
        while (i>0) res+=d[i], i-=(i&-i);
        return res;
    }
} f;

int n, q, ans[nx], t;
map<int, int> mp;

void solve(int l, int r)
{
    if (l==r) return;
    int md=(l+r)/2, idx=l;
    solve(l, md);
    solve(md+1, r);
    for (int i=l, j=md+1; idx<=r;)
    {
        if (j>r||(i<=md&&p[i].y>=p[j].y))
        {
            tmp[idx++]=p[i];
            if (p[i].i==0) f.add(mp[p[i].z], 1);
            i++;
        }
        else
        {
            tmp[idx++]=p[j];
            if (p[j].i!=0) ans[p[j].i]+=f.query(nx-1)-f.query(mp[p[j].z]-1);
            j++;
        }
    }
    for (int i=l; i<=md; i++) if (p[i].i==0) f.add(mp[p[i].z], -1);
    for (int i=l; i<=r; i++) p[i]=tmp[i];
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>q;
    for (int i=1; i<=n; i++) cin>>p[i].x>>p[i].y, p[i].z=p[i].x+p[i].y, p[i].i=0;
    for (int i=1; i<=q; i++) cin>>p[i+n].x>>p[i+n].y>>p[i+n].z, p[i+n].i=i;
    sort(p+1, p+n+q+1);
    for (int i=1; i<=n+q; i++) mp[p[i].z]=0;
    for (auto &[x, y]:mp) y=++t;
    solve(1, n+q);
    for (int i=1; i<=q; i++) cout<<ans[i]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4564 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 9 ms 4932 KB Output is correct
8 Correct 10 ms 4952 KB Output is correct
9 Correct 9 ms 5012 KB Output is correct
10 Correct 10 ms 5208 KB Output is correct
11 Correct 8 ms 4952 KB Output is correct
12 Correct 4 ms 4440 KB Output is correct
13 Correct 7 ms 4840 KB Output is correct
14 Correct 7 ms 4700 KB Output is correct
15 Correct 7 ms 4844 KB Output is correct
16 Correct 7 ms 4700 KB Output is correct
17 Correct 8 ms 4956 KB Output is correct
18 Correct 4 ms 4600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 409 ms 12228 KB Output is correct
2 Correct 390 ms 12112 KB Output is correct
3 Correct 374 ms 12380 KB Output is correct
4 Correct 240 ms 11736 KB Output is correct
5 Correct 271 ms 11732 KB Output is correct
6 Correct 98 ms 8784 KB Output is correct
7 Correct 378 ms 12368 KB Output is correct
8 Correct 347 ms 12456 KB Output is correct
9 Correct 372 ms 12116 KB Output is correct
10 Correct 273 ms 11492 KB Output is correct
11 Correct 282 ms 11604 KB Output is correct
12 Correct 88 ms 8276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 409 ms 12228 KB Output is correct
2 Correct 390 ms 12112 KB Output is correct
3 Correct 374 ms 12380 KB Output is correct
4 Correct 240 ms 11736 KB Output is correct
5 Correct 271 ms 11732 KB Output is correct
6 Correct 98 ms 8784 KB Output is correct
7 Correct 378 ms 12368 KB Output is correct
8 Correct 347 ms 12456 KB Output is correct
9 Correct 372 ms 12116 KB Output is correct
10 Correct 273 ms 11492 KB Output is correct
11 Correct 282 ms 11604 KB Output is correct
12 Correct 88 ms 8276 KB Output is correct
13 Correct 580 ms 14560 KB Output is correct
14 Correct 578 ms 13920 KB Output is correct
15 Correct 392 ms 12112 KB Output is correct
16 Correct 388 ms 12628 KB Output is correct
17 Correct 422 ms 12932 KB Output is correct
18 Correct 100 ms 8772 KB Output is correct
19 Correct 577 ms 14608 KB Output is correct
20 Correct 585 ms 14208 KB Output is correct
21 Correct 571 ms 14404 KB Output is correct
22 Correct 300 ms 11604 KB Output is correct
23 Correct 284 ms 11476 KB Output is correct
24 Correct 90 ms 8260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4564 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 9 ms 4932 KB Output is correct
8 Correct 10 ms 4952 KB Output is correct
9 Correct 9 ms 5012 KB Output is correct
10 Correct 10 ms 5208 KB Output is correct
11 Correct 8 ms 4952 KB Output is correct
12 Correct 4 ms 4440 KB Output is correct
13 Correct 7 ms 4840 KB Output is correct
14 Correct 7 ms 4700 KB Output is correct
15 Correct 7 ms 4844 KB Output is correct
16 Correct 7 ms 4700 KB Output is correct
17 Correct 8 ms 4956 KB Output is correct
18 Correct 4 ms 4600 KB Output is correct
19 Correct 409 ms 12228 KB Output is correct
20 Correct 390 ms 12112 KB Output is correct
21 Correct 374 ms 12380 KB Output is correct
22 Correct 240 ms 11736 KB Output is correct
23 Correct 271 ms 11732 KB Output is correct
24 Correct 98 ms 8784 KB Output is correct
25 Correct 378 ms 12368 KB Output is correct
26 Correct 347 ms 12456 KB Output is correct
27 Correct 372 ms 12116 KB Output is correct
28 Correct 273 ms 11492 KB Output is correct
29 Correct 282 ms 11604 KB Output is correct
30 Correct 88 ms 8276 KB Output is correct
31 Correct 580 ms 14560 KB Output is correct
32 Correct 578 ms 13920 KB Output is correct
33 Correct 392 ms 12112 KB Output is correct
34 Correct 388 ms 12628 KB Output is correct
35 Correct 422 ms 12932 KB Output is correct
36 Correct 100 ms 8772 KB Output is correct
37 Correct 577 ms 14608 KB Output is correct
38 Correct 585 ms 14208 KB Output is correct
39 Correct 571 ms 14404 KB Output is correct
40 Correct 300 ms 11604 KB Output is correct
41 Correct 284 ms 11476 KB Output is correct
42 Correct 90 ms 8260 KB Output is correct
43 Correct 672 ms 22940 KB Output is correct
44 Correct 670 ms 23048 KB Output is correct
45 Correct 650 ms 22960 KB Output is correct
46 Correct 476 ms 21484 KB Output is correct
47 Correct 491 ms 21584 KB Output is correct
48 Correct 116 ms 9560 KB Output is correct
49 Correct 722 ms 22980 KB Output is correct
50 Correct 650 ms 22968 KB Output is correct
51 Correct 696 ms 22800 KB Output is correct
52 Correct 395 ms 21332 KB Output is correct
53 Correct 318 ms 15728 KB Output is correct