// author: erray
#include<bits/stdc++.h>
using namespace std;
template<typename T, typename F> string to_string(pair<T, F> p);
template<typename T, typename F, typename Tr> string to_string(tuple<T, F, Tr> p);
template<typename T, typename F, typename Tr, typename Th> string to_string(tuple<T, F, Tr, Th> p);
string to_string(string s) {
return '"' + s + '"';
}
string to_string(char c) {
return (string) "'" + c + "'";
}
string to_string(const char* p) {
return to_string((string) p);
}
string to_string(bool B) {
return (B ? "true" : "false");
}
string to_string(vector<bool> v) {
string res = "{";
for (int i = 0; i < (int) v.size(); ++i) {
if ((int) res.size() > 1) res += ", ";
res += to_string(v[i]);
}
res += "}";
return res;
}
template<size_t T> string to_string(bitset<T> bs) {
return bs.to_string();
}
template<typename T> string to_string(T v) {
string res = "{";
for (auto& el : v) {
if ((int) res.size() > 1) res += ", ";
res += to_string(el);
}
res += "}";
return res;
}
template<typename T, typename F> string to_string(pair<T, F> p) {
return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
template<typename T, typename F, typename Tr> string to_string(tuple<T, F, Tr> p) {
return '(' + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ')';
}
template<typename T, typename F, typename Tr, typename Th> string to_string(tuple<T, F, Tr, Th> p) {
return '(' + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ')';
}
void debug_out() {
cerr << endl;
}
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" , debug_out(__VA_ARGS__)
#else
#define debug(...) (void) 37
#endif
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
vector<tuple<int, int, int>> ord(n);
for (int i = 0; i < n; ++i) {
ord[i] = make_tuple(a[i].first, a[i].second, i);
}
sort(ord.rbegin(), ord.rend(), [&](auto x, auto y) {
return get<1>(x) < get<1>(y);
});
vector<int> ind(n), sum(n);
for (int i = 0; i < n; ++i) {
ind[get<2>(ord[i])] = i;
sum[i] = get<0>(ord[i]) + get<1>(ord[i]);
}
debug(ord, a);
const int BLOCK = (int) ceil(sqrt(n)), sz = (n - 1) / BLOCK + 1;
vector<vector<int>> dec(sz);
vector<int> topPoint(sz);
for (int i = 0; i < n; ++i) {
dec[i / BLOCK].push_back(sum[i]);
topPoint[i / BLOCK] = get<1>(ord[i]);
}
for (int i = 0; i < sz; ++i) {
sort(dec[i].rbegin(), dec[i].rend());
}
debug(BLOCK, sz, topPoint);
debug(dec);
vector<tuple<int, int, int, int>> q(m);
vector<int> ans(m);
for (int i = 0; i < m; ++i) {
cin >> get<0>(q[i]) >> get<1>(q[i]) >> get<2>(q[i]);
get<3>(q[i]) = i;
}
sort(q.begin(), q.end());
debug(sum);
int lst = 0;
vector<bool> mark(n);
for (auto[x, y, z, wh] : q) {
debug(x, y, z, wh, lst);
while (lst < n && a[lst].first < x) {
int mind = ind[lst];
mark[mind] = true;
dec[mind / BLOCK].erase(lower_bound(dec[mind / BLOCK].begin(), dec[mind / BLOCK].end(), a[lst].first + a[lst].second, [](int tx, int ty) {
return tx > ty;
}));
++lst;
}
int cur = 0, res = 0;
while (cur < sz && topPoint[cur] >= y) {
res += (int) (lower_bound(dec[cur].begin(), dec[cur].end(), z - 1, [](int tx, int ty) {
return tx > ty;
}) - dec[cur].begin());
++cur;
}
debug(cur, res);
cur *= BLOCK;
while (cur < n && get<1>(ord[cur]) >= y) {
res += (!mark[cur] && sum[cur] >= z);
++cur;
}
debug(cur);
ans[wh] = res;
}
for (auto el : ans) cout << el << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
7 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
640 KB |
Output is correct |
11 |
Correct |
4 ms |
640 KB |
Output is correct |
12 |
Correct |
4 ms |
512 KB |
Output is correct |
13 |
Correct |
4 ms |
640 KB |
Output is correct |
14 |
Correct |
4 ms |
640 KB |
Output is correct |
15 |
Correct |
4 ms |
640 KB |
Output is correct |
16 |
Correct |
3 ms |
640 KB |
Output is correct |
17 |
Correct |
4 ms |
640 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
340 ms |
8824 KB |
Output is correct |
2 |
Correct |
361 ms |
8824 KB |
Output is correct |
3 |
Correct |
358 ms |
8824 KB |
Output is correct |
4 |
Correct |
328 ms |
8012 KB |
Output is correct |
5 |
Correct |
309 ms |
8056 KB |
Output is correct |
6 |
Correct |
272 ms |
7288 KB |
Output is correct |
7 |
Correct |
318 ms |
8696 KB |
Output is correct |
8 |
Correct |
479 ms |
8696 KB |
Output is correct |
9 |
Correct |
487 ms |
8696 KB |
Output is correct |
10 |
Correct |
212 ms |
7800 KB |
Output is correct |
11 |
Correct |
195 ms |
7800 KB |
Output is correct |
12 |
Correct |
103 ms |
6904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
340 ms |
8824 KB |
Output is correct |
2 |
Correct |
361 ms |
8824 KB |
Output is correct |
3 |
Correct |
358 ms |
8824 KB |
Output is correct |
4 |
Correct |
328 ms |
8012 KB |
Output is correct |
5 |
Correct |
309 ms |
8056 KB |
Output is correct |
6 |
Correct |
272 ms |
7288 KB |
Output is correct |
7 |
Correct |
318 ms |
8696 KB |
Output is correct |
8 |
Correct |
479 ms |
8696 KB |
Output is correct |
9 |
Correct |
487 ms |
8696 KB |
Output is correct |
10 |
Correct |
212 ms |
7800 KB |
Output is correct |
11 |
Correct |
195 ms |
7800 KB |
Output is correct |
12 |
Correct |
103 ms |
6904 KB |
Output is correct |
13 |
Correct |
564 ms |
9208 KB |
Output is correct |
14 |
Correct |
400 ms |
9208 KB |
Output is correct |
15 |
Correct |
357 ms |
8824 KB |
Output is correct |
16 |
Correct |
535 ms |
8444 KB |
Output is correct |
17 |
Correct |
341 ms |
8440 KB |
Output is correct |
18 |
Correct |
274 ms |
7288 KB |
Output is correct |
19 |
Correct |
511 ms |
9288 KB |
Output is correct |
20 |
Correct |
474 ms |
9208 KB |
Output is correct |
21 |
Correct |
853 ms |
9376 KB |
Output is correct |
22 |
Correct |
213 ms |
7976 KB |
Output is correct |
23 |
Correct |
199 ms |
7928 KB |
Output is correct |
24 |
Correct |
104 ms |
6904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
7 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
640 KB |
Output is correct |
11 |
Correct |
4 ms |
640 KB |
Output is correct |
12 |
Correct |
4 ms |
512 KB |
Output is correct |
13 |
Correct |
4 ms |
640 KB |
Output is correct |
14 |
Correct |
4 ms |
640 KB |
Output is correct |
15 |
Correct |
4 ms |
640 KB |
Output is correct |
16 |
Correct |
3 ms |
640 KB |
Output is correct |
17 |
Correct |
4 ms |
640 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
340 ms |
8824 KB |
Output is correct |
20 |
Correct |
361 ms |
8824 KB |
Output is correct |
21 |
Correct |
358 ms |
8824 KB |
Output is correct |
22 |
Correct |
328 ms |
8012 KB |
Output is correct |
23 |
Correct |
309 ms |
8056 KB |
Output is correct |
24 |
Correct |
272 ms |
7288 KB |
Output is correct |
25 |
Correct |
318 ms |
8696 KB |
Output is correct |
26 |
Correct |
479 ms |
8696 KB |
Output is correct |
27 |
Correct |
487 ms |
8696 KB |
Output is correct |
28 |
Correct |
212 ms |
7800 KB |
Output is correct |
29 |
Correct |
195 ms |
7800 KB |
Output is correct |
30 |
Correct |
103 ms |
6904 KB |
Output is correct |
31 |
Correct |
564 ms |
9208 KB |
Output is correct |
32 |
Correct |
400 ms |
9208 KB |
Output is correct |
33 |
Correct |
357 ms |
8824 KB |
Output is correct |
34 |
Correct |
535 ms |
8444 KB |
Output is correct |
35 |
Correct |
341 ms |
8440 KB |
Output is correct |
36 |
Correct |
274 ms |
7288 KB |
Output is correct |
37 |
Correct |
511 ms |
9288 KB |
Output is correct |
38 |
Correct |
474 ms |
9208 KB |
Output is correct |
39 |
Correct |
853 ms |
9376 KB |
Output is correct |
40 |
Correct |
213 ms |
7976 KB |
Output is correct |
41 |
Correct |
199 ms |
7928 KB |
Output is correct |
42 |
Correct |
104 ms |
6904 KB |
Output is correct |
43 |
Correct |
524 ms |
11172 KB |
Output is correct |
44 |
Correct |
528 ms |
11256 KB |
Output is correct |
45 |
Correct |
399 ms |
11384 KB |
Output is correct |
46 |
Correct |
526 ms |
9720 KB |
Output is correct |
47 |
Correct |
348 ms |
9592 KB |
Output is correct |
48 |
Correct |
337 ms |
7160 KB |
Output is correct |
49 |
Correct |
496 ms |
11044 KB |
Output is correct |
50 |
Correct |
847 ms |
11256 KB |
Output is correct |
51 |
Correct |
1008 ms |
11056 KB |
Output is correct |
52 |
Correct |
247 ms |
9464 KB |
Output is correct |
53 |
Correct |
205 ms |
8712 KB |
Output is correct |