Submission #102574

# Submission time Handle Problem Language Result Execution time Memory
102574 2019-03-26T02:01:45 Z TMJN Examination (JOI19_examination) C++14
2 / 100
3000 ms 102200 KB
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

struct T{
	int data, sl, sr, tl, tr, next;
};

int N, Q, s[100000], t[100000], x, y, z;
vector<int>svec, tvec;
vector<T>tree;

void update(int k, int s, int t) {
	if (tree[k].sl <= s&&s <= tree[k].sr&&tree[k].tl <= t&&t <= tree[k].tr) {
		if (tree[k].sl == tree[k].sr&&tree[k].tl == tree[k].tr) {
			++tree[k].data;
		}
		else {
			if (tree[k].next == -1) {
				tree[k].next = tree.size();
				tree.push_back({ 0,tree[k].sl,(tree[k].sl + tree[k].sr) / 2,tree[k].tl,(tree[k].tl + tree[k].tr) / 2,-1 });
				tree.push_back({ 0,tree[k].sl,(tree[k].sl + tree[k].sr) / 2,(tree[k].tl + tree[k].tr) / 2 + 1,tree[k].tr,-1 });
				tree.push_back({ 0,(tree[k].sl + tree[k].sr) / 2 + 1,tree[k].sr,tree[k].tl,(tree[k].tl + tree[k].tr) / 2,-1 });
				tree.push_back({ 0,(tree[k].sl + tree[k].sr) / 2 + 1,tree[k].sr,(tree[k].tl + tree[k].tr) / 2 + 1,tree[k].tr,-1 });
			}
			update(tree[k].next, s, t);
			update(tree[k].next + 1, s, t);
			update(tree[k].next + 2, s, t);
			update(tree[k].next + 3, s, t);
			tree[k].data = tree[tree[k].next].data + tree[tree[k].next + 1].data + tree[tree[k].next + 2].data + tree[tree[k].next + 3].data;
		}
	}
}

int calc(int k) {
	if (tree[k].data == 0)return 0;
	if (svec[tree[k].sr] < x || tvec[tree[k].tr] < y || svec[tree[k].sr] + tvec[tree[k].tr] < z)return 0;
	if (x <= svec[tree[k].sl] && y <= tvec[tree[k].tl] && z <= svec[tree[k].sl] + tvec[tree[k].tl])return tree[k].data;
	return calc(tree[k].next) + calc(tree[k].next + 1) + calc(tree[k].next + 2) + calc(tree[k].next + 3);
}

int main() {
	cin >> N >> Q;
	for (int i = 0; i < N; ++i) {
		cin >> s[i] >> t[i];
		svec.push_back(s[i]);
		tvec.push_back(t[i]);
	}
	sort(svec.begin(), svec.end());
	svec.erase(unique(svec.begin(), svec.end()), svec.end());
	sort(tvec.begin(), tvec.end());
	tvec.erase(unique(tvec.begin(), tvec.end()), tvec.end());
	tree.push_back({ 0,0,(int)svec.size() - 1,0,(int)tvec.size() - 1,-1 });
	for (int i = 0; i < N; ++i) {
		update(0, lower_bound(svec.begin(), svec.end(), s[i]) - svec.begin(), lower_bound(tvec.begin(), tvec.end(), t[i]) - tvec.begin());
	}
	for (int i = 0; i < Q; ++i) {
		cin >> x >> y >> z;
		cout << calc(0) << endl;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 41 ms 3712 KB Output is correct
8 Correct 38 ms 3712 KB Output is correct
9 Correct 34 ms 3680 KB Output is correct
10 Correct 20 ms 2052 KB Output is correct
11 Correct 27 ms 2180 KB Output is correct
12 Correct 11 ms 456 KB Output is correct
13 Correct 38 ms 3728 KB Output is correct
14 Correct 47 ms 3712 KB Output is correct
15 Correct 45 ms 3712 KB Output is correct
16 Correct 12 ms 972 KB Output is correct
17 Correct 15 ms 1032 KB Output is correct
18 Correct 9 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3015 ms 102200 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3015 ms 102200 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 41 ms 3712 KB Output is correct
8 Correct 38 ms 3712 KB Output is correct
9 Correct 34 ms 3680 KB Output is correct
10 Correct 20 ms 2052 KB Output is correct
11 Correct 27 ms 2180 KB Output is correct
12 Correct 11 ms 456 KB Output is correct
13 Correct 38 ms 3728 KB Output is correct
14 Correct 47 ms 3712 KB Output is correct
15 Correct 45 ms 3712 KB Output is correct
16 Correct 12 ms 972 KB Output is correct
17 Correct 15 ms 1032 KB Output is correct
18 Correct 9 ms 384 KB Output is correct
19 Execution timed out 3015 ms 102200 KB Time limit exceeded
20 Halted 0 ms 0 KB -