이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T> 
	using ord_set = tree<T, null_type, less<T>, rb_tree_tag,
	tree_order_statistics_node_update>;
const int MAX = 4*76;
const int SHIFT = 76;
int bit[MAX][MAX][MAX];
void fix(int& val) {
	val = max(val, 0);
	val = min(val, MAX-1);
}
int pref(int x, int y, int z) {
	int ret = 0;
	x++, y++, z++;
	fix(x), fix(y), fix(z);
	for (; x; x -= x & -x) for (int y2 = y; y2; y2 -= y2 & -y2)
		for (int z2 = z; z2; z2 -= z2 & -z2) ret += bit[x][y2][z2];
	return ret;
}
void update(int x, int y, int z, int val) {
	x++, y++, z++;
	for (; x < MAX; x += x & -x) for (int y2 = y; y2 < MAX; y2 += y2 & -y2)
		for (int z2 = z; z2 < MAX; z2 += z2 & -z2) bit[x][y2][z2] += val;
}
int query(int x0, int y0, int z0, int x1, int y1, int z1) { 
	return pref(x1, y1, z1) 
	- pref(x1, y1, z0-1) - pref(x1, y0-1, z1)  - pref(x0-1, y1, z1) 
	+ pref(x1, y0-1, z0-1) + pref(x0-1, y1, z0-1) + pref(x0-1, y0-1, z1)
	- pref(x0-1, y0-1, z0-1); 
}
void solve1(int n, int d, int m) {
	vector<pair<int, int>> ev;
	for (int i = 0; i<n; i++) {
		int x; cin >> x;
		ev.emplace_back(x, 0);
		ev.emplace_back(x+d, 1);
	}
	sort(ev.begin(), ev.end());
	int cnt = 0;
	ll ans = 0;
	for (auto [x, ty] : ev) {
		if (ty == 0) ans += cnt, cnt++;
		else cnt--;
	}
	cout << ans << endl;
}
void solve2(int n, int d, int m) {
	vector<tuple<int, int, int, int>> ev;
	for (int i = 0; i<n; i++) {
		int x, y; cin >> x >> y;
		int nx = x + y;
		y = x - y;
		x = nx;
		ev.emplace_back(x, 0, y, i);
		ev.emplace_back(x+d, 1, y, i);
	}
	sort(ev.begin(), ev.end());
	ord_set<pair<int, int>> st;
	ll ans = 0;
	for (auto [x, ty, y, i] : ev) {
		if (ty == 0) {
			ans += st.order_of_key({y+d, INF}) - st.order_of_key({y-d, -INF});
			st.insert({y, i});
		}
		else st.erase({y, i});
	}
	cout << ans << endl;
}
void solve3(int n, int d, int m) {
	vector<tuple<int, int, int, int, int>> ev; // w ty x y z
	for (int i = 0; i<n; i++) {
		int x, y, z; cin >> x >> y >> z;
		int nx = x + y + z + SHIFT;
		int ny = x + y - z + SHIFT;
		int nz = x - y + z + SHIFT;
		int nw = x - y - z;
		ev.emplace_back(nw, 0, nx, ny, nz);
		ev.emplace_back(nw+d, 1, nx, ny, nz);
	}
	sort(ev.begin(), ev.end());
	ll ans = 0;
	for (auto [w, ty, x, y, z] : ev) {
		if (ty == 0) {
			ans += query(x-d, y-d, z-d, x+d, y+d, z+d);
			update(x, y, z, +1);
		}
		else update(x, y, z, -1);
	}
	cout << ans << endl;
}
int main() { _
	int b, n, d, m; cin >> b >> n >> d >> m;
	if (b == 1) solve1(n, d, m);
	if (b == 2) solve2(n, d, m);
	if (b == 3) solve3(n, d, m);
	exit(0);
}
| # | 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... |