답안 #620011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
620011 2022-08-02T18:44:02 Z 1ne Pairs (IOI07_pairs) C++14
35 / 100
4000 ms 293784 KB
#include<bits/stdc++.h>
using namespace std;
struct dataa{
	long long v = 0;
	void add(long long left,long long right,long long val){
		v+=val;
		//sum += val *(right - left + 1);
	}
};
long long S,T;
struct Segment_Tree{
	vector<dataa>tree;
	void init(long long n){
		tree.resize(2*n - 1);
	}
	dataa combine(dataa left,dataa right){
		dataa res;
		res.v = left.v + right.v;
		return res;
	}
	long long query(long long node,long long left,long long right,long long qleft,long long qright){
		if (qright<left|| qleft > right)return 0;
		if (qleft<=left && qright>=right){
			return tree[node].v;
		}
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		return query(node + 1,left,mid,qleft,qright) + query(z,mid + 1,right,qleft,qright);
	}
	void update(long long node,long long left,long long right,long long uleft,long long uright,long long v){
		if (left > uright || right < uleft) return;
		if (uleft <= left && right <=uright){
			tree[node].add(left,right,v);
			return;
		}
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		if (uleft<=mid){
			update(node + 1,left,mid,uleft,uright,v);
		}
		if (uright > mid){
			update(z,mid + 1,right,uleft,uright,v);
		}
		tree[node] = combine(tree[node + 1],tree[z]);
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int b,n,d,m;cin>>b>>n>>d>>m;
	if (b == 1){
		vector<int>arr(m + 1,0);
		for (int i = 0;i<n;++i){
			int a;cin>>a;
			arr[a]++;
		}
		for (int i = 1;i<=m;++i){
			arr[i]+=arr[i - 1];
		}
		long long ans = arr[d] * (arr[d] - 1)/2;
		for (int i = d + 1;i<=m;++i){
			//cout<<i<<" "<<(arr[i] - arr[i - 1])<<" "<<arr[i - 1] - arr[i - d - 1]<<'\n';
			long long pos = (arr[i] - arr[i - 1]) * (arr[i - 1] - arr[i - d - 1]);
			ans+=pos;
			ans+=(arr[i] - arr[i - 1]) * (arr[i] - arr[i - 1] - 1)/2;
		}
		cout<<ans<<'\n';
	}
	else if (b == 2){
		vector<int>arr(n),brr(n);
		for (int i = 0;i<n;++i){
			int x,y;cin>>x>>y;
			arr[i] = x + y;
			brr[i] = x - y + m;
		}
		vector<int>order(n);
		iota(order.begin(),order.end(),0);
		sort(order.begin(),order.end(),[&](int i,int j){
			return arr[i] < arr[j];
		});
		long long ans = 0;
		Segment_Tree st;
		st.init(m * 2 + 1);
		int l = 0;
		for (int i = 0;i<n;++i){
			while(l<n && arr[order[l]] - arr[order[i]]<=d){st.update(0,0,m * 2,brr[order[l]],brr[order[l]],1);++l;}
			ans+=st.query(0,0,m * 2,brr[order[i]] - d,brr[order[i]] + d + 1);
			st.update(0,0,m * 2,brr[order[i]],brr[order[i]],-1);
		}
		cout<<ans - n<<'\n';
	}
	else{
		long long ans = 0;
		vector<vector<int>>arr(n,vector<int>(3));
		for (int i = 0;i<n;++i){
			for (int j = 0;j<3;++j){
				cin>>arr[i][j];
			}
		}
		for (int i = 0;i<n;++i){
			for (int j = i + 1;j<n;++j){
				long long sum = abs(arr[i][0] - arr[j][0]) + abs(arr[i][1] - arr[j][1]) + abs(arr[i][2] - arr[j][2]);
				if (sum<=d)ans++;
			}
		}
		cout<<ans<<'\n';
	}
	return 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 425 ms 293784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 212 KB Output is correct
2 Incorrect 6 ms 324 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 413 ms 274256 KB Output is correct
2 Incorrect 295 ms 274180 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 392 ms 274256 KB Output is correct
2 Correct 393 ms 274256 KB Output is correct
3 Correct 456 ms 274212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 1520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 97 ms 3672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4065 ms 5712 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4069 ms 5716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4081 ms 5716 KB Time limit exceeded
2 Halted 0 ms 0 KB -