Submission #985989

# Submission time Handle Problem Language Result Execution time Memory
985989 2024-05-19T14:30:30 Z andrei_boaca Examination (JOI19_examination) C++17
100 / 100
1107 ms 124260 KB
#include <bits/stdc++.h>

using namespace std;
int n,q,sol[100005];
vector<int> vals[4*200005],aint[4*200005];
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 12 ms 40536 KB Output is correct
2 Correct 9 ms 40612 KB Output is correct
3 Correct 9 ms 40392 KB Output is correct
4 Correct 9 ms 40548 KB Output is correct
5 Correct 9 ms 40376 KB Output is correct
6 Correct 9 ms 40540 KB Output is correct
7 Correct 22 ms 42716 KB Output is correct
8 Correct 22 ms 42588 KB Output is correct
9 Correct 22 ms 42588 KB Output is correct
10 Correct 17 ms 41820 KB Output is correct
11 Correct 15 ms 41308 KB Output is correct
12 Correct 12 ms 40796 KB Output is correct
13 Correct 22 ms 42708 KB Output is correct
14 Correct 22 ms 42588 KB Output is correct
15 Correct 21 ms 42584 KB Output is correct
16 Correct 13 ms 41304 KB Output is correct
17 Correct 15 ms 41820 KB Output is correct
18 Correct 10 ms 40796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 828 ms 94264 KB Output is correct
2 Correct 845 ms 94256 KB Output is correct
3 Correct 836 ms 94444 KB Output is correct
4 Correct 322 ms 71356 KB Output is correct
5 Correct 248 ms 55736 KB Output is correct
6 Correct 89 ms 45760 KB Output is correct
7 Correct 750 ms 90596 KB Output is correct
8 Correct 754 ms 93364 KB Output is correct
9 Correct 703 ms 89788 KB Output is correct
10 Correct 161 ms 50368 KB Output is correct
11 Correct 224 ms 66380 KB Output is correct
12 Correct 59 ms 44728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 828 ms 94264 KB Output is correct
2 Correct 845 ms 94256 KB Output is correct
3 Correct 836 ms 94444 KB Output is correct
4 Correct 322 ms 71356 KB Output is correct
5 Correct 248 ms 55736 KB Output is correct
6 Correct 89 ms 45760 KB Output is correct
7 Correct 750 ms 90596 KB Output is correct
8 Correct 754 ms 93364 KB Output is correct
9 Correct 703 ms 89788 KB Output is correct
10 Correct 161 ms 50368 KB Output is correct
11 Correct 224 ms 66380 KB Output is correct
12 Correct 59 ms 44728 KB Output is correct
13 Correct 904 ms 94184 KB Output is correct
14 Correct 893 ms 94396 KB Output is correct
15 Correct 843 ms 94312 KB Output is correct
16 Correct 330 ms 71100 KB Output is correct
17 Correct 258 ms 55776 KB Output is correct
18 Correct 90 ms 45760 KB Output is correct
19 Correct 891 ms 94304 KB Output is correct
20 Correct 890 ms 94376 KB Output is correct
21 Correct 845 ms 92856 KB Output is correct
22 Correct 159 ms 50368 KB Output is correct
23 Correct 229 ms 66508 KB Output is correct
24 Correct 58 ms 44732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 40536 KB Output is correct
2 Correct 9 ms 40612 KB Output is correct
3 Correct 9 ms 40392 KB Output is correct
4 Correct 9 ms 40548 KB Output is correct
5 Correct 9 ms 40376 KB Output is correct
6 Correct 9 ms 40540 KB Output is correct
7 Correct 22 ms 42716 KB Output is correct
8 Correct 22 ms 42588 KB Output is correct
9 Correct 22 ms 42588 KB Output is correct
10 Correct 17 ms 41820 KB Output is correct
11 Correct 15 ms 41308 KB Output is correct
12 Correct 12 ms 40796 KB Output is correct
13 Correct 22 ms 42708 KB Output is correct
14 Correct 22 ms 42588 KB Output is correct
15 Correct 21 ms 42584 KB Output is correct
16 Correct 13 ms 41304 KB Output is correct
17 Correct 15 ms 41820 KB Output is correct
18 Correct 10 ms 40796 KB Output is correct
19 Correct 828 ms 94264 KB Output is correct
20 Correct 845 ms 94256 KB Output is correct
21 Correct 836 ms 94444 KB Output is correct
22 Correct 322 ms 71356 KB Output is correct
23 Correct 248 ms 55736 KB Output is correct
24 Correct 89 ms 45760 KB Output is correct
25 Correct 750 ms 90596 KB Output is correct
26 Correct 754 ms 93364 KB Output is correct
27 Correct 703 ms 89788 KB Output is correct
28 Correct 161 ms 50368 KB Output is correct
29 Correct 224 ms 66380 KB Output is correct
30 Correct 59 ms 44728 KB Output is correct
31 Correct 904 ms 94184 KB Output is correct
32 Correct 893 ms 94396 KB Output is correct
33 Correct 843 ms 94312 KB Output is correct
34 Correct 330 ms 71100 KB Output is correct
35 Correct 258 ms 55776 KB Output is correct
36 Correct 90 ms 45760 KB Output is correct
37 Correct 891 ms 94304 KB Output is correct
38 Correct 890 ms 94376 KB Output is correct
39 Correct 845 ms 92856 KB Output is correct
40 Correct 159 ms 50368 KB Output is correct
41 Correct 229 ms 66508 KB Output is correct
42 Correct 58 ms 44732 KB Output is correct
43 Correct 1093 ms 119176 KB Output is correct
44 Correct 1107 ms 124260 KB Output is correct
45 Correct 1107 ms 124012 KB Output is correct
46 Correct 446 ms 92864 KB Output is correct
47 Correct 303 ms 65568 KB Output is correct
48 Correct 93 ms 46524 KB Output is correct
49 Correct 975 ms 122680 KB Output is correct
50 Correct 1016 ms 123944 KB Output is correct
51 Correct 958 ms 122660 KB Output is correct
52 Correct 207 ms 60420 KB Output is correct
53 Correct 328 ms 87224 KB Output is correct