Submission #54548

# Submission time Handle Problem Language Result Execution time Memory
54548 2018-07-04T04:52:21 Z 노영훈(#1490) Pairs (IOI07_pairs) C++11
60 / 100
119 ms 3836 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

int b,n,d,m;

ll ans=0;

void solve1(){
    int A[MX];
    for(int i=1; i<=n; i++) cin>>A[i];
    sort(A+1, A+n+1);
    for(int i=1, r=1; i<=n; i++){
        while(r<n && A[r+1]<=A[i]+d) r++;
        ans+=r-i;
    }
}

struct _SEG {
    int tree[150000*4], n;
    void init(int sz){
        n=sz;
        for(int i=1; i<150000*4; i++) tree[i]=0;
    }
    void upt(int v, int s, int e, int pos, int val){
        if(pos<s || e<pos) return;
        tree[v]+=val;
        if(s==e) return;
        upt(v*2,s,(s+e)/2,pos,val);
        upt(v*2+1,(s+e)/2+1,e,pos,val);
    }
    int sum(int v, int s, int e, int l, int r){
        if(e<l || r<s) return 0;
        if(l<=s && e<=r) return tree[v];
        return sum(v*2,s,(s+e)/2,l,r) + sum(v*2+1,(s+e)/2+1,e,l,r);
    }
    void upt(int pos, int val){
        upt(1,1,n,pos,val);
    }
    int sum(int l, int r){
        l=max(l,1);
        r=min(r,n);
        if(r<l) return 0;
        return sum(1,1,n,l,r);
    }
};

struct pt2 {
    int x, y;
    bool operator < (const pt2 &p) const {
        return x-y<p.x-p.y;
    }
    void scan(){
        cin>>x>>y;
    }
};

void solve2(){
    _SEG Seg; Seg.init(150000);
    pt2 P[MX];
    for(int i=1; i<=n; i++) P[i].scan();
    sort(P+1, P+n+1);
    // for(int i=1; i<=n; i++) cout<<P[i].x<<' '<<P[i].y<<'\n';
    for(int i=1, r=0, l=1; i<=n; i++){
        while(r<n && P[r+1].x-P[r+1].y<=P[i].x-P[i].y+d){
            r++;
            Seg.upt(P[r].x+P[r].y,1);
        }
        while(l<=i){
            Seg.upt(P[l].x+P[l].y,-1);
            l++;
        }
        // cout<<l<<"~"<<r<<'\n';
        ans+=Seg.sum(P[i].x+P[i].y-d, P[i].x+P[i].y+d);
    }
}

void solve3(){

}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>b>>n>>d>>m;
    if(b==1) solve1();
    if(b==2) solve2();
    if(b==3) solve3();
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 872 KB Output is correct
2 Correct 16 ms 948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 964 KB Output is correct
2 Correct 22 ms 964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1004 KB Output is correct
2 Correct 22 ms 1004 KB Output is correct
3 Correct 22 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2924 KB Output is correct
2 Correct 5 ms 2924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 3692 KB Output is correct
2 Correct 61 ms 3760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 3820 KB Output is correct
2 Correct 82 ms 3820 KB Output is correct
3 Correct 74 ms 3820 KB Output is correct
4 Correct 77 ms 3820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 3836 KB Output is correct
2 Correct 111 ms 3836 KB Output is correct
3 Correct 80 ms 3836 KB Output is correct
4 Correct 79 ms 3836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3836 KB Output isn't correct
2 Halted 0 ms 0 KB -