// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
using db = long double;
template<class T> using pq = priority_queue<T, V<T>, less<T>>;
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 19;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, Q; cin >> N >> Q;
vi A(N), B(N); for(int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
}
vi I(N); iota(begin(I), end(I), 0);
sort(begin(I), end(I), [&](int a, int b) {
return A[a] > A[b];
});
V<V<array<ll, 3>>> QQ(N); vi ans(Q);
auto find = [&](int x) {
int lo = -1, hi = N - 1;
while(lo < hi) {
int mid = (lo + hi + 1) / 2;
if (x <= A[I[mid]]) lo = mid;
else hi = mid - 1;
}
return lo;
};
for(int i = 0; i < Q; i++) {
ll a, b, c; cin >> a >> b >> c;
// cout << a << " " << b << " " << c << endl;
// c-query
int cq = find(a);
if (cq != -1) {
QQ[cq].pb({c, 1, i});
// cout << i << " " << cq << endl;
}
// everything after is a b-query
int bq = min(find(c - b), cq);
if (bq != -1) {
QQ[bq].pb({c, -1, i});
QQ[bq].pb({b, 0, i});
// cout << i << " " << bq << endl;
}
}
// cout << endl;
iset<pl> ct, bt;
for(int i = 0; i < N; i++) {
ct.insert(mp(A[I[i]] + B[I[i]], i));
bt.insert(mp(B[I[i]], i));
// cout << i << endl;
for(auto q : QQ[i]) {
if (q[1] == 0) {
ans[q[2]] += int(sz(bt) - bt.order_of_key(mp(q[0], -MOD)));
// cout << q[2] << " " << q[1] << " " << int(sz(bt) - bt.order_of_key(mp(q[0], -MOD))) << endl;
} else {
ans[q[2]] += q[1] * int(sz(ct) - ct.order_of_key(mp(q[0], -MOD)));
// cout << "> " << sz(ct) << " " << ct.order_of_key(mp(q[0], -MOD)) << endl;
// cout << q[2] << " " << q[1] << " " << q[1] * int(sz(ct) - ct.order_of_key(mp(q[0], -MOD))) << endl;
}
}
// cout << endl;
}
for(int i = 0; i < Q; i++) cout << ans[i] << endl;
exit(0-0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
452 KB |
Output is correct |
7 |
Correct |
7 ms |
1116 KB |
Output is correct |
8 |
Correct |
8 ms |
1256 KB |
Output is correct |
9 |
Correct |
7 ms |
1116 KB |
Output is correct |
10 |
Correct |
8 ms |
1112 KB |
Output is correct |
11 |
Correct |
8 ms |
1112 KB |
Output is correct |
12 |
Correct |
6 ms |
1116 KB |
Output is correct |
13 |
Correct |
7 ms |
1236 KB |
Output is correct |
14 |
Correct |
7 ms |
1416 KB |
Output is correct |
15 |
Correct |
9 ms |
1372 KB |
Output is correct |
16 |
Correct |
6 ms |
916 KB |
Output is correct |
17 |
Correct |
7 ms |
1112 KB |
Output is correct |
18 |
Correct |
6 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
336 ms |
30588 KB |
Output is correct |
2 |
Correct |
320 ms |
30612 KB |
Output is correct |
3 |
Correct |
325 ms |
30784 KB |
Output is correct |
4 |
Correct |
264 ms |
29844 KB |
Output is correct |
5 |
Correct |
254 ms |
26088 KB |
Output is correct |
6 |
Correct |
223 ms |
25408 KB |
Output is correct |
7 |
Correct |
314 ms |
30136 KB |
Output is correct |
8 |
Correct |
315 ms |
30648 KB |
Output is correct |
9 |
Correct |
300 ms |
29948 KB |
Output is correct |
10 |
Correct |
228 ms |
24324 KB |
Output is correct |
11 |
Correct |
285 ms |
29956 KB |
Output is correct |
12 |
Correct |
266 ms |
19864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
336 ms |
30588 KB |
Output is correct |
2 |
Correct |
320 ms |
30612 KB |
Output is correct |
3 |
Correct |
325 ms |
30784 KB |
Output is correct |
4 |
Correct |
264 ms |
29844 KB |
Output is correct |
5 |
Correct |
254 ms |
26088 KB |
Output is correct |
6 |
Correct |
223 ms |
25408 KB |
Output is correct |
7 |
Correct |
314 ms |
30136 KB |
Output is correct |
8 |
Correct |
315 ms |
30648 KB |
Output is correct |
9 |
Correct |
300 ms |
29948 KB |
Output is correct |
10 |
Correct |
228 ms |
24324 KB |
Output is correct |
11 |
Correct |
285 ms |
29956 KB |
Output is correct |
12 |
Correct |
266 ms |
19864 KB |
Output is correct |
13 |
Correct |
344 ms |
28796 KB |
Output is correct |
14 |
Correct |
343 ms |
30524 KB |
Output is correct |
15 |
Correct |
318 ms |
30780 KB |
Output is correct |
16 |
Correct |
299 ms |
29916 KB |
Output is correct |
17 |
Correct |
257 ms |
24148 KB |
Output is correct |
18 |
Correct |
223 ms |
25396 KB |
Output is correct |
19 |
Correct |
332 ms |
28752 KB |
Output is correct |
20 |
Correct |
362 ms |
30040 KB |
Output is correct |
21 |
Correct |
338 ms |
27732 KB |
Output is correct |
22 |
Correct |
226 ms |
23548 KB |
Output is correct |
23 |
Correct |
279 ms |
29876 KB |
Output is correct |
24 |
Correct |
264 ms |
19908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
452 KB |
Output is correct |
7 |
Correct |
7 ms |
1116 KB |
Output is correct |
8 |
Correct |
8 ms |
1256 KB |
Output is correct |
9 |
Correct |
7 ms |
1116 KB |
Output is correct |
10 |
Correct |
8 ms |
1112 KB |
Output is correct |
11 |
Correct |
8 ms |
1112 KB |
Output is correct |
12 |
Correct |
6 ms |
1116 KB |
Output is correct |
13 |
Correct |
7 ms |
1236 KB |
Output is correct |
14 |
Correct |
7 ms |
1416 KB |
Output is correct |
15 |
Correct |
9 ms |
1372 KB |
Output is correct |
16 |
Correct |
6 ms |
916 KB |
Output is correct |
17 |
Correct |
7 ms |
1112 KB |
Output is correct |
18 |
Correct |
6 ms |
860 KB |
Output is correct |
19 |
Correct |
336 ms |
30588 KB |
Output is correct |
20 |
Correct |
320 ms |
30612 KB |
Output is correct |
21 |
Correct |
325 ms |
30784 KB |
Output is correct |
22 |
Correct |
264 ms |
29844 KB |
Output is correct |
23 |
Correct |
254 ms |
26088 KB |
Output is correct |
24 |
Correct |
223 ms |
25408 KB |
Output is correct |
25 |
Correct |
314 ms |
30136 KB |
Output is correct |
26 |
Correct |
315 ms |
30648 KB |
Output is correct |
27 |
Correct |
300 ms |
29948 KB |
Output is correct |
28 |
Correct |
228 ms |
24324 KB |
Output is correct |
29 |
Correct |
285 ms |
29956 KB |
Output is correct |
30 |
Correct |
266 ms |
19864 KB |
Output is correct |
31 |
Correct |
344 ms |
28796 KB |
Output is correct |
32 |
Correct |
343 ms |
30524 KB |
Output is correct |
33 |
Correct |
318 ms |
30780 KB |
Output is correct |
34 |
Correct |
299 ms |
29916 KB |
Output is correct |
35 |
Correct |
257 ms |
24148 KB |
Output is correct |
36 |
Correct |
223 ms |
25396 KB |
Output is correct |
37 |
Correct |
332 ms |
28752 KB |
Output is correct |
38 |
Correct |
362 ms |
30040 KB |
Output is correct |
39 |
Correct |
338 ms |
27732 KB |
Output is correct |
40 |
Correct |
226 ms |
23548 KB |
Output is correct |
41 |
Correct |
279 ms |
29876 KB |
Output is correct |
42 |
Correct |
264 ms |
19908 KB |
Output is correct |
43 |
Correct |
344 ms |
30548 KB |
Output is correct |
44 |
Correct |
364 ms |
30548 KB |
Output is correct |
45 |
Correct |
341 ms |
32588 KB |
Output is correct |
46 |
Correct |
374 ms |
30760 KB |
Output is correct |
47 |
Correct |
255 ms |
25392 KB |
Output is correct |
48 |
Correct |
239 ms |
22336 KB |
Output is correct |
49 |
Correct |
384 ms |
32084 KB |
Output is correct |
50 |
Correct |
318 ms |
29288 KB |
Output is correct |
51 |
Correct |
379 ms |
31600 KB |
Output is correct |
52 |
Correct |
251 ms |
22876 KB |
Output is correct |
53 |
Correct |
321 ms |
30600 KB |
Output is correct |