Submission #677050

# Submission time Handle Problem Language Result Execution time Memory
677050 2023-01-02T07:53:20 Z tommy1024 Pairs (IOI07_pairs) C++17
62 / 100
186 ms 47320 KB
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int B,N,D,M;
int arr[100005];
int tree[150005];
int tree3[226][226][226];
ll ans;
struct point{
    int d1,d2;
    bool operator<(const point &r)const{
        return d1<r.d1;
    }
}p[100005];
struct point3{
    int d1,d2,d3,d4;
    bool operator<(const point3 &r)const{
        return d1<r.d1;
    }
}p3[100005];
void update(int x,int val){
    while(x<=150000){
        tree[x]+=val;
        x+=x&-x;
    }
}
void update3(int x,int y,int z,int val){
    while(x<=225){
        int Y=y;
        while(Y<=225){
            int Z=z;
            while(Z<=225){
                tree3[x][Y][Z]+=val;
                Z+=Z&-Z;
            }
            Y+=Y&-Y;
        }
        x+=x&-x;
    }
}
ll sum(int x){
    ll ret=0;
    while(x>0){
        ret+=tree[x];
        x-=x&-x;
    }
    return ret;
}
ll sum3(int x,int y,int z){
    ll ret=0;
    while(x>0){
        int Y=y;
        while(Y>0){
            int Z=z;
            while(Z>0){
                ret+=tree3[x][Y][Z];
                Z-=Z&-Z;
            }
            Y-=Y&-Y;
        }
        x-=x&-x;
    }
    return ret;
}
ll query(int x,int y){
    return sum(y)-sum(x-1);
}
ll query3(int x1,int x2,int y1,int y2,int z1,int z2){
    ll ret=sum3(x2,y2,z2)-sum3(x1-1,y2,z2)-sum3(x2,y1-1,z2)-sum3(x2,y2,z1-1);
    ret+=sum3(x1-1,y1-1,z2)+sum3(x1-1,y2,z1-1)+sum3(x2,y1-1,z1-1)-sum3(x1-1,y1-1,z1-1);
    return ret;
}
int main()
{
    scanf("%d%d%d%d",&B,&N,&D,&M);
    if(B==1){
        for(int i=1;i<=N;i++){
            scanf("%d",&arr[i]);
        }
        sort(arr+1,arr+N+1);
        int t=1;
        for(int h=1;h<=N;h++){
            while(t<h&&arr[h]-arr[t]>D)t++;
            ans+=h-t;
        }
    }
    else if(B==2){
        for(int i=1;i<=N;i++){
            int a,b;
            scanf("%d%d",&a,&b);
            p[i]={a+b,a-b+75000};
        }
        sort(p+1,p+N+1);
        int t=1;
        for(int h=1;h<=N;h++){
            while(t<h&&p[h].d1-p[t].d1>D){
                update(p[t].d2,-1);
                t++;
            }
            ans+=query(p[h].d2-D,p[h].d2+D);
            update(p[h].d2,1);
        }
    }
    else if(B==3){
        for(int i=1;i<=N;i++){
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            p3[i]={a+b+c,a+b-c+75,a-b+c+75,-a+b+c+75};
        }
        sort(p3+1,p3+N+1);
        int t=1;
        for(int h=1;h<=N;h++){
            while(t<h&&p3[h].d1-p3[t].d1>D){
                update3(p3[t].d2,p3[t].d3,p3[t].d4,-1);
                t++;
            }
            ans+=query3(p3[h].d2-D,p3[h].d2+D,p3[h].d3-D,p3[h].d3+D,p3[h].d4-D,p3[h].d4+D);
            update3(p3[h].d2,p3[h].d3,p3[h].d4,1);
        }
    }
    printf("%lld",ans);
    return 0;
}

Compilation message

pairs.cpp: In function 'int main()':
pairs.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |     scanf("%d%d%d%d",&B,&N,&D,&M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:79:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |             scanf("%d",&arr[i]);
      |             ~~~~~^~~~~~~~~~~~~~
pairs.cpp:91:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |             scanf("%d%d",&a,&b);
      |             ~~~~~^~~~~~~~~~~~~~
pairs.cpp:108:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |             scanf("%d%d%d",&a,&b,&c);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1064 KB Output is correct
2 Correct 14 ms 1072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1516 KB Output is correct
2 Correct 20 ms 1440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1444 KB Output is correct
2 Correct 19 ms 1568 KB Output is correct
3 Correct 20 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 816 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 1652 KB Output is correct
2 Correct 24 ms 1592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1880 KB Output is correct
2 Correct 28 ms 1808 KB Output is correct
3 Correct 27 ms 1812 KB Output is correct
4 Correct 28 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2768 KB Output is correct
2 Incorrect 34 ms 2780 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 22740 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 102 ms 3312 KB Output is correct
2 Correct 108 ms 3232 KB Output is correct
3 Correct 106 ms 3212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 17800 KB Output is correct
2 Runtime error 131 ms 33772 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 158 ms 47320 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -