Submission #854694

# Submission time Handle Problem Language Result Execution time Memory
854694 2023-09-28T14:26:56 Z DobromirAngelov Examination (JOI19_examination) C++14
100 / 100
232 ms 17520 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int MAXN=1e5+5;
const int MAXQ=1e5+5;

struct point
{
    int x,y,z,num;
};

int n,q;
int mx;
point p[MAXN+MAXQ];
int tree[MAXN+MAXQ];
int ans[MAXQ];

void update(int idx,int val)
{
    while(idx<=mx)
    {
        tree[idx]+=val;
        idx+=idx&(-idx);
    }
}

int query(int idx)
{
    int ret=0;
    while(idx>0)
    {
        ret+=tree[idx];
        idx-=idx&(-idx);
    }
    return ret;
}

void cdq(int l,int r)
{
    if(l+1>=r) return;

    int mid=(l+r)/2;

    cdq(l,mid);
    cdq(mid,r);

    vector<int> hist;
    vector<point> tmp;
    int ptr1=l, ptr2=mid;
    int cntl=0;
    while(ptr1<mid && ptr2<r)
    {
        if(p[ptr1].y>=p[ptr2].y)
        {
            if(!p[ptr1].num)
            {
                update(p[ptr1].z,1);
                hist.push_back(p[ptr1].z);
                cntl++;
            }
            tmp.push_back(p[ptr1++]);
        }
        else
        {
            if(p[ptr2].num) ans[p[ptr2].num]+=cntl-query(p[ptr2].z-1);
            tmp.push_back(p[ptr2++]);
        }
    }
    while(ptr1<mid) tmp.push_back(p[ptr1++]);
    while(ptr2<r)
    {
        if(p[ptr2].num) ans[p[ptr2].num]+=cntl-query(p[ptr2].z-1);
        tmp.push_back(p[ptr2++]);
    }

    for(int i=0;i<hist.size();i++) update(hist[i], -1);
    for(int i=l;i<r;i++) p[i]=tmp[i-l];

    return;
}

bool cmpx(point a,point b) {return a.x<b.x;}
bool cmpy(point a,point b) {return a.y<b.y;}
bool cmpz(point a,point b) {return a.z<b.z;}

void compress()
{
    sort(p+1,p+n+q+1,cmpx);
    int ptr=1;
    for(int i=1;i<n+q;i++)
    {
        if(p[i].x!=p[i+1].x) p[i].x=ptr++;
        else p[i].x=ptr;
    }
    p[n+q].x=ptr;

    sort(p+1,p+n+q+1,cmpy);
    ptr=1;
    for(int i=1;i<n+q;i++)
    {
        if(p[i].y!=p[i+1].y) p[i].y=ptr++;
        else p[i].y=ptr;
    }
    p[n+q].y=ptr;

    sort(p+1,p+n+q+1,cmpz);
    ptr=1;
    for(int i=1;i<n+q;i++)
    {
        if(p[i].z!=p[i+1].z) p[i].z=ptr++;
        else p[i].z=ptr;
    }
    p[n+q].z=ptr;
}

bool cmp(point a,point b)
{
    if(a.x==b.x)
    {
        if((a.num && b.num) || (!a.num && !b.num))
        {
            if(a.y==b.y) return a.z>b.z;
            return a.y>b.y;
        }
        return a.num<b.num;
    }
    return a.x>b.x;
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

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].num=0;
}
for(int i=n+1;i<=n+q;i++)
{
    cin>>p[i].x>>p[i].y>>p[i].z;
    p[i].num=i-n;
}

compress();

sort(p+1,p+n+q+1,cmp);

mx=n+q+1;
cdq(1,n+q+1);

for(int i=1;i<=q;i++) cout<<ans[i]<<endl;

return 0;
}

Compilation message

examination.cpp: In function 'void cdq(int, int)':
examination.cpp:78:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(int i=0;i<hist.size();i++) update(hist[i], -1);
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 6 ms 2652 KB Output is correct
8 Correct 6 ms 2560 KB Output is correct
9 Correct 6 ms 2652 KB Output is correct
10 Correct 5 ms 2652 KB Output is correct
11 Correct 6 ms 2652 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 5 ms 2800 KB Output is correct
14 Correct 6 ms 2908 KB Output is correct
15 Correct 5 ms 2784 KB Output is correct
16 Correct 4 ms 2652 KB Output is correct
17 Correct 5 ms 2652 KB Output is correct
18 Correct 3 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 198 ms 12272 KB Output is correct
2 Correct 202 ms 14372 KB Output is correct
3 Correct 200 ms 14600 KB Output is correct
4 Correct 192 ms 13568 KB Output is correct
5 Correct 169 ms 14556 KB Output is correct
6 Correct 125 ms 13560 KB Output is correct
7 Correct 186 ms 14752 KB Output is correct
8 Correct 195 ms 15092 KB Output is correct
9 Correct 184 ms 14172 KB Output is correct
10 Correct 150 ms 13668 KB Output is correct
11 Correct 160 ms 14012 KB Output is correct
12 Correct 122 ms 12872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 198 ms 12272 KB Output is correct
2 Correct 202 ms 14372 KB Output is correct
3 Correct 200 ms 14600 KB Output is correct
4 Correct 192 ms 13568 KB Output is correct
5 Correct 169 ms 14556 KB Output is correct
6 Correct 125 ms 13560 KB Output is correct
7 Correct 186 ms 14752 KB Output is correct
8 Correct 195 ms 15092 KB Output is correct
9 Correct 184 ms 14172 KB Output is correct
10 Correct 150 ms 13668 KB Output is correct
11 Correct 160 ms 14012 KB Output is correct
12 Correct 122 ms 12872 KB Output is correct
13 Correct 222 ms 14836 KB Output is correct
14 Correct 218 ms 14816 KB Output is correct
15 Correct 198 ms 14312 KB Output is correct
16 Correct 196 ms 13928 KB Output is correct
17 Correct 179 ms 14144 KB Output is correct
18 Correct 131 ms 12788 KB Output is correct
19 Correct 231 ms 15120 KB Output is correct
20 Correct 220 ms 15692 KB Output is correct
21 Correct 214 ms 15736 KB Output is correct
22 Correct 145 ms 14200 KB Output is correct
23 Correct 154 ms 13596 KB Output is correct
24 Correct 120 ms 12928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 6 ms 2652 KB Output is correct
8 Correct 6 ms 2560 KB Output is correct
9 Correct 6 ms 2652 KB Output is correct
10 Correct 5 ms 2652 KB Output is correct
11 Correct 6 ms 2652 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 5 ms 2800 KB Output is correct
14 Correct 6 ms 2908 KB Output is correct
15 Correct 5 ms 2784 KB Output is correct
16 Correct 4 ms 2652 KB Output is correct
17 Correct 5 ms 2652 KB Output is correct
18 Correct 3 ms 2652 KB Output is correct
19 Correct 198 ms 12272 KB Output is correct
20 Correct 202 ms 14372 KB Output is correct
21 Correct 200 ms 14600 KB Output is correct
22 Correct 192 ms 13568 KB Output is correct
23 Correct 169 ms 14556 KB Output is correct
24 Correct 125 ms 13560 KB Output is correct
25 Correct 186 ms 14752 KB Output is correct
26 Correct 195 ms 15092 KB Output is correct
27 Correct 184 ms 14172 KB Output is correct
28 Correct 150 ms 13668 KB Output is correct
29 Correct 160 ms 14012 KB Output is correct
30 Correct 122 ms 12872 KB Output is correct
31 Correct 222 ms 14836 KB Output is correct
32 Correct 218 ms 14816 KB Output is correct
33 Correct 198 ms 14312 KB Output is correct
34 Correct 196 ms 13928 KB Output is correct
35 Correct 179 ms 14144 KB Output is correct
36 Correct 131 ms 12788 KB Output is correct
37 Correct 231 ms 15120 KB Output is correct
38 Correct 220 ms 15692 KB Output is correct
39 Correct 214 ms 15736 KB Output is correct
40 Correct 145 ms 14200 KB Output is correct
41 Correct 154 ms 13596 KB Output is correct
42 Correct 120 ms 12928 KB Output is correct
43 Correct 232 ms 16752 KB Output is correct
44 Correct 228 ms 17424 KB Output is correct
45 Correct 226 ms 16872 KB Output is correct
46 Correct 206 ms 15760 KB Output is correct
47 Correct 187 ms 15100 KB Output is correct
48 Correct 134 ms 13004 KB Output is correct
49 Correct 215 ms 17520 KB Output is correct
50 Correct 217 ms 16776 KB Output is correct
51 Correct 214 ms 17076 KB Output is correct
52 Correct 183 ms 15060 KB Output is correct
53 Correct 153 ms 14372 KB Output is correct