Submission #985988

# Submission time Handle Problem Language Result Execution time Memory
985988 2024-05-19T14:29:41 Z andrei_boaca Examination (JOI19_examination) C++17
43 / 100
909 ms 90304 KB
#include <bits/stdc++.h>

using namespace std;
int n,q,sol[100005];
vector<int> vals[4*100005],aint[4*100005];
int nrx,nry;
struct point
{
    int x,y,z;
} v[100005];
struct date
{
    int x,y,z,ind;
} qr[100005];
vector<int> vx,vy;
map<int,int> nrmx,nrmy;
bool byz(point a,point b)
{
    return a.z>b.z;
}
bool comp(date a, date b)
{
    return a.z>b.z;
}
void plsput(int nod,int st,int dr,int x,int y)
{
    vals[nod].push_back(y);
    if(st==dr)
        return;
    int mij=(st+dr)/2;
    if(x<=mij)
        plsput(nod*2,st,mij,x,y);
    else
        plsput(nod*2+1,mij+1,dr,x,y);
}
int getpoz(int ind,int val)
{
    int poz=vals[ind].size();
    poz++;
    int st=0;
    int dr=vals[ind].size();
    dr--;
    while(st<=dr)
    {
        int mij=(st+dr)/2;
        if(vals[ind][mij]>=val)
        {
            poz=mij+1;
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    return poz;
}
void build(int nod,int st,int dr)
{
    sort(vals[nod].begin(),vals[nod].end());
    vals[nod].erase(unique(vals[nod].begin(),vals[nod].end()),vals[nod].end());
    int lg=vals[nod].size();
    aint[nod].resize(4*lg+5);
    if(st==dr)
        return;
    int mij=(st+dr)/2;
    build(nod*2,st,mij);
    build(nod*2+1,mij+1,dr);
}
void upd2(int ind,int nod,int st,int dr,int poz,int val)
{
    if(st==dr)
    {
        aint[ind][nod]+=val;
        return;
    }
    int mij=(st+dr)/2;
    if(poz<=mij)
        upd2(ind,nod*2,st,mij,poz,val);
    else
        upd2(ind,nod*2+1,mij+1,dr,poz,val);
    aint[ind][nod]=aint[ind][nod*2]+aint[ind][nod*2+1];
}
int qr2(int ind,int nod,int st,int dr,int a,int b)
{
    if(st>=a&&dr<=b)
        return aint[ind][nod];
    int rez=0;
    int mij=(st+dr)/2;
    if(a<=mij)
        rez+=qr2(ind,nod*2,st,mij,a,b);
    if(b>mij)
        rez+=qr2(ind,nod*2+1,mij+1,dr,a,b);
    return rez;
}
void update(int nod,int st,int dr,int x,int y,int val)
{
    int poz=getpoz(nod,y);
    int lg=vals[nod].size();
    upd2(nod,1,1,lg,poz,val);
    if(st==dr)
        return;
    int mij=(st+dr)/2;
    if(x<=mij)
        update(nod*2,st,mij,x,y,val);
    else
        update(nod*2+1,mij+1,dr,x,y,val);
}
int query(int nod,int st,int dr,int a,int b,int y)
{
    if(st>=a&&dr<=b)
    {
        int poz=getpoz(nod,y);
        if(poz<=vals[nod].size())
            return qr2(nod,1,1,vals[nod].size(),poz,vals[nod].size());
        return 0;
    }
    int rez=0;
    int mij=(st+dr)/2;
    if(a<=mij)
        rez+=query(nod*2,st,mij,a,b,y);
    if(b>mij)
        rez+=query(nod*2+1,mij+1,dr,a,b,y);
    return rez;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i].x>>v[i].y;
        v[i].z=v[i].x+v[i].y;
        vx.push_back(v[i].x);
        vy.push_back(v[i].y);
    }
    for(int i=1;i<=q;i++)
    {
        cin>>qr[i].x>>qr[i].y>>qr[i].z;
        qr[i].ind=i;
        vx.push_back(qr[i].x);
        vy.push_back(qr[i].y);
    }
    sort(vx.begin(),vx.end());
    sort(vy.begin(),vy.end());
    vx.erase(unique(vx.begin(),vx.end()),vx.end());
    vy.erase(unique(vy.begin(),vy.end()),vy.end());
    nrx=vx.size();
    nry=vy.size();
    for(int i=0;i<vx.size();i++)
        nrmx[vx[i]]=i+1;
    for(int i=0;i<vy.size();i++)
        nrmy[vy[i]]=i+1;
    for(int i=1;i<=n;i++)
    {
        v[i].x=nrmx[v[i].x];
        v[i].y=nrmy[v[i].y];
    }
    for(int i=1;i<=q;i++)
    {
        qr[i].x=nrmx[qr[i].x];
        qr[i].y=nrmy[qr[i].y];
    }
    sort(v+1,v+n+1,byz);
    sort(qr+1,qr+q+1,comp);
    for(int i=1;i<=n;i++)
        plsput(1,1,nrx,v[i].x,v[i].y);
    build(1,1,nrx);
    int j=1;
    for(int i=1;i<=q;i++)
    {
        while(j<=n&&v[j].z>=qr[i].z)
        {
            update(1,1,nrx,v[j].x,v[j].y,+1);
            j++;
        }
        sol[qr[i].ind]=query(1,1,nrx,qr[i].x,nrx,qr[i].y);
    }
    for(int i=1;i<=q;i++)
        cout<<sol[i]<<'\n';
    return 0;
}

Compilation message

examination.cpp: In function 'int query(int, int, int, int, int, int)':
examination.cpp:112:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |         if(poz<=vals[nod].size())
      |            ~~~^~~~~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:149:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  149 |     for(int i=0;i<vx.size();i++)
      |                 ~^~~~~~~~~~
examination.cpp:151:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  151 |     for(int i=0;i<vy.size();i++)
      |                 ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21592 KB Output is correct
2 Correct 5 ms 21592 KB Output is correct
3 Correct 6 ms 21596 KB Output is correct
4 Correct 5 ms 21804 KB Output is correct
5 Correct 5 ms 21596 KB Output is correct
6 Correct 5 ms 21596 KB Output is correct
7 Correct 18 ms 23900 KB Output is correct
8 Correct 18 ms 24068 KB Output is correct
9 Correct 18 ms 23900 KB Output is correct
10 Correct 12 ms 23324 KB Output is correct
11 Correct 11 ms 22872 KB Output is correct
12 Correct 8 ms 21852 KB Output is correct
13 Correct 17 ms 23824 KB Output is correct
14 Correct 18 ms 23896 KB Output is correct
15 Correct 17 ms 23896 KB Output is correct
16 Correct 9 ms 22360 KB Output is correct
17 Correct 11 ms 23236 KB Output is correct
18 Correct 7 ms 21852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 850 ms 77964 KB Output is correct
2 Correct 837 ms 77928 KB Output is correct
3 Correct 875 ms 78024 KB Output is correct
4 Correct 317 ms 54184 KB Output is correct
5 Correct 234 ms 38636 KB Output is correct
6 Correct 85 ms 28096 KB Output is correct
7 Correct 756 ms 74196 KB Output is correct
8 Correct 768 ms 76924 KB Output is correct
9 Correct 683 ms 73476 KB Output is correct
10 Correct 154 ms 33144 KB Output is correct
11 Correct 230 ms 49596 KB Output is correct
12 Correct 55 ms 26816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 850 ms 77964 KB Output is correct
2 Correct 837 ms 77928 KB Output is correct
3 Correct 875 ms 78024 KB Output is correct
4 Correct 317 ms 54184 KB Output is correct
5 Correct 234 ms 38636 KB Output is correct
6 Correct 85 ms 28096 KB Output is correct
7 Correct 756 ms 74196 KB Output is correct
8 Correct 768 ms 76924 KB Output is correct
9 Correct 683 ms 73476 KB Output is correct
10 Correct 154 ms 33144 KB Output is correct
11 Correct 230 ms 49596 KB Output is correct
12 Correct 55 ms 26816 KB Output is correct
13 Correct 909 ms 78728 KB Output is correct
14 Correct 893 ms 78424 KB Output is correct
15 Correct 818 ms 77984 KB Output is correct
16 Correct 329 ms 54640 KB Output is correct
17 Correct 243 ms 38840 KB Output is correct
18 Correct 88 ms 27836 KB Output is correct
19 Correct 883 ms 78520 KB Output is correct
20 Correct 905 ms 78480 KB Output is correct
21 Correct 849 ms 76932 KB Output is correct
22 Correct 157 ms 33212 KB Output is correct
23 Correct 222 ms 49340 KB Output is correct
24 Correct 58 ms 26816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21592 KB Output is correct
2 Correct 5 ms 21592 KB Output is correct
3 Correct 6 ms 21596 KB Output is correct
4 Correct 5 ms 21804 KB Output is correct
5 Correct 5 ms 21596 KB Output is correct
6 Correct 5 ms 21596 KB Output is correct
7 Correct 18 ms 23900 KB Output is correct
8 Correct 18 ms 24068 KB Output is correct
9 Correct 18 ms 23900 KB Output is correct
10 Correct 12 ms 23324 KB Output is correct
11 Correct 11 ms 22872 KB Output is correct
12 Correct 8 ms 21852 KB Output is correct
13 Correct 17 ms 23824 KB Output is correct
14 Correct 18 ms 23896 KB Output is correct
15 Correct 17 ms 23896 KB Output is correct
16 Correct 9 ms 22360 KB Output is correct
17 Correct 11 ms 23236 KB Output is correct
18 Correct 7 ms 21852 KB Output is correct
19 Correct 850 ms 77964 KB Output is correct
20 Correct 837 ms 77928 KB Output is correct
21 Correct 875 ms 78024 KB Output is correct
22 Correct 317 ms 54184 KB Output is correct
23 Correct 234 ms 38636 KB Output is correct
24 Correct 85 ms 28096 KB Output is correct
25 Correct 756 ms 74196 KB Output is correct
26 Correct 768 ms 76924 KB Output is correct
27 Correct 683 ms 73476 KB Output is correct
28 Correct 154 ms 33144 KB Output is correct
29 Correct 230 ms 49596 KB Output is correct
30 Correct 55 ms 26816 KB Output is correct
31 Correct 909 ms 78728 KB Output is correct
32 Correct 893 ms 78424 KB Output is correct
33 Correct 818 ms 77984 KB Output is correct
34 Correct 329 ms 54640 KB Output is correct
35 Correct 243 ms 38840 KB Output is correct
36 Correct 88 ms 27836 KB Output is correct
37 Correct 883 ms 78520 KB Output is correct
38 Correct 905 ms 78480 KB Output is correct
39 Correct 849 ms 76932 KB Output is correct
40 Correct 157 ms 33212 KB Output is correct
41 Correct 222 ms 49340 KB Output is correct
42 Correct 58 ms 26816 KB Output is correct
43 Runtime error 341 ms 90304 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -