Submission #894392

# Submission time Handle Problem Language Result Execution time Memory
894392 2023-12-28T08:31:13 Z ttamx Examination (JOI19_examination) C++14
100 / 100
191 ms 9700 KB
#include<bits/stdc++.h>

using namespace std;

const int N=2e5+5;

int n,q;
int ans[N];
vector<int> v;

struct point{
    int x,y,z,i;
    bool operator<(const point &o)const{
        if(x!=o.x)return x>o.x;
        if(y!=o.y)return y>o.y;
        return i<o.i;
    }
}a[N],b[N];

struct fenwick{
    int t[N];
    void update(int i,int v){
        for(;i<=n+q;i+=i&-i)t[i]+=v;
    }
    int query(int i){
        int res=0;
        for(;i>0;i-=i&-i)res+=t[i];
        return res;
    }
}f;

void CDQ(int l,int r){
    if(l==r)return;
    int m=(l+r)/2;
    CDQ(l,m);
    CDQ(m+1,r);
    for(int i=l,j=m+1,p=l;p<=r;){
        if(j>r||(i<=m&&a[i].y>=a[j].y)){
            b[p++]=a[i];
            if(a[i].i==0)f.update(a[i].z,1);
            i++;
        }else{
            b[p++]=a[j];
            if(a[j].i)ans[a[j].i]+=f.query(n+q)-f.query(a[j].z-1);
            j++;
        }
    }
    for(int i=l;i<=m;i++)if(a[i].i==0)f.update(a[i].z,-1);
    for(int i=l;i<=r;i++)a[i]=b[i];
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> q;
    for(int i=1;i<=n;i++){
        cin >> a[i].x >> a[i].y;
        a[i].z=a[i].x+a[i].y;
        v.emplace_back(a[i].z);
    }
    for(int i=n+1;i<=n+q;i++){
        cin >> a[i].x >> a[i].y >> a[i].z;
        v.emplace_back(a[i].z);
        a[i].i=i-n;
    }
    sort(v.begin(),v.end());
    for(int i=1;i<=n+q;i++)a[i].z=lower_bound(v.begin(),v.end(),a[i].z)-v.begin()+1;
    sort(a+1,a+n+q+1);
    CDQ(1,n+q);
    for(int i=1;i<=q;i++)cout << ans[i] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 5 ms 4668 KB Output is correct
8 Correct 5 ms 4444 KB Output is correct
9 Correct 5 ms 4444 KB Output is correct
10 Correct 4 ms 4444 KB Output is correct
11 Correct 5 ms 4444 KB Output is correct
12 Correct 3 ms 4444 KB Output is correct
13 Correct 4 ms 4444 KB Output is correct
14 Correct 4 ms 4444 KB Output is correct
15 Correct 4 ms 4444 KB Output is correct
16 Correct 4 ms 4444 KB Output is correct
17 Correct 4 ms 4624 KB Output is correct
18 Correct 3 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 9008 KB Output is correct
2 Correct 148 ms 9020 KB Output is correct
3 Correct 149 ms 9184 KB Output is correct
4 Correct 132 ms 9144 KB Output is correct
5 Correct 132 ms 9164 KB Output is correct
6 Correct 79 ms 9140 KB Output is correct
7 Correct 131 ms 9160 KB Output is correct
8 Correct 130 ms 9168 KB Output is correct
9 Correct 127 ms 9020 KB Output is correct
10 Correct 117 ms 9008 KB Output is correct
11 Correct 115 ms 8904 KB Output is correct
12 Correct 89 ms 8764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 9008 KB Output is correct
2 Correct 148 ms 9020 KB Output is correct
3 Correct 149 ms 9184 KB Output is correct
4 Correct 132 ms 9144 KB Output is correct
5 Correct 132 ms 9164 KB Output is correct
6 Correct 79 ms 9140 KB Output is correct
7 Correct 131 ms 9160 KB Output is correct
8 Correct 130 ms 9168 KB Output is correct
9 Correct 127 ms 9020 KB Output is correct
10 Correct 117 ms 9008 KB Output is correct
11 Correct 115 ms 8904 KB Output is correct
12 Correct 89 ms 8764 KB Output is correct
13 Correct 182 ms 9168 KB Output is correct
14 Correct 185 ms 9364 KB Output is correct
15 Correct 149 ms 9000 KB Output is correct
16 Correct 166 ms 9164 KB Output is correct
17 Correct 165 ms 9420 KB Output is correct
18 Correct 92 ms 9164 KB Output is correct
19 Correct 180 ms 9164 KB Output is correct
20 Correct 178 ms 9164 KB Output is correct
21 Correct 168 ms 9332 KB Output is correct
22 Correct 113 ms 8908 KB Output is correct
23 Correct 118 ms 9020 KB Output is correct
24 Correct 89 ms 8656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 5 ms 4668 KB Output is correct
8 Correct 5 ms 4444 KB Output is correct
9 Correct 5 ms 4444 KB Output is correct
10 Correct 4 ms 4444 KB Output is correct
11 Correct 5 ms 4444 KB Output is correct
12 Correct 3 ms 4444 KB Output is correct
13 Correct 4 ms 4444 KB Output is correct
14 Correct 4 ms 4444 KB Output is correct
15 Correct 4 ms 4444 KB Output is correct
16 Correct 4 ms 4444 KB Output is correct
17 Correct 4 ms 4624 KB Output is correct
18 Correct 3 ms 4440 KB Output is correct
19 Correct 149 ms 9008 KB Output is correct
20 Correct 148 ms 9020 KB Output is correct
21 Correct 149 ms 9184 KB Output is correct
22 Correct 132 ms 9144 KB Output is correct
23 Correct 132 ms 9164 KB Output is correct
24 Correct 79 ms 9140 KB Output is correct
25 Correct 131 ms 9160 KB Output is correct
26 Correct 130 ms 9168 KB Output is correct
27 Correct 127 ms 9020 KB Output is correct
28 Correct 117 ms 9008 KB Output is correct
29 Correct 115 ms 8904 KB Output is correct
30 Correct 89 ms 8764 KB Output is correct
31 Correct 182 ms 9168 KB Output is correct
32 Correct 185 ms 9364 KB Output is correct
33 Correct 149 ms 9000 KB Output is correct
34 Correct 166 ms 9164 KB Output is correct
35 Correct 165 ms 9420 KB Output is correct
36 Correct 92 ms 9164 KB Output is correct
37 Correct 180 ms 9164 KB Output is correct
38 Correct 178 ms 9164 KB Output is correct
39 Correct 168 ms 9332 KB Output is correct
40 Correct 113 ms 8908 KB Output is correct
41 Correct 118 ms 9020 KB Output is correct
42 Correct 89 ms 8656 KB Output is correct
43 Correct 188 ms 9168 KB Output is correct
44 Correct 189 ms 9164 KB Output is correct
45 Correct 191 ms 9700 KB Output is correct
46 Correct 169 ms 9136 KB Output is correct
47 Correct 169 ms 9164 KB Output is correct
48 Correct 100 ms 9008 KB Output is correct
49 Correct 171 ms 9164 KB Output is correct
50 Correct 171 ms 9284 KB Output is correct
51 Correct 166 ms 9264 KB Output is correct
52 Correct 153 ms 9164 KB Output is correct
53 Correct 118 ms 9144 KB Output is correct