Submission #54551

# Submission time Handle Problem Language Result Execution time Memory
54551 2018-07-04T05:10:20 Z 윤교준(#1492) Pairs (IOI07_pairs) C++11
93 / 100
289 ms 40444 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)))
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

namespace TC1 {
	int A[100005];

	ll Ans;
	int N, L, M;

	void init(int _N, int _L, int _M) {
	    N = _N; L = _L; M = _M;
		Ans = 0;
	}
	void run() {
		for(int i = 1; i <= N; i++) cin >> A[i];
		sort(A+1, A+N+1);

		for(int i = 1, j = 1; i <= N; i++) {
			for(; j <= N && A[j] <= A[i]+L; j++);
			Ans += j-i-1;
		}

		cout << Ans << endl;
	}
};

namespace TC2 {
	struct EVT {
		EVT(int type, int x, int y) : type(type), x(x), y(y) {}
		int type, x, y;

		bool operator < (const EVT &t) const {
			if(x != t.x) return x < t.x;
			if(type != t.type) return type < t.type;
			return y < t.type;
		}
	};

	const static int MX = 262144;
	struct SEG {
		SEG() { init(); }
		int d[MX*2];
		void init() { fill(d, d+MX*2, 0); }
		void upd(int x, int r) {
			for(x += 75000 + MX; x; x /= 2)
				d[x] += r;
		}
		int get(int s, int e) {
			int r = 0;
			s += 75000; e += 75000;
			s = max(1, s); e = min(75000*2, e);
			for(s += MX, e += MX; s <= e; s /= 2, e /= 2) {
				if(s&1) r += d[s++];
				if(~e&1) r += d[e--];
			}
			return r;
		}
	} seg;

	vector<EVT> EV;

	int X[100005], Y[100005];

	ll Ans;
	int N, L, M;

	void init(int _N, int _L, int _M) {
	    N = _N; L = _L; M = _M;
		Ans = 0;
	}
	void run() {
		{
			vector<pii> V;
			for(int i = 1, x, y; i <= N; i++) {
				cin >> x >> y;
				V.eb(x+y, y-x);
			}
			sorv(V);
			for(int i = 1; i <= N; i++)
				tie(X[i], Y[i]) = V[i-1];
		}

		for(int i = 1; i <= N; i++) {
			EV.eb(2, X[i], Y[i]);
			EV.eb(1, X[i]+L+1, Y[i]);
		}
		sorv(EV);

		for(auto &e : EV) {
			if(2 == e.type) {
				Ans += seg.get(e.y - L, e.y + L);
				seg.upd(e.y, 1);
			} else {
				seg.upd(e.y, -1);
			}
		}

		cout << Ans << endl;
	}
};

namespace TC3 {
	const static int MX = 75*3 + 5;

	struct BIT {
		int d[MX][MX][MX];
		void init() {
			for(int i = 0; i < MX; i++)
                for(int j = 0; j < MX; j++)
                    fill(d[i][j], d[i][j]+MX, 0);
		}
		void upd(int x, int y, int z, int r) {
			x++; y++; z++;
			for(int i = x; i < MX; i += rb(i))
				for(int j = y; j < MX; j += rb(j))
                    for(int k = z; k < MX; k += rb(k))
                        d[i][j][k] += r;
		}
		int get(int x, int y, int z) {
			x++; y++; z++;
			int r = 0;
			for(int i = x; i; i -= rb(i))
				for(int j = y; j; j -= rb(j))
                    for(int k = z; k; k -= rb(k))
                        r += d[i][j][k];
			return r;
		}
	} bit;

	struct EVT {
		EVT(int type, int x, int y, int z, int t) : type(type), x(x), y(y), z(z), t(t) {}
		int type, x, y, z, t;

		bool operator < (const EVT &tt) const {
			if(x != tt.x) return x < tt.x;
			if(type != tt.type) return type < tt.type;
			if(t != tt.t) return t < tt.t;
			return pii(y, z) < pii(tt.y, tt.z);
		}
	};

	int ff(int x, int y, int z) {
		x = min(75*3, max(0, x));
		y = min(75*3, max(0, y));
		z = min(75*3, max(0, z));
		return bit.get(x, y, z);
	}
	int f(int sx, int sy, int sz, int ex, int ey, int ez) {
		sx--; sy--; sz--;
        return ff(ex, ey, ez) - ff(sx, ey, ez) - ff(ex, sy, ez) - ff(ex, ey, sz)
                + ff(sx, sy, ez) + ff(sx, ey, sz) + ff(ex, sy, sz) - ff(sx, sy, sz);
	}

	vector<EVT> VE;

	int X[100005], Y[100005], Z[100005], T[100005];

	ll Ans;
	int N, L, M;

	void init(int _N, int _L, int _M) {
		N = _N; L = _L; M = _M;
	}
	void run() {
		{
			vector<pair<pii, pii>> V;
			for(int i = 1, x, y, z; i <= N; i++) {
				cin >> x >> y >> z;
				V.eb(pii(x+y+z, x+y-z), pii(x-y+z, x-y-z));
			}
			sorv(V);
			for(int i = 1; i <= N; i++) {
				tie(X[i], T[i]) = V[i-1].first;
				tie(Y[i], Z[i]) = V[i-1].second;
			}
		}

		for(int i = 1; i <= N; i++) {
			T[i] += 75;
			Y[i] += 75;
			Z[i] += 150;
		}

		for(int i = 1; i <= N; i++) {
			VE.eb(2, X[i], Y[i], Z[i], T[i]);
			VE.eb(1, X[i]+L+1, Y[i], Z[i], T[i]);
		}
		sorv(VE);

		for(auto &e : VE) {
			if(2 == e.type) {
				Ans += f(e.y-L, e.z-L, e.t-L, e.y+L, e.z+L, e.t+L);
				bit.upd(e.y, e.z, e.t, 1);
			} else {
				bit.upd(e.y, e.z, e.t, -1);
			}
		}

		cout << Ans << endl;
	}
};

int K, N, L, M;

int main() {
    //freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);

	cin >> K >> N >> L >> M;

	if(1 == K) {
		TC1 :: init(N, L, M);
		TC1 :: run();
	}
	else if(2 == K) {
        TC2 :: init(N, L, M);
        TC2 :: run();
	}
	else {
        TC3 :: init(N, L, M);
        TC3 :: run();
	}
	return 0;
}

Compilation message

pairs.cpp: In member function 'int TC3::BIT::get(int, int, int)':
pairs.cpp:137:21: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
                     for(int k = z; k; k -= rb(k))
                     ^~~
pairs.cpp:139:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    return r;
    ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2424 KB Output is correct
2 Correct 4 ms 2532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2860 KB Output is correct
2 Correct 18 ms 2868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2900 KB Output is correct
2 Correct 24 ms 2976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 2976 KB Output is correct
2 Correct 29 ms 3052 KB Output is correct
3 Correct 24 ms 3052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3052 KB Output is correct
2 Correct 5 ms 3052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 47 ms 14304 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 74 ms 15300 KB Output is correct
2 Correct 78 ms 15300 KB Output is correct
3 Correct 90 ms 15300 KB Output is correct
4 Correct 79 ms 15300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 15300 KB Output is correct
2 Correct 92 ms 15300 KB Output is correct
3 Correct 82 ms 15300 KB Output is correct
4 Correct 84 ms 15300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 21004 KB Output is correct
2 Correct 12 ms 21004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 21004 KB Output is correct
2 Correct 143 ms 21004 KB Output is correct
3 Correct 173 ms 21004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 227 ms 32836 KB Output is correct
2 Correct 240 ms 32836 KB Output is correct
3 Correct 151 ms 32836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 289 ms 40420 KB Output is correct
2 Correct 250 ms 40420 KB Output is correct
3 Correct 194 ms 40444 KB Output is correct