#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Общий файл.
#include <ext/pb_ds/tree_policy.hpp> // Содержит класс tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define long unsigned long
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define PI 2*acos(0.0)
void solve(int test) {
int n, q;
cin >> n >> q;
vector <int> a(n), b(n);
vector <pair <pii, pii>> queries(q);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < q; i++) {
auto &to = queries[i];
cin >> to.first.first >> to.first.second >> to.second.first;
to.second.second = i;
}
vector <int> inds(n);
iota(all(inds), 0);
sort(all(inds), [&](int i, int j) {
return a[i] < a[j];
});
int i = n - 1;
ordered_set st;
sort(rall(queries));
vector <int> ans(q);
for (auto to : queries) {
auto x = to.first.first, y = to.first.second, z = to.second.first;
if (x + y < z) continue;
auto ind = to.second.second;
while (i >= 0 && a[inds[i]] >= x) {
st.insert(b[inds[i--]]);
}
ans[ind] = sz(st) - st.order_of_key(y);
}
sort(all(inds), [&](int i, int j) {
return a[i] + b[i] < a[j] + b[j];
});
i = n - 1;
ordered_set math, infor;
sort(all(queries), [&](pair <pii, pii> i, pair <pii, pii> j) {
return i.second.first > j.second.first;
});
for (auto to : queries) {
auto x = to.first.first, y = to.first.second, z = to.second.first;
if (x + y >= z) continue;
auto ind = to.second.second;
while (i >= 0 && a[inds[i]] + b[inds[i]] >= z) {
math.insert(a[inds[i]]);
infor.insert(b[inds[i]]);
i--;
}
int saizu = n - i - 1;
ans[ind] = (saizu - math.order_of_key(x)) + (saizu - infor.order_of_key(y)) - saizu;
}
for (auto to : ans) cout << to << endl;
}
int main() {
do_not_disturb
int t = 1;
//~ cin >> t;
for (int i = 1; i <= t; i++) {
solve(i);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
6 ms |
924 KB |
Output is correct |
8 |
Correct |
6 ms |
980 KB |
Output is correct |
9 |
Correct |
5 ms |
980 KB |
Output is correct |
10 |
Correct |
5 ms |
852 KB |
Output is correct |
11 |
Correct |
5 ms |
844 KB |
Output is correct |
12 |
Correct |
5 ms |
852 KB |
Output is correct |
13 |
Correct |
4 ms |
584 KB |
Output is correct |
14 |
Correct |
3 ms |
640 KB |
Output is correct |
15 |
Correct |
3 ms |
640 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
4 ms |
852 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
9300 KB |
Output is correct |
2 |
Correct |
131 ms |
9460 KB |
Output is correct |
3 |
Correct |
129 ms |
9280 KB |
Output is correct |
4 |
Correct |
109 ms |
9064 KB |
Output is correct |
5 |
Correct |
120 ms |
9040 KB |
Output is correct |
6 |
Correct |
93 ms |
9044 KB |
Output is correct |
7 |
Correct |
133 ms |
9308 KB |
Output is correct |
8 |
Correct |
123 ms |
9276 KB |
Output is correct |
9 |
Correct |
126 ms |
9328 KB |
Output is correct |
10 |
Correct |
100 ms |
8860 KB |
Output is correct |
11 |
Correct |
105 ms |
8832 KB |
Output is correct |
12 |
Correct |
98 ms |
8716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
9300 KB |
Output is correct |
2 |
Correct |
131 ms |
9460 KB |
Output is correct |
3 |
Correct |
129 ms |
9280 KB |
Output is correct |
4 |
Correct |
109 ms |
9064 KB |
Output is correct |
5 |
Correct |
120 ms |
9040 KB |
Output is correct |
6 |
Correct |
93 ms |
9044 KB |
Output is correct |
7 |
Correct |
133 ms |
9308 KB |
Output is correct |
8 |
Correct |
123 ms |
9276 KB |
Output is correct |
9 |
Correct |
126 ms |
9328 KB |
Output is correct |
10 |
Correct |
100 ms |
8860 KB |
Output is correct |
11 |
Correct |
105 ms |
8832 KB |
Output is correct |
12 |
Correct |
98 ms |
8716 KB |
Output is correct |
13 |
Correct |
243 ms |
18892 KB |
Output is correct |
14 |
Correct |
252 ms |
18752 KB |
Output is correct |
15 |
Correct |
129 ms |
9392 KB |
Output is correct |
16 |
Correct |
185 ms |
18368 KB |
Output is correct |
17 |
Correct |
205 ms |
18468 KB |
Output is correct |
18 |
Correct |
166 ms |
18416 KB |
Output is correct |
19 |
Correct |
246 ms |
18740 KB |
Output is correct |
20 |
Correct |
245 ms |
18908 KB |
Output is correct |
21 |
Correct |
245 ms |
18848 KB |
Output is correct |
22 |
Correct |
108 ms |
8912 KB |
Output is correct |
23 |
Correct |
110 ms |
8820 KB |
Output is correct |
24 |
Correct |
90 ms |
8664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
6 ms |
924 KB |
Output is correct |
8 |
Correct |
6 ms |
980 KB |
Output is correct |
9 |
Correct |
5 ms |
980 KB |
Output is correct |
10 |
Correct |
5 ms |
852 KB |
Output is correct |
11 |
Correct |
5 ms |
844 KB |
Output is correct |
12 |
Correct |
5 ms |
852 KB |
Output is correct |
13 |
Correct |
4 ms |
584 KB |
Output is correct |
14 |
Correct |
3 ms |
640 KB |
Output is correct |
15 |
Correct |
3 ms |
640 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
4 ms |
852 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
133 ms |
9300 KB |
Output is correct |
20 |
Correct |
131 ms |
9460 KB |
Output is correct |
21 |
Correct |
129 ms |
9280 KB |
Output is correct |
22 |
Correct |
109 ms |
9064 KB |
Output is correct |
23 |
Correct |
120 ms |
9040 KB |
Output is correct |
24 |
Correct |
93 ms |
9044 KB |
Output is correct |
25 |
Correct |
133 ms |
9308 KB |
Output is correct |
26 |
Correct |
123 ms |
9276 KB |
Output is correct |
27 |
Correct |
126 ms |
9328 KB |
Output is correct |
28 |
Correct |
100 ms |
8860 KB |
Output is correct |
29 |
Correct |
105 ms |
8832 KB |
Output is correct |
30 |
Correct |
98 ms |
8716 KB |
Output is correct |
31 |
Correct |
243 ms |
18892 KB |
Output is correct |
32 |
Correct |
252 ms |
18752 KB |
Output is correct |
33 |
Correct |
129 ms |
9392 KB |
Output is correct |
34 |
Correct |
185 ms |
18368 KB |
Output is correct |
35 |
Correct |
205 ms |
18468 KB |
Output is correct |
36 |
Correct |
166 ms |
18416 KB |
Output is correct |
37 |
Correct |
246 ms |
18740 KB |
Output is correct |
38 |
Correct |
245 ms |
18908 KB |
Output is correct |
39 |
Correct |
245 ms |
18848 KB |
Output is correct |
40 |
Correct |
108 ms |
8912 KB |
Output is correct |
41 |
Correct |
110 ms |
8820 KB |
Output is correct |
42 |
Correct |
90 ms |
8664 KB |
Output is correct |
43 |
Correct |
245 ms |
18724 KB |
Output is correct |
44 |
Correct |
262 ms |
18752 KB |
Output is correct |
45 |
Correct |
248 ms |
18856 KB |
Output is correct |
46 |
Correct |
206 ms |
18764 KB |
Output is correct |
47 |
Correct |
215 ms |
18872 KB |
Output is correct |
48 |
Correct |
156 ms |
18112 KB |
Output is correct |
49 |
Correct |
266 ms |
18912 KB |
Output is correct |
50 |
Correct |
260 ms |
18892 KB |
Output is correct |
51 |
Correct |
263 ms |
18864 KB |
Output is correct |
52 |
Correct |
231 ms |
18652 KB |
Output is correct |
53 |
Correct |
109 ms |
9056 KB |
Output is correct |