답안 #371027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
371027 2021-02-25T15:58:15 Z cheissmart Pairs (IOI07_pairs) C++14
45 / 100
70 ms 4696 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

int n, d, m;

struct solve1 {
	solve1() {
		vi a(n);
		for(int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(ALL(a));
		ll ans = 0;
		for(int i = 0, j = 0; i < n; i++) {
			while(a[i] - a[j] > d) j++;
			assert(a[i] - a[j] <= d);
			ans += i - j;
		}
		cout << ans << '\n';
	}
};


struct solve2 {
	static const int N = 150000 + 7;
	int bit[N];
	void add(int y, int val) {
		for(; y < N; y += y & -y)
			bit[y] += val;
	}
	int qry(int y) {
		int res = 0;
		for(; y; y -= y & -y)
			res += bit[y];
		return res;
	}
	solve2() {
		V<pi> a(n);
		for(int i = 0; i < n; i++) {
			int x, y;
			cin >> x >> y;
			a[i] = {x - y, x + y};
			assert(a[i].S < N);
		}
		V<array<int, 3>> ev;
		ll ans = 0;
		for(int i = 0; i < n; i++) {
			ev.PB({a[i].F, 0, a[i].S});
			ev.PB({a[i].F + d, 1, a[i].S});
		}
		sort(ALL(ev));
		deque<pi> dk;
		for(auto e:ev) {
			if(e[1] == 0) { // add point
				add(e[2], 1);
				dk.EB(e[0], e[2]);
			} else { // qry
				while(dk.size() && dk[0].F < e[0] - 2 * d) {
					add(dk[0].S, -1);
					dk.pop_front();
				}
				int l = max(e[2] - d, 1), r = min(e[2] + d, N - 1);
				ans += qry(r) - qry(l - 1) - 1;
			}
		}
		cout << ans / 2 << '\n';
	}
};

struct solve3 {
	solve3() {

	}
};

signed main()
{
	IO_OP;

	int b;
	cin >> b >> n >> d >> m;
	if(b == 1) solve1();
	else if(b == 2) solve2();
	else solve3();


}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 748 KB Output is correct
2 Correct 15 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 748 KB Output is correct
2 Correct 19 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 748 KB Output is correct
2 Correct 20 ms 748 KB Output is correct
3 Correct 22 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Incorrect 1 ms 1004 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 4320 KB Output is correct
2 Correct 55 ms 4320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 4320 KB Output is correct
2 Correct 59 ms 4340 KB Output is correct
3 Correct 61 ms 4320 KB Output is correct
4 Correct 60 ms 4320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 4320 KB Output is correct
2 Incorrect 58 ms 4696 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -