답안 #894783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894783 2023-12-29T02:12:11 Z 12345678 Examination (JOI19_examination) C++17
0 / 100
137 ms 12892 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[1000005];
    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 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6616 KB Output is correct
4 Runtime error 7 ms 12892 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 135 ms 9856 KB Output is correct
2 Correct 137 ms 9688 KB Output is correct
3 Correct 129 ms 9676 KB Output is correct
4 Correct 114 ms 9668 KB Output is correct
5 Correct 118 ms 10068 KB Output is correct
6 Incorrect 93 ms 9808 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 135 ms 9856 KB Output is correct
2 Correct 137 ms 9688 KB Output is correct
3 Correct 129 ms 9676 KB Output is correct
4 Correct 114 ms 9668 KB Output is correct
5 Correct 118 ms 10068 KB Output is correct
6 Incorrect 93 ms 9808 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6616 KB Output is correct
4 Runtime error 7 ms 12892 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -