Submission #54547

# Submission time Handle Problem Language Result Execution time Memory
54547 2018-07-04T04:42:52 Z 윤교준(#1492) Pairs (IOI07_pairs) C++11
53 / 100
95 ms 15120 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 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;
	}
};

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;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 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 2616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 3000 KB Output is correct
2 Correct 19 ms 3108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 3108 KB Output is correct
2 Correct 35 ms 3108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 3108 KB Output is correct
2 Correct 26 ms 3108 KB Output is correct
3 Correct 24 ms 3176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3176 KB Output is correct
2 Correct 4 ms 3176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 53 ms 14288 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 76 ms 14948 KB Output is correct
2 Correct 80 ms 14952 KB Output is correct
3 Correct 95 ms 15012 KB Output is correct
4 Correct 95 ms 15012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 15120 KB Output is correct
2 Correct 74 ms 15120 KB Output is correct
3 Correct 81 ms 15120 KB Output is correct
4 Correct 95 ms 15120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 15120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 15120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 15120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 15120 KB Output isn't correct
2 Halted 0 ms 0 KB -