Submission #208546

# Submission time Handle Problem Language Result Execution time Memory
208546 2020-03-11T13:45:53 Z opukittpceno_hhr Examination (JOI19_examination) C++17
2 / 100
3000 ms 12756 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 {
	vector<int> hv;

	int solve(int x) {
		int ans = 0;
		for (auto t : hv) {
			ans += (t >= x);
		}
		return ans;
	}

	void insert(int x) {
		hv.push_back(x);
	}

	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 632 KB Output is correct
8 Correct 14 ms 632 KB Output is correct
9 Correct 15 ms 632 KB Output is correct
10 Correct 13 ms 636 KB Output is correct
11 Correct 14 ms 632 KB Output is correct
12 Correct 12 ms 632 KB Output is correct
13 Correct 22 ms 760 KB Output is correct
14 Correct 20 ms 632 KB Output is correct
15 Correct 21 ms 632 KB Output is correct
16 Correct 18 ms 632 KB Output is correct
17 Correct 13 ms 632 KB Output is correct
18 Correct 10 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3074 ms 12756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3074 ms 12756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 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 632 KB Output is correct
8 Correct 14 ms 632 KB Output is correct
9 Correct 15 ms 632 KB Output is correct
10 Correct 13 ms 636 KB Output is correct
11 Correct 14 ms 632 KB Output is correct
12 Correct 12 ms 632 KB Output is correct
13 Correct 22 ms 760 KB Output is correct
14 Correct 20 ms 632 KB Output is correct
15 Correct 21 ms 632 KB Output is correct
16 Correct 18 ms 632 KB Output is correct
17 Correct 13 ms 632 KB Output is correct
18 Correct 10 ms 636 KB Output is correct
19 Execution timed out 3074 ms 12756 KB Time limit exceeded
20 Halted 0 ms 0 KB -