#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 1e5 + 7;
vector<int> tree[mxN * 4], x[mxN * 4], y[mxN * 4];
ii a[mxN], b[mxN], sum[mxN];
int n, q;
void Build(int j = 1, int l = 1, int r = n)
{
if (l == r)
{
tree[j].push_back(a[l].se);
x[j].push_back(b[sum[l].se].fi);
y[j].push_back(b[sum[l].se].se);
return;
}
int mid = (l + r) / 2;
Build(j * 2, l, mid);
Build(j * 2 + 1, mid + 1, r);
merge(tree[j * 2].begin(), tree[j * 2].end(), tree[j * 2 + 1].begin(), tree[j * 2 + 1].end(), back_inserter(tree[j]));
merge(x[j * 2].begin(), x[j * 2].end(), x[j * 2 + 1].begin(), x[j * 2 + 1].end(), back_inserter(x[j]));
merge(y[j * 2].begin(), y[j * 2].end(), y[j * 2 + 1].begin(), y[j * 2 + 1].end(), back_inserter(y[j]));
}
int Get1(int u, int v, int j = 1, int l = 1, int r = n)
{
if (a[r].fi < u)
return 0;
if (a[l].fi >= u)
return r - l + 1 - (lower_bound(tree[j].begin(), tree[j].end(), v) - tree[j].begin());
int mid = (l + r) / 2;
return Get1(u, v, j * 2, l, mid) + Get1(u, v, j * 2 + 1, mid + 1, r);
}
int Get2(int total, int u, int v, int j = 1, int l = 1, int r = n)
{
if (sum[r].fi < total)
return 0;
if (sum[l].fi >= total)
return r - l + 1 - (lower_bound(x[j].begin(), x[j].end(), u) - x[j].begin()) - (lower_bound(y[j].begin(), y[j].end(), v) - y[j].begin());
int mid = (l + r) / 2;
return Get2(total, u, v, j * 2, l, mid) + Get2(total, u, v, j * 2 + 1, mid + 1, r);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
cin >> n >> q;
for (int i = 1; i <= n; i++)
{
cin >> a[i].fi >> a[i].se;
b[i] = a[i];
sum[i].fi = a[i].fi + a[i].se;
sum[i].se = i;
}
sort(sum + 1, sum + n + 1);
sort(a + 1, a + n + 1);
Build();
for (int i = 1; i <= q; i++)
{
int u, v, c;
cin >> u >> v >> c;
if (u + v >= c)
cout << Get1(u, v) << '\n';
else
cout << Get2(c, u, v) << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
28508 KB |
Output is correct |
2 |
Correct |
13 ms |
28508 KB |
Output is correct |
3 |
Correct |
14 ms |
28508 KB |
Output is correct |
4 |
Correct |
14 ms |
28508 KB |
Output is correct |
5 |
Correct |
14 ms |
28504 KB |
Output is correct |
6 |
Correct |
15 ms |
28644 KB |
Output is correct |
7 |
Correct |
18 ms |
29932 KB |
Output is correct |
8 |
Correct |
20 ms |
29788 KB |
Output is correct |
9 |
Correct |
18 ms |
29804 KB |
Output is correct |
10 |
Correct |
18 ms |
29916 KB |
Output is correct |
11 |
Correct |
18 ms |
29788 KB |
Output is correct |
12 |
Correct |
16 ms |
29788 KB |
Output is correct |
13 |
Correct |
17 ms |
29788 KB |
Output is correct |
14 |
Correct |
17 ms |
29784 KB |
Output is correct |
15 |
Correct |
18 ms |
29788 KB |
Output is correct |
16 |
Correct |
16 ms |
29788 KB |
Output is correct |
17 |
Correct |
24 ms |
29692 KB |
Output is correct |
18 |
Correct |
20 ms |
29848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
288 ms |
75596 KB |
Output is correct |
2 |
Correct |
287 ms |
75576 KB |
Output is correct |
3 |
Correct |
286 ms |
75484 KB |
Output is correct |
4 |
Correct |
247 ms |
74828 KB |
Output is correct |
5 |
Correct |
208 ms |
74932 KB |
Output is correct |
6 |
Correct |
161 ms |
74056 KB |
Output is correct |
7 |
Correct |
258 ms |
75592 KB |
Output is correct |
8 |
Correct |
256 ms |
75596 KB |
Output is correct |
9 |
Correct |
245 ms |
75372 KB |
Output is correct |
10 |
Correct |
171 ms |
74792 KB |
Output is correct |
11 |
Correct |
200 ms |
74568 KB |
Output is correct |
12 |
Correct |
122 ms |
73804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
288 ms |
75596 KB |
Output is correct |
2 |
Correct |
287 ms |
75576 KB |
Output is correct |
3 |
Correct |
286 ms |
75484 KB |
Output is correct |
4 |
Correct |
247 ms |
74828 KB |
Output is correct |
5 |
Correct |
208 ms |
74932 KB |
Output is correct |
6 |
Correct |
161 ms |
74056 KB |
Output is correct |
7 |
Correct |
258 ms |
75592 KB |
Output is correct |
8 |
Correct |
256 ms |
75596 KB |
Output is correct |
9 |
Correct |
245 ms |
75372 KB |
Output is correct |
10 |
Correct |
171 ms |
74792 KB |
Output is correct |
11 |
Correct |
200 ms |
74568 KB |
Output is correct |
12 |
Correct |
122 ms |
73804 KB |
Output is correct |
13 |
Correct |
276 ms |
76116 KB |
Output is correct |
14 |
Correct |
269 ms |
75860 KB |
Output is correct |
15 |
Correct |
264 ms |
75484 KB |
Output is correct |
16 |
Correct |
296 ms |
75340 KB |
Output is correct |
17 |
Correct |
234 ms |
75340 KB |
Output is correct |
18 |
Correct |
199 ms |
74276 KB |
Output is correct |
19 |
Correct |
295 ms |
76108 KB |
Output is correct |
20 |
Correct |
303 ms |
75888 KB |
Output is correct |
21 |
Correct |
295 ms |
76008 KB |
Output is correct |
22 |
Correct |
162 ms |
74568 KB |
Output is correct |
23 |
Correct |
210 ms |
74796 KB |
Output is correct |
24 |
Correct |
134 ms |
73800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
28508 KB |
Output is correct |
2 |
Correct |
13 ms |
28508 KB |
Output is correct |
3 |
Correct |
14 ms |
28508 KB |
Output is correct |
4 |
Correct |
14 ms |
28508 KB |
Output is correct |
5 |
Correct |
14 ms |
28504 KB |
Output is correct |
6 |
Correct |
15 ms |
28644 KB |
Output is correct |
7 |
Correct |
18 ms |
29932 KB |
Output is correct |
8 |
Correct |
20 ms |
29788 KB |
Output is correct |
9 |
Correct |
18 ms |
29804 KB |
Output is correct |
10 |
Correct |
18 ms |
29916 KB |
Output is correct |
11 |
Correct |
18 ms |
29788 KB |
Output is correct |
12 |
Correct |
16 ms |
29788 KB |
Output is correct |
13 |
Correct |
17 ms |
29788 KB |
Output is correct |
14 |
Correct |
17 ms |
29784 KB |
Output is correct |
15 |
Correct |
18 ms |
29788 KB |
Output is correct |
16 |
Correct |
16 ms |
29788 KB |
Output is correct |
17 |
Correct |
24 ms |
29692 KB |
Output is correct |
18 |
Correct |
20 ms |
29848 KB |
Output is correct |
19 |
Correct |
288 ms |
75596 KB |
Output is correct |
20 |
Correct |
287 ms |
75576 KB |
Output is correct |
21 |
Correct |
286 ms |
75484 KB |
Output is correct |
22 |
Correct |
247 ms |
74828 KB |
Output is correct |
23 |
Correct |
208 ms |
74932 KB |
Output is correct |
24 |
Correct |
161 ms |
74056 KB |
Output is correct |
25 |
Correct |
258 ms |
75592 KB |
Output is correct |
26 |
Correct |
256 ms |
75596 KB |
Output is correct |
27 |
Correct |
245 ms |
75372 KB |
Output is correct |
28 |
Correct |
171 ms |
74792 KB |
Output is correct |
29 |
Correct |
200 ms |
74568 KB |
Output is correct |
30 |
Correct |
122 ms |
73804 KB |
Output is correct |
31 |
Correct |
276 ms |
76116 KB |
Output is correct |
32 |
Correct |
269 ms |
75860 KB |
Output is correct |
33 |
Correct |
264 ms |
75484 KB |
Output is correct |
34 |
Correct |
296 ms |
75340 KB |
Output is correct |
35 |
Correct |
234 ms |
75340 KB |
Output is correct |
36 |
Correct |
199 ms |
74276 KB |
Output is correct |
37 |
Correct |
295 ms |
76108 KB |
Output is correct |
38 |
Correct |
303 ms |
75888 KB |
Output is correct |
39 |
Correct |
295 ms |
76008 KB |
Output is correct |
40 |
Correct |
162 ms |
74568 KB |
Output is correct |
41 |
Correct |
210 ms |
74796 KB |
Output is correct |
42 |
Correct |
134 ms |
73800 KB |
Output is correct |
43 |
Correct |
321 ms |
77900 KB |
Output is correct |
44 |
Correct |
301 ms |
77896 KB |
Output is correct |
45 |
Correct |
307 ms |
77896 KB |
Output is correct |
46 |
Correct |
289 ms |
76364 KB |
Output is correct |
47 |
Correct |
251 ms |
76360 KB |
Output is correct |
48 |
Correct |
165 ms |
74060 KB |
Output is correct |
49 |
Correct |
352 ms |
77836 KB |
Output is correct |
50 |
Correct |
303 ms |
77896 KB |
Output is correct |
51 |
Correct |
320 ms |
77900 KB |
Output is correct |
52 |
Correct |
228 ms |
76256 KB |
Output is correct |
53 |
Correct |
190 ms |
75412 KB |
Output is correct |