Submission #874625

# Submission time Handle Problem Language Result Execution time Memory
874625 2023-11-17T12:14:46 Z josanneo22 Pairs (IOI07_pairs) C++17
60 / 100
42 ms 9884 KB
/*
Problem: IOI 2007 Pairs
When:    2023-11-16 14:54:19
Author:  Ning07
*/

#include<bits/stdc++.h>
using namespace std;
using i64=long long;

constexpr int NN=2e5;
int N,B,M,D,a[NN],x[NN],y[NN];

void solve1(){
    for(int i=0;i<N;i++){
        std::cin>>a[i];
    }
    sort(a,a+N);
    i64 ans=0;
    for(int i=0;i<N;i++){
        int lst=lower_bound(a,a+N,a[i]-D)-a;
        ans+=i-lst;
    }
    std::cout<<ans<<'\n';
}
i64 tr[NN<<1];
void update(int x,i64 v){
    x+=NN;
    for(;x;x/=2){ tr[x]+=v;}
}
i64 get(int x,int y){
    x+=NN; y+=NN;
    i64 res=0;
    while(x<=y){
        if(x%2==1) res+=tr[x++];
        if(y%2==0) res+=tr[y--];
        x/=2; y/=2;
    }
    return res;
}
void solve2(){
    vector<int> pos[75000*2+500];
    i64 ans=0;
    for(int i=0;i<N;i++){
        std::cin>>x[i]>>y[i];
        pos[x[i]+y[i]].push_back(x[i]-y[i]+M);
    }
    for(int i=2;i<=2*M;i++){
        for(auto &u:pos[i]){
            ans+=get(max(0,u-D),min(2*M,u+D));
            update(u,1);
        }
        if(i-D<=0) continue;
        for(auto &u:pos[i-D]) update(u,-1); 
    }
    std::cout<<ans<<'\n';
}
void solve3(){
    std::cout<<"fck this\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    std::cin>>B>>N>>D>>M;
    if(B==1) solve1();
    else if(B==2) solve2();
    else if(B==3) solve3();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 604 KB Output is correct
2 Correct 10 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 600 KB Output is correct
2 Correct 14 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 600 KB Output is correct
2 Correct 17 ms 860 KB Output is correct
3 Correct 15 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7732 KB Output is correct
2 Correct 4 ms 7772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 6748 KB Output is correct
2 Correct 15 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 6748 KB Output is correct
2 Correct 27 ms 6748 KB Output is correct
3 Correct 26 ms 6748 KB Output is correct
4 Correct 22 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 9884 KB Output is correct
2 Correct 40 ms 9828 KB Output is correct
3 Correct 27 ms 8468 KB Output is correct
4 Correct 25 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -