// In the name of God
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define len(x) ((ll)(x).size())
const ll maxn = 1e5 + 5;
const ll inf = 1e9 + 7;
ll n, q, cur, sq = 1000, arr[maxn], ans[maxn];
pll a[maxn];
pair<pll, pll> b[maxn];
vector<ll> vec[maxn];
bool cmp(int i, int j){
return a[i].F + a[i].S < a[j].F + a[j].S;
}
void del(int i){
ll x = a[i].S;
i = i / sq;
vec[i].erase(find(all(vec[i]), x));
}
ll get(ll i, ll x){
ll res = 0;
for(; i < n; i += sq){
int d = lower_bound(all(vec[i / sq]), x) - vec[i / sq].begin();
res += vec[i / sq].size() - d;
}
return res;
}
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
for(int i = 0; i < n; i++){
cin >> a[i].F;
cin >> a[i].S;
}
sort(a, a + n);
for(int i = 0; i < n; i++){
vec[i / sq].pb(a[i].S);
}
for(int i = 0; i < sq; i++) sort(all(vec[i]));
for(int i = 0; i < q; i++){
cin >> b[i].S.F >> b[i].S.S >> b[i].F.F;
b[i].F.S = i;
}
sort(b, b + q);
for(int i = 0; i < n; i++) arr[i] = i;
sort(arr, arr + n, cmp);
for(int i = 0; i < q; i++){
ll Z = b[i].F.F, ind = b[i].F.S, A = b[i].S.F, B = b[i].S.S;
while(cur < n && a[arr[cur]].F + a[arr[cur]].S < Z) del(arr[cur++]);
int j = lower_bound(a, a + n, mp(A, 0ll)) - a;
j = (j / sq) * sq;
for(int k = j; ((1ll * k) < n) && ((1ll * k / sq) == (1ll * j / sq)); k++){
if(a[k].F >= A && a[k].S >= B && a[k].F + a[k].S >= Z) ans[ind]++;
}
j += sq;
if(j < n) ans[ind] += get(j, B);
}
for(int i = 0; i < q; i++) cout << ans[i] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8628 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
18 ms |
8792 KB |
Output is correct |
8 |
Correct |
18 ms |
8792 KB |
Output is correct |
9 |
Correct |
19 ms |
8872 KB |
Output is correct |
10 |
Correct |
17 ms |
8796 KB |
Output is correct |
11 |
Correct |
17 ms |
8796 KB |
Output is correct |
12 |
Correct |
16 ms |
8796 KB |
Output is correct |
13 |
Correct |
17 ms |
8872 KB |
Output is correct |
14 |
Correct |
18 ms |
8796 KB |
Output is correct |
15 |
Correct |
18 ms |
8792 KB |
Output is correct |
16 |
Correct |
10 ms |
8796 KB |
Output is correct |
17 |
Correct |
17 ms |
8796 KB |
Output is correct |
18 |
Correct |
6 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
921 ms |
10384 KB |
Output is correct |
2 |
Correct |
924 ms |
10368 KB |
Output is correct |
3 |
Correct |
910 ms |
10368 KB |
Output is correct |
4 |
Correct |
759 ms |
10368 KB |
Output is correct |
5 |
Correct |
688 ms |
10320 KB |
Output is correct |
6 |
Correct |
621 ms |
10368 KB |
Output is correct |
7 |
Correct |
1132 ms |
10368 KB |
Output is correct |
8 |
Correct |
779 ms |
10380 KB |
Output is correct |
9 |
Correct |
894 ms |
10368 KB |
Output is correct |
10 |
Correct |
332 ms |
10116 KB |
Output is correct |
11 |
Correct |
630 ms |
10128 KB |
Output is correct |
12 |
Correct |
171 ms |
10068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
921 ms |
10384 KB |
Output is correct |
2 |
Correct |
924 ms |
10368 KB |
Output is correct |
3 |
Correct |
910 ms |
10368 KB |
Output is correct |
4 |
Correct |
759 ms |
10368 KB |
Output is correct |
5 |
Correct |
688 ms |
10320 KB |
Output is correct |
6 |
Correct |
621 ms |
10368 KB |
Output is correct |
7 |
Correct |
1132 ms |
10368 KB |
Output is correct |
8 |
Correct |
779 ms |
10380 KB |
Output is correct |
9 |
Correct |
894 ms |
10368 KB |
Output is correct |
10 |
Correct |
332 ms |
10116 KB |
Output is correct |
11 |
Correct |
630 ms |
10128 KB |
Output is correct |
12 |
Correct |
171 ms |
10068 KB |
Output is correct |
13 |
Correct |
833 ms |
10372 KB |
Output is correct |
14 |
Correct |
925 ms |
10580 KB |
Output is correct |
15 |
Correct |
920 ms |
10320 KB |
Output is correct |
16 |
Correct |
708 ms |
10376 KB |
Output is correct |
17 |
Correct |
658 ms |
10368 KB |
Output is correct |
18 |
Correct |
629 ms |
10324 KB |
Output is correct |
19 |
Correct |
833 ms |
10364 KB |
Output is correct |
20 |
Correct |
883 ms |
10372 KB |
Output is correct |
21 |
Correct |
835 ms |
10372 KB |
Output is correct |
22 |
Correct |
320 ms |
10116 KB |
Output is correct |
23 |
Correct |
637 ms |
10120 KB |
Output is correct |
24 |
Correct |
173 ms |
10068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8628 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
18 ms |
8792 KB |
Output is correct |
8 |
Correct |
18 ms |
8792 KB |
Output is correct |
9 |
Correct |
19 ms |
8872 KB |
Output is correct |
10 |
Correct |
17 ms |
8796 KB |
Output is correct |
11 |
Correct |
17 ms |
8796 KB |
Output is correct |
12 |
Correct |
16 ms |
8796 KB |
Output is correct |
13 |
Correct |
17 ms |
8872 KB |
Output is correct |
14 |
Correct |
18 ms |
8796 KB |
Output is correct |
15 |
Correct |
18 ms |
8792 KB |
Output is correct |
16 |
Correct |
10 ms |
8796 KB |
Output is correct |
17 |
Correct |
17 ms |
8796 KB |
Output is correct |
18 |
Correct |
6 ms |
8796 KB |
Output is correct |
19 |
Correct |
921 ms |
10384 KB |
Output is correct |
20 |
Correct |
924 ms |
10368 KB |
Output is correct |
21 |
Correct |
910 ms |
10368 KB |
Output is correct |
22 |
Correct |
759 ms |
10368 KB |
Output is correct |
23 |
Correct |
688 ms |
10320 KB |
Output is correct |
24 |
Correct |
621 ms |
10368 KB |
Output is correct |
25 |
Correct |
1132 ms |
10368 KB |
Output is correct |
26 |
Correct |
779 ms |
10380 KB |
Output is correct |
27 |
Correct |
894 ms |
10368 KB |
Output is correct |
28 |
Correct |
332 ms |
10116 KB |
Output is correct |
29 |
Correct |
630 ms |
10128 KB |
Output is correct |
30 |
Correct |
171 ms |
10068 KB |
Output is correct |
31 |
Correct |
833 ms |
10372 KB |
Output is correct |
32 |
Correct |
925 ms |
10580 KB |
Output is correct |
33 |
Correct |
920 ms |
10320 KB |
Output is correct |
34 |
Correct |
708 ms |
10376 KB |
Output is correct |
35 |
Correct |
658 ms |
10368 KB |
Output is correct |
36 |
Correct |
629 ms |
10324 KB |
Output is correct |
37 |
Correct |
833 ms |
10364 KB |
Output is correct |
38 |
Correct |
883 ms |
10372 KB |
Output is correct |
39 |
Correct |
835 ms |
10372 KB |
Output is correct |
40 |
Correct |
320 ms |
10116 KB |
Output is correct |
41 |
Correct |
637 ms |
10120 KB |
Output is correct |
42 |
Correct |
173 ms |
10068 KB |
Output is correct |
43 |
Correct |
836 ms |
10368 KB |
Output is correct |
44 |
Correct |
826 ms |
10364 KB |
Output is correct |
45 |
Correct |
945 ms |
10368 KB |
Output is correct |
46 |
Correct |
712 ms |
10368 KB |
Output is correct |
47 |
Correct |
665 ms |
10380 KB |
Output is correct |
48 |
Correct |
598 ms |
10108 KB |
Output is correct |
49 |
Correct |
1134 ms |
10372 KB |
Output is correct |
50 |
Correct |
716 ms |
10320 KB |
Output is correct |
51 |
Correct |
807 ms |
10352 KB |
Output is correct |
52 |
Correct |
334 ms |
10108 KB |
Output is correct |
53 |
Correct |
633 ms |
10116 KB |
Output is correct |