Submission #208549

# Submission time Handle Problem Language Result Execution time Memory
208549 2020-03-11T13:48:50 Z opukittpceno_hhr Examination (JOI19_examination) C++17
100 / 100
1880 ms 75496 KB
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>


using namespace std;
using namespace __gnu_pbds;

template<typename T>
using flex_set = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;  

struct Block {
	int sz;
	flex_set<pair<int, int>> kek;

	int solve(int x) {
		return kek.order_of_key(make_pair(x, -1));
	}

	void insert(int x) {
		sz++;
		kek.insert(make_pair(x, sz));
	}

	Block() {}
};

struct UltraFenw {
	int n;
	vector<Block> f;

	int cnt(int r, int x) {
		int ans = 0;
		for (int i = r; i >= 0; i = (i & (i + 1)) - 1) {
			ans += f[i].solve(x);
		}
		return ans;
	}

	int cnt(int l, int r, int x) {
		return cnt(r, x) - cnt(l - 1, x);
	}

	void insert(int pos, int val) {
		for (int i = pos; i < n; i = i | (i + 1)) {
			f[i].insert(val);
		}
	}

	UltraFenw(int n_) {
		n = n_;
		f.resize(n);
	}
};

struct Query {
	int a, b, c;
	int ind;

	Query(int a_, int b_, int c_, int ind_) {
		a = a_;
		b = b_;
		c = c_;
		ind = ind_;
	};

	bool operator<(const Query &other) const {
		return c < other.c;
	}
};

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, q;
	cin >> n >> q;
	vector<pair<int, int>> a(n);
	for (auto &t : a) cin >> t.first >> t.second;
	sort(a.begin(), a.end());
	vector<int> f(n);
	vector<int> s(n);
	vector<int> sm(n);
	for (int i = 0; i < n; i++) {
		tie(f[i], s[i]) = a[i];
		sm[i] = f[i] + s[i];
	}
	UltraFenw fn(n);
	vector<Query> qs;
	for (int i = 0; i < q; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		qs.push_back(Query(x, y, z, i));
	}
	sort(qs.rbegin(), qs.rend());
	vector<int> ind(n);
	iota(ind.begin(), ind.end(), 0);
	sort(ind.rbegin(), ind.rend(), [&](int i, int j) {
		return sm[i] < sm[j];
	});
	int pnt = 0;
	vector<int> ans(q);
	for (auto t : qs) {
		while (pnt < n && sm[ind[pnt]] >= t.c) {
			fn.insert(ind[pnt], s[ind[pnt]]);
			pnt++;
		}
		int i = lower_bound(f.begin(), f.end(), t.a) - f.begin();
		ans[t.ind] = fn.cnt(i, n - 1, t.b);
	}
	for (auto t : ans) {
		cout << t << ' ';
	}
	cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 15 ms 1912 KB Output is correct
8 Correct 17 ms 1912 KB Output is correct
9 Correct 15 ms 1912 KB Output is correct
10 Correct 13 ms 1912 KB Output is correct
11 Correct 14 ms 1912 KB Output is correct
12 Correct 11 ms 1912 KB Output is correct
13 Correct 15 ms 1912 KB Output is correct
14 Correct 15 ms 1912 KB Output is correct
15 Correct 15 ms 1912 KB Output is correct
16 Correct 12 ms 1912 KB Output is correct
17 Correct 12 ms 1912 KB Output is correct
18 Correct 9 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1855 ms 70436 KB Output is correct
2 Correct 1797 ms 72912 KB Output is correct
3 Correct 1844 ms 73076 KB Output is correct
4 Correct 1109 ms 72360 KB Output is correct
5 Correct 958 ms 72168 KB Output is correct
6 Correct 638 ms 71528 KB Output is correct
7 Correct 1418 ms 72772 KB Output is correct
8 Correct 1669 ms 72904 KB Output is correct
9 Correct 1161 ms 72732 KB Output is correct
10 Correct 492 ms 72016 KB Output is correct
11 Correct 837 ms 72168 KB Output is correct
12 Correct 378 ms 71016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1855 ms 70436 KB Output is correct
2 Correct 1797 ms 72912 KB Output is correct
3 Correct 1844 ms 73076 KB Output is correct
4 Correct 1109 ms 72360 KB Output is correct
5 Correct 958 ms 72168 KB Output is correct
6 Correct 638 ms 71528 KB Output is correct
7 Correct 1418 ms 72772 KB Output is correct
8 Correct 1669 ms 72904 KB Output is correct
9 Correct 1161 ms 72732 KB Output is correct
10 Correct 492 ms 72016 KB Output is correct
11 Correct 837 ms 72168 KB Output is correct
12 Correct 378 ms 71016 KB Output is correct
13 Correct 1525 ms 73576 KB Output is correct
14 Correct 1860 ms 73532 KB Output is correct
15 Correct 1836 ms 72960 KB Output is correct
16 Correct 831 ms 72556 KB Output is correct
17 Correct 1034 ms 72680 KB Output is correct
18 Correct 608 ms 71656 KB Output is correct
19 Correct 1558 ms 73452 KB Output is correct
20 Correct 1719 ms 73460 KB Output is correct
21 Correct 1337 ms 73524 KB Output is correct
22 Correct 477 ms 72040 KB Output is correct
23 Correct 853 ms 71924 KB Output is correct
24 Correct 408 ms 71016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 15 ms 1912 KB Output is correct
8 Correct 17 ms 1912 KB Output is correct
9 Correct 15 ms 1912 KB Output is correct
10 Correct 13 ms 1912 KB Output is correct
11 Correct 14 ms 1912 KB Output is correct
12 Correct 11 ms 1912 KB Output is correct
13 Correct 15 ms 1912 KB Output is correct
14 Correct 15 ms 1912 KB Output is correct
15 Correct 15 ms 1912 KB Output is correct
16 Correct 12 ms 1912 KB Output is correct
17 Correct 12 ms 1912 KB Output is correct
18 Correct 9 ms 1912 KB Output is correct
19 Correct 1855 ms 70436 KB Output is correct
20 Correct 1797 ms 72912 KB Output is correct
21 Correct 1844 ms 73076 KB Output is correct
22 Correct 1109 ms 72360 KB Output is correct
23 Correct 958 ms 72168 KB Output is correct
24 Correct 638 ms 71528 KB Output is correct
25 Correct 1418 ms 72772 KB Output is correct
26 Correct 1669 ms 72904 KB Output is correct
27 Correct 1161 ms 72732 KB Output is correct
28 Correct 492 ms 72016 KB Output is correct
29 Correct 837 ms 72168 KB Output is correct
30 Correct 378 ms 71016 KB Output is correct
31 Correct 1525 ms 73576 KB Output is correct
32 Correct 1860 ms 73532 KB Output is correct
33 Correct 1836 ms 72960 KB Output is correct
34 Correct 831 ms 72556 KB Output is correct
35 Correct 1034 ms 72680 KB Output is correct
36 Correct 608 ms 71656 KB Output is correct
37 Correct 1558 ms 73452 KB Output is correct
38 Correct 1719 ms 73460 KB Output is correct
39 Correct 1337 ms 73524 KB Output is correct
40 Correct 477 ms 72040 KB Output is correct
41 Correct 853 ms 71924 KB Output is correct
42 Correct 408 ms 71016 KB Output is correct
43 Correct 1668 ms 75496 KB Output is correct
44 Correct 1571 ms 75368 KB Output is correct
45 Correct 1880 ms 75496 KB Output is correct
46 Correct 862 ms 73832 KB Output is correct
47 Correct 979 ms 73708 KB Output is correct
48 Correct 419 ms 71272 KB Output is correct
49 Correct 1485 ms 75380 KB Output is correct
50 Correct 1388 ms 75240 KB Output is correct
51 Correct 1253 ms 75088 KB Output is correct
52 Correct 570 ms 73572 KB Output is correct
53 Correct 858 ms 72808 KB Output is correct