// 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 << ' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 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 |
5 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 |
Incorrect |
4 ms |
512 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
342 ms |
8824 KB |
Output is correct |
2 |
Correct |
341 ms |
8864 KB |
Output is correct |
3 |
Correct |
337 ms |
8872 KB |
Output is correct |
4 |
Correct |
320 ms |
8044 KB |
Output is correct |
5 |
Correct |
319 ms |
8096 KB |
Output is correct |
6 |
Incorrect |
302 ms |
7288 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
342 ms |
8824 KB |
Output is correct |
2 |
Correct |
341 ms |
8864 KB |
Output is correct |
3 |
Correct |
337 ms |
8872 KB |
Output is correct |
4 |
Correct |
320 ms |
8044 KB |
Output is correct |
5 |
Correct |
319 ms |
8096 KB |
Output is correct |
6 |
Incorrect |
302 ms |
7288 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 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 |
5 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 |
Incorrect |
4 ms |
512 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |