Submission #129947

# Submission time Handle Problem Language Result Execution time Memory
129947 2019-07-13T15:13:02 Z tmwilliamlin168 Pairs (IOI07_pairs) C++14
27 / 100
4000 ms 47864 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN=1e5;
int b, n, d, m;
long long ans;

namespace subtask2 {
	static const int MG1=1.5e5;
	array<int, 2> a[mxN];
	int ft[MG1];

	void upd(int i, int x) {
		for(++i; i<MG1; i+=i&-i)
			ft[i]+=x;
	}

	int qry(int i) {
		int r=0;
		for(; i>0; i-=i&-i)
			r+=ft[i];
		return r;
	}

	void solve() {
		for(int i=0; i<n; ++i) {
			cin >> a[i][0];
			if(b^1) {
				cin >> a[i][1];
				tie(a[i][0], a[i][1])=make_pair(a[i][0]+a[i][1], a[i][0]-a[i][1]-1+m);
			}
		}
		sort(a, a+n);
		for(int i=0, j=0; i<n; ++i) {
			while(a[j][0]<a[i][0]-d)
				upd(a[j++][1], -1);
			ans+=qry(a[i][1]+d+1)-qry(a[i][1]-d);
			upd(a[i][1], 1);
		}
	}
}

namespace subtask3 {
	static const int MG1=223;
	array<int, 3> a[mxN];
	array<int, 4> b[mxN];
	int c[MG1+1][MG1+1][MG1+1];

	void solve() {
		for(int i=0; i<n; ++i) {
			cin >> a[i][0] >> a[i][1] >> a[i][2];
			b[i][0]=a[i][0]+a[i][1]+a[i][2]-3;
			b[i][1]=a[i][0]+a[i][1]-a[i][2]-2+m;
			b[i][2]=a[i][0]-a[i][1]+a[i][2]-2+m;
			b[i][3]=a[i][0]-a[i][1]-a[i][2]-1+2*m;
		}
		for(int i=0; i<MG1; ++i) {
			memset(c, 0, sizeof(c));
			for(int j=0; j<n; ++j)
				if(b[j][3]==i)
					++c[b[j][0]+1][b[j][1]+1][b[j][2]+1];
			for(int j1=1; j1<=MG1; ++j1) {
				for(int j2=1; j2<=MG1; ++j2) {
					for(int j3=1; j3<=MG1; ++j3)
						c[j1][j2][j3]+=c[j1][j2][j3-1];
					for(int j3=1; j3<=MG1; ++j3)
						c[j1][j2][j3]+=c[j1][j2-1][j3];
				}
				for(int j2=1; j2<=MG1; ++j2)
					for(int j3=1; j3<=MG1; ++j3)
						c[j1][j2][j3]+=c[j1-1][j2][j3];
			}
			for(int j=0; j<n; ++j) {
				if(b[j][3]-d<=i&&i<=b[j][3]+d) {
					int l1=max(b[j][0]-d, 0), r1=min(b[j][0]+d+1, MG1), l2=max(b[j][1]-d, 0), r2=min(b[j][1]+d+1, MG1), l3=max(b[j][2]-d, 0), r3=min(b[j][2]+d+1, MG1);
					ans+=c[r1][r2][r3]-c[r1][r2][l3]-c[r1][l2][r3]+c[r1][l2][l3]-c[l1][r2][r3]+c[l1][r2][l3]+c[l1][l2][r3]-c[l1][l2][l3];
				}
			}
		}
		ans=(ans-n)/2;
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> b >> n >> d >> m;
	if(b<3)
		subtask2::solve();
	else
		subtask3::solve();
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1592 KB Output is correct
2 Correct 28 ms 1556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 2068 KB Output is correct
2 Runtime error 30 ms 2908 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 31 ms 2940 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Incorrect 3 ms 1016 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 1696 KB Output is correct
2 Correct 36 ms 1688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 2008 KB Output is correct
2 Correct 41 ms 1960 KB Output is correct
3 Correct 42 ms 2064 KB Output is correct
4 Correct 40 ms 1940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 2808 KB Output is correct
2 Incorrect 45 ms 2808 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4016 ms 44408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4006 ms 47864 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4025 ms 47864 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4011 ms 47864 KB Time limit exceeded
2 Halted 0 ms 0 KB -