답안 #894782

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894782 2023-12-29T02:11:48 Z 12345678 Examination (JOI19_examination) C++17
0 / 100
147 ms 11264 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) 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)
    {
        i++;
        while (i<nx) d[i]+=vl, i+=(i&-i);
    }
    int query(int i)
    {
        i++;
        int res=0;
        while (i>0) res+=d[i], i-=(i&-i);
        return res;
    }
} f;

int n, q, a, b, c, ans[nx];

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(p[i].z, 1);
            i++;
        }
        else
        {
            tmp[idx++]=p[j];
            if (p[j].i!=0) ans[p[j].i]+=f.query(nx-2)-f.query(p[j].z-1);
            j++;
        }
    }
    for (int i=l; i<=md; i++) if (p[i].i==0) f.add(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++) cout<<p[i].x<<' '<<p[i].y<<' '<<p[i].z<<' '<<p[i].i<<'\n';
    solve(1, n+q);
    for (int i=1; i<=q; i++) cout<<ans[i]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Runtime error 4 ms 8796 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 8588 KB Output is correct
2 Correct 147 ms 8768 KB Output is correct
3 Correct 136 ms 11264 KB Output is correct
4 Correct 115 ms 10580 KB Output is correct
5 Correct 112 ms 10348 KB Output is correct
6 Incorrect 96 ms 9868 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 8588 KB Output is correct
2 Correct 147 ms 8768 KB Output is correct
3 Correct 136 ms 11264 KB Output is correct
4 Correct 115 ms 10580 KB Output is correct
5 Correct 112 ms 10348 KB Output is correct
6 Incorrect 96 ms 9868 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Runtime error 4 ms 8796 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -