답안 #521977

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521977 2022-02-03T14:39:04 Z emanuelsilva Pairs (IOI07_pairs) C++17
60 / 100
120 ms 9904 KB
#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 = 80;

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) {
	assert(false);	
}

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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 2888 KB Output is correct
2 Correct 21 ms 2888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 3144 KB Output is correct
2 Correct 28 ms 3144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 3144 KB Output is correct
2 Correct 28 ms 3144 KB Output is correct
3 Correct 27 ms 3068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 5020 KB Output is correct
2 Correct 92 ms 9904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 5188 KB Output is correct
2 Correct 120 ms 7472 KB Output is correct
3 Correct 108 ms 7052 KB Output is correct
4 Correct 108 ms 6516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 5188 KB Output is correct
2 Correct 119 ms 7420 KB Output is correct
3 Correct 100 ms 8676 KB Output is correct
4 Correct 95 ms 6920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -