Submission #705867

# Submission time Handle Problem Language Result Execution time Memory
705867 2023-03-05T14:24:51 Z Darren0724 Examination (JOI19_examination) C++17
100 / 100
331 ms 19644 KB
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
const int N=600005;
struct D{
    int a,b,c,id,ans=0;
    D(){}
    D(int a1,int b1,int c1,int d1,int e1){
        a=a1,b=b1,c=c1,id=d1,ans=e1;
    }
};
vector<int> bit(N+1);
void add(int p,int x){
    //cout<<p<<' '<<x<<endl;
    for(int i=p;i<=N;i+=(i&-i)){
        bit[i]+=x;
    }
}
int ask(int p){
    int ans=0;
    for(int i=p;i>0;i-=i&(-i)){
        ans+=bit[i];
    }
    return ans;
}

vector<D> v;
void dc(int l,int r){
    if(r-l==1){
        return;
    }
    int m=(l+r)>>1;
    dc(l,m);
    dc(m,r);
    int ptr=0;
    vector<D> a(r-l);
    int ptr1=l,ptr2=m;
    while(ptr1<m&&ptr2<r){
        if(v[ptr1].b<=v[ptr2].b){
            if(v[ptr1].id==-1)add(v[ptr1].c,1);
            a[ptr++]=v[ptr1];
            ptr1++;
        }
        else{
            if(v[ptr2].id!=-1)v[ptr2].ans+=ask(v[ptr2].c);
            a[ptr++]=v[ptr2];
            ptr2++;
        }
    }
    while(ptr1<m){
        if(v[ptr1].id==-1)add(v[ptr1].c,1);
        a[ptr++]=v[ptr1];
        ptr1++;
    }
    while(ptr2<r){
        v[ptr2].ans+=ask(v[ptr2].c);
        a[ptr++]=v[ptr2];
        ptr2++;
    }
    for(int i=l;i<m;i++){
        if(v[i].id==-1)add(v[i].c,-1);
    }
    for(int i=0;i<r-l;i++){
        v[l+i]=a[i];
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m;cin>>n>>m;
    v.resize(n+m);
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        v[i]=D(a,b,a+b,-1,0);
    }
    for(int i=0;i<m;i++){
        int a,b,c;cin>>a>>b>>c;
        v[i+n]=D(a,b,c,i,0);
    }
    vector<int> g;
    for(int i=0;i<n+m;i++){
        g.push_back(v[i].a);
        g.push_back(v[i].b);
        g.push_back(v[i].c);
    }
    sort(all(g));
    g.resize(unique(all(g))-g.begin());
    for(int i=0;i<n+m;i++){
        v[i].a=lower_bound(all(g),v[i].a)-g.begin()+1;
        v[i].b=lower_bound(all(g),v[i].b)-g.begin()+1;
        v[i].c=lower_bound(all(g),v[i].c)-g.begin()+1;
        v[i].a=N-v[i].a;
        v[i].b=N-v[i].b;
        v[i].c=N-v[i].c;
    }
    sort(all(v),[](D x,D y){return (x.a!=y.a?x.a<y.a:x.id<y.id);});
    dc(0,n+m);
    vector<int> ans(m);
    for(int i=0;i<n+m;i++){
        if(v[i].id!=-1){
            ans[v[i].id]=v[i].ans;
        }
    }
    for(int i=0;i<m;i++){
        cout<<ans[i]<<'\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 8 ms 3156 KB Output is correct
8 Correct 9 ms 3076 KB Output is correct
9 Correct 8 ms 3068 KB Output is correct
10 Correct 8 ms 3028 KB Output is correct
11 Correct 7 ms 3028 KB Output is correct
12 Correct 5 ms 3028 KB Output is correct
13 Correct 8 ms 3036 KB Output is correct
14 Correct 8 ms 3028 KB Output is correct
15 Correct 8 ms 3028 KB Output is correct
16 Correct 6 ms 3068 KB Output is correct
17 Correct 7 ms 3024 KB Output is correct
18 Correct 4 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 263 ms 15164 KB Output is correct
2 Correct 256 ms 17288 KB Output is correct
3 Correct 275 ms 17192 KB Output is correct
4 Correct 214 ms 16452 KB Output is correct
5 Correct 205 ms 16452 KB Output is correct
6 Correct 118 ms 15708 KB Output is correct
7 Correct 246 ms 17116 KB Output is correct
8 Correct 243 ms 17084 KB Output is correct
9 Correct 230 ms 17040 KB Output is correct
10 Correct 190 ms 16444 KB Output is correct
11 Correct 197 ms 16440 KB Output is correct
12 Correct 100 ms 15720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 263 ms 15164 KB Output is correct
2 Correct 256 ms 17288 KB Output is correct
3 Correct 275 ms 17192 KB Output is correct
4 Correct 214 ms 16452 KB Output is correct
5 Correct 205 ms 16452 KB Output is correct
6 Correct 118 ms 15708 KB Output is correct
7 Correct 246 ms 17116 KB Output is correct
8 Correct 243 ms 17084 KB Output is correct
9 Correct 230 ms 17040 KB Output is correct
10 Correct 190 ms 16444 KB Output is correct
11 Correct 197 ms 16440 KB Output is correct
12 Correct 100 ms 15720 KB Output is correct
13 Correct 286 ms 17692 KB Output is correct
14 Correct 288 ms 17612 KB Output is correct
15 Correct 261 ms 17188 KB Output is correct
16 Correct 241 ms 16912 KB Output is correct
17 Correct 238 ms 16936 KB Output is correct
18 Correct 129 ms 15724 KB Output is correct
19 Correct 291 ms 17668 KB Output is correct
20 Correct 290 ms 17724 KB Output is correct
21 Correct 272 ms 17724 KB Output is correct
22 Correct 188 ms 16536 KB Output is correct
23 Correct 196 ms 16460 KB Output is correct
24 Correct 95 ms 15680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 8 ms 3156 KB Output is correct
8 Correct 9 ms 3076 KB Output is correct
9 Correct 8 ms 3068 KB Output is correct
10 Correct 8 ms 3028 KB Output is correct
11 Correct 7 ms 3028 KB Output is correct
12 Correct 5 ms 3028 KB Output is correct
13 Correct 8 ms 3036 KB Output is correct
14 Correct 8 ms 3028 KB Output is correct
15 Correct 8 ms 3028 KB Output is correct
16 Correct 6 ms 3068 KB Output is correct
17 Correct 7 ms 3024 KB Output is correct
18 Correct 4 ms 2900 KB Output is correct
19 Correct 263 ms 15164 KB Output is correct
20 Correct 256 ms 17288 KB Output is correct
21 Correct 275 ms 17192 KB Output is correct
22 Correct 214 ms 16452 KB Output is correct
23 Correct 205 ms 16452 KB Output is correct
24 Correct 118 ms 15708 KB Output is correct
25 Correct 246 ms 17116 KB Output is correct
26 Correct 243 ms 17084 KB Output is correct
27 Correct 230 ms 17040 KB Output is correct
28 Correct 190 ms 16444 KB Output is correct
29 Correct 197 ms 16440 KB Output is correct
30 Correct 100 ms 15720 KB Output is correct
31 Correct 286 ms 17692 KB Output is correct
32 Correct 288 ms 17612 KB Output is correct
33 Correct 261 ms 17188 KB Output is correct
34 Correct 241 ms 16912 KB Output is correct
35 Correct 238 ms 16936 KB Output is correct
36 Correct 129 ms 15724 KB Output is correct
37 Correct 291 ms 17668 KB Output is correct
38 Correct 290 ms 17724 KB Output is correct
39 Correct 272 ms 17724 KB Output is correct
40 Correct 188 ms 16536 KB Output is correct
41 Correct 196 ms 16460 KB Output is correct
42 Correct 95 ms 15680 KB Output is correct
43 Correct 329 ms 19644 KB Output is correct
44 Correct 326 ms 19636 KB Output is correct
45 Correct 331 ms 19592 KB Output is correct
46 Correct 263 ms 18080 KB Output is correct
47 Correct 259 ms 18060 KB Output is correct
48 Correct 133 ms 15828 KB Output is correct
49 Correct 316 ms 19544 KB Output is correct
50 Correct 306 ms 19484 KB Output is correct
51 Correct 293 ms 19388 KB Output is correct
52 Correct 245 ms 17996 KB Output is correct
53 Correct 206 ms 17244 KB Output is correct