Submission #521974

# Submission time Handle Problem Language Result Execution time Memory
521974 2022-02-03T14:38:06 Z emanuelsilva Pairs (IOI07_pairs) C++17
60 / 100
134 ms 10000 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) {
	
}

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);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2884 KB Output is correct
2 Correct 21 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3144 KB Output is correct
2 Correct 26 ms 3176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 3148 KB Output is correct
2 Correct 30 ms 3140 KB Output is correct
3 Correct 28 ms 3172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 5044 KB Output is correct
2 Correct 90 ms 10000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 5316 KB Output is correct
2 Correct 116 ms 7616 KB Output is correct
3 Correct 111 ms 7224 KB Output is correct
4 Correct 134 ms 6692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 5500 KB Output is correct
2 Correct 120 ms 7912 KB Output is correct
3 Correct 111 ms 9140 KB Output is correct
4 Correct 106 ms 7304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 324 KB Output isn't correct
2 Halted 0 ms 0 KB -