| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 279713 | patrikpavic2 | Pairs (IOI07_pairs) | C++17 | 436 ms | 12664 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef long long ll;
typedef pair < int, int > pii;
const int N = 3e5 + 500;
const int OFF = 1e5 + 500;
const int M = 160;
const int OFF2 = 80;
int loga[N], B, n, m, D;
int Q[M][M][M], P[M][M][M];
inline int trans(int x){
	return max(min(x + OFF, N - 1), 0);
}
void add(int x, int y){
	x = trans(x);
	for(; x < N ; x += x & -x)
		loga[x] += y;
}
int query(int x){
	int ret = 0;
	x = trans(x);
	for(; x ; x -= x & -x)
		ret += loga[x];
	return ret;
}
int main(){
	scanf("%d%d%d%d", &B, &n, &D, &m);
	if(B == 1){
		vector < int > v;
		for(int i = 0;i < n;i++){
			int x; scanf("%d", &x);
			v.PB(x);
		}
		sort(v.begin(), v.end());
		int l = 0, r = 0, cur = 0;
		ll sol = 0;
		for(int i = 0;i < n;i++){
			while(v[i] - v[l] > D)
				cur--, l++;
			while(r < n && v[r] - v[i] <= D)
				cur++, r++;
			sol += cur;
		}
		printf("%lld\n", (sol - n) / 2);
	}
	if(B == 2){
		vector < pii > v;
		for(int i = 0;i < n;i++){
			int x, y; scanf("%d%d", &x, &y);
			v.PB({x + y, x - y});
		}
		sort(v.begin(), v.end());
		int l = 0, r = 0;
		ll sol = 0;
		for(int i = 0;i < n;i++){
			while(v[i].X - v[l].X > D)
				add(v[l++].Y, -1);
			while(r < n && v[r].X - v[i].X <= D)
				add(v[r++].Y, 1);
			sol += query(v[i].Y + D) - query(v[i].Y - D - 1);
		}
		printf("%lld\n", (sol - n) / 2);
	}
	if(B == 3){
		for(int i = 0;i < n;i++){
			int x, y, z; scanf("%d%d%d", &x, &y, &z);
			P[x][y][z]++;
			for(int k = 1;k <= 75;k++){
				int DD = D - abs(k - x);
				if(DD < 0) 
					continue;
				int y0 = (y - z - DD);
				int y1 = (y - z + DD);
				int z0 = (y + z - DD);
				int z1 = (y + z + DD);
				y0 += OFF2; y1 += OFF2;
				y0 = max(y0, 1);
				z0 = max(z0, 1);
				y1 = min(y1, M - 2);
				z1 = min(z1, M - 2);
				Q[k][y0][z0]++;	
				Q[k][y1 + 1][z0]--;
				Q[k][y0][z1 + 1]--;
				Q[k][y1 + 1][z1 + 1]++;
				//printf("na %d dodaj %d %d do %d %d\n", k, y0, z0, y1, z1);
			}
		}
		ll sol = 0;
		for(int k = 1;k <= 75;k++){
			for(int i = 1;i < M;i++)
				for(int j = 0;j < M;j++)
					Q[k][i][j] += Q[k][i - 1][j];
			for(int i = 0;i < M;i++)
				for(int j = 1;j < M;j++)
					Q[k][i][j] += Q[k][i][j - 1];
			for(int i = 1;i <= 75;i++){
				for(int j = 1;j <= 75;j++){
					sol += P[k][i][j] * Q[k][i - j + OFF2][i + j]; 
				}
			}
		}
		printf("%lld\n", (sol - n) / 2);
	}
	return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
