답안 #697345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697345 2023-02-09T11:16:02 Z WongChun1234 Pairs (IOI07_pairs) C++14
70 / 100
3428 ms 9568 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100050;
ll b,n,d,m,x[N],y[N],z[N],ans;
ll pt=1,psum[150][150][150],par,dy;
vector<pair<int,int>> srt;
void sub1(){
    for (int i=1;i<=n;i++){
        cin>>x[i];
    }
    sort(x+1,x+1+n);
    for (int i=1;i<=n;i++){
        while (x[pt]<x[i]-d) pt++;
        ans+=i-pt;
    }
    cout<<ans<<"\n";
}
const int D=115000;
struct bit{
	const static int size=300060;
	array<int,size> bit;
	void modify(int id,int val){
		for (;id<size;id+=(id&-id)) bit[id]+=val;
	}
	int query(int id){
		int ret=0;
		for (;id;id-=(id&-id)) ret+=bit[id];
		return ret;
	}
	int query(int l,int r){
	    //cout<<l-D<<" "<<r-D<<endl;
	    return query(r)-query(l-1);
	}
}cnt[2];
void sub2(){
    for (int i=1;i<=n;i++){
        cin>>x[i]>>y[i];
        srt.emplace_back(x[i],y[i]);
    }
    sort(srt.begin(),srt.end(),[](pair<int,int> a, pair<int,int> b) {return a.first+a.second < b.first+b.second;});
    auto curr=srt.begin();
    for (auto i:srt){
        while ((*curr).first+(*curr).second<i.first+i.second-d){
            par=((*curr).first+(*curr).second)%2;
            cnt[par].modify(((*curr).second-(*curr).first+par)/2+D,-1),curr++;
        }
        //cout<<i.first<<" "<<i.second<<endl;
        par=(i.first+i.second)%2;
        dy=(i.second-i.first+par)/2;
        if (d%2){
            ans+=cnt[!par].query(dy-d/2-1+D,dy+d/2+D);
            ans+=cnt[par].query(dy-d/2+D,dy+d/2+D);
        }else{
            ans+=cnt[par].query(dy-d/2+D,dy+d/2+D);
            ans+=cnt[!par].query(dy-d/2+2+D,dy+d/2+1+D);
        }
        cnt[par].modify((i.second-i.first+par)/2+D,1);
        //cout<<ans<<"\n";
    }
    cout<<ans<<"\n";
}
void sub3(){
    for (int i=1;i<=n;i++){
        cin>>x[i]>>y[i]>>z[i];
        psum[x[i]][y[i]][z[i]]++;
    }
    for (int i=1;i<=75;i++) for (int j=1;j<=75;j++) for (int k=1;k<=75;k++) psum[i][j][k]+=psum[i][j][k-1];
    for (int i=1;i<=n;i++){
        for (int xx=max(1LL,x[i]-d);xx<=min(m,x[i]+d);xx++){
            int dx=abs(x[i]-xx);
            for (int yy=max(1LL,y[i]-(d-dx));yy<=min(m,y[i]+(d-dx));yy++){
                int maxdz=d-dx-abs(y[i]-yy);
                ans+=psum[xx][yy][min(m,z[i]+maxdz)]-psum[xx][yy][max(0LL,z[i]-maxdz-1)];
            }
        }
    }
    cout<<(ans-n)/2<<"\n";
}
int main(){
    cin>>b>>n>>d>>m;
    if (b==1) sub1();
    else if (b==2) sub2();
    else if (b==3) sub3();
    else assert(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1052 KB Output is correct
2 Correct 25 ms 1044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 1072 KB Output is correct
2 Correct 48 ms 1064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 1000 KB Output is correct
2 Correct 42 ms 972 KB Output is correct
3 Correct 38 ms 1092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 852 KB Output is correct
2 Incorrect 1 ms 852 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 2844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 2768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 69 ms 3336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7124 KB Output is correct
2 Correct 40 ms 7124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 9420 KB Output is correct
2 Correct 69 ms 9480 KB Output is correct
3 Correct 71 ms 9420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 154 ms 9568 KB Output is correct
2 Correct 1411 ms 9512 KB Output is correct
3 Correct 1475 ms 9516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 883 ms 9516 KB Output is correct
2 Correct 2518 ms 9512 KB Output is correct
3 Correct 3428 ms 9548 KB Output is correct