Submission #894781

# Submission time Handle Problem Language Result Execution time Memory
894781 2023-12-29T02:07:45 Z 12345678 Examination (JOI19_examination) C++17
0 / 100
131 ms 11288 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) 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);
    /*
    if (l==1&r==9)
    {
        cout<<"answer "<<ans[2]<<'\n';
        cout<<"left: \n";
        for (int i=l; i<=md; i++) cout<<p[i].x<<' '<<p[i].y<<' '<<p[i].z<<' '<<p[i].i<<'\n';
        cout<<"right\n";
        for (int i=md+1; i<=r; i++) cout<<p[i].x<<' '<<p[i].y<<' '<<p[i].z<<' '<<p[i].i<<'\n';
        cout<<'\n';
    }*/
    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];
    //cout<<"value "<<l<<' '<<r<<' '<<ans[2]<<'\n';
}

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';
}

/*
2 3
2 5
2 4
1 6 17
10 2 3
5 2 2
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Runtime error 4 ms 8796 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 130 ms 11288 KB Output is correct
2 Incorrect 131 ms 11272 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 130 ms 11288 KB Output is correct
2 Incorrect 131 ms 11272 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Runtime error 4 ms 8796 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -