// 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 = 1200, arr[maxn], ans[maxn];
pll a[maxn];
pair<pll, pll> b[maxn];
vector<ll> vec[maxn];
inline bool cmp(int i, int j){
return a[i].F + a[i].S < a[j].F + a[j].S;
}
inline void del(int i){
ll x = a[i].S;
i = i / sq;
vec[i].erase(find(all(vec[i]), x));
}
inline 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;
for(; j < n && j % sq; j++){
if(a[j].F >= A && a[j].S >= B && a[j].F + a[j].S >= Z) ans[ind]++;
}
if(j < n) ans[ind] += get(j, B);
}
for(int i = 0; i < q; i++) cout << ans[i] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
3 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
3 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
16 ms |
8796 KB |
Output is correct |
8 |
Correct |
17 ms |
8796 KB |
Output is correct |
9 |
Correct |
17 ms |
8796 KB |
Output is correct |
10 |
Correct |
15 ms |
8796 KB |
Output is correct |
11 |
Correct |
13 ms |
8796 KB |
Output is correct |
12 |
Correct |
10 ms |
8796 KB |
Output is correct |
13 |
Correct |
15 ms |
8796 KB |
Output is correct |
14 |
Correct |
11 ms |
8792 KB |
Output is correct |
15 |
Correct |
11 ms |
8884 KB |
Output is correct |
16 |
Correct |
3 ms |
8796 KB |
Output is correct |
17 |
Correct |
11 ms |
8796 KB |
Output is correct |
18 |
Correct |
3 ms |
8880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
736 ms |
10788 KB |
Output is correct |
2 |
Correct |
672 ms |
10796 KB |
Output is correct |
3 |
Correct |
656 ms |
10832 KB |
Output is correct |
4 |
Correct |
507 ms |
10832 KB |
Output is correct |
5 |
Correct |
431 ms |
10796 KB |
Output is correct |
6 |
Correct |
386 ms |
10832 KB |
Output is correct |
7 |
Correct |
862 ms |
10836 KB |
Output is correct |
8 |
Correct |
539 ms |
10792 KB |
Output is correct |
9 |
Correct |
654 ms |
10804 KB |
Output is correct |
10 |
Correct |
99 ms |
10580 KB |
Output is correct |
11 |
Correct |
413 ms |
10544 KB |
Output is correct |
12 |
Correct |
62 ms |
10324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
736 ms |
10788 KB |
Output is correct |
2 |
Correct |
672 ms |
10796 KB |
Output is correct |
3 |
Correct |
656 ms |
10832 KB |
Output is correct |
4 |
Correct |
507 ms |
10832 KB |
Output is correct |
5 |
Correct |
431 ms |
10796 KB |
Output is correct |
6 |
Correct |
386 ms |
10832 KB |
Output is correct |
7 |
Correct |
862 ms |
10836 KB |
Output is correct |
8 |
Correct |
539 ms |
10792 KB |
Output is correct |
9 |
Correct |
654 ms |
10804 KB |
Output is correct |
10 |
Correct |
99 ms |
10580 KB |
Output is correct |
11 |
Correct |
413 ms |
10544 KB |
Output is correct |
12 |
Correct |
62 ms |
10324 KB |
Output is correct |
13 |
Correct |
604 ms |
10788 KB |
Output is correct |
14 |
Correct |
670 ms |
10796 KB |
Output is correct |
15 |
Correct |
650 ms |
10832 KB |
Output is correct |
16 |
Correct |
483 ms |
10800 KB |
Output is correct |
17 |
Correct |
404 ms |
10840 KB |
Output is correct |
18 |
Correct |
352 ms |
10796 KB |
Output is correct |
19 |
Correct |
598 ms |
10796 KB |
Output is correct |
20 |
Correct |
644 ms |
10836 KB |
Output is correct |
21 |
Correct |
597 ms |
10832 KB |
Output is correct |
22 |
Correct |
107 ms |
10792 KB |
Output is correct |
23 |
Correct |
406 ms |
10532 KB |
Output is correct |
24 |
Correct |
64 ms |
10320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
3 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
3 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
16 ms |
8796 KB |
Output is correct |
8 |
Correct |
17 ms |
8796 KB |
Output is correct |
9 |
Correct |
17 ms |
8796 KB |
Output is correct |
10 |
Correct |
15 ms |
8796 KB |
Output is correct |
11 |
Correct |
13 ms |
8796 KB |
Output is correct |
12 |
Correct |
10 ms |
8796 KB |
Output is correct |
13 |
Correct |
15 ms |
8796 KB |
Output is correct |
14 |
Correct |
11 ms |
8792 KB |
Output is correct |
15 |
Correct |
11 ms |
8884 KB |
Output is correct |
16 |
Correct |
3 ms |
8796 KB |
Output is correct |
17 |
Correct |
11 ms |
8796 KB |
Output is correct |
18 |
Correct |
3 ms |
8880 KB |
Output is correct |
19 |
Correct |
736 ms |
10788 KB |
Output is correct |
20 |
Correct |
672 ms |
10796 KB |
Output is correct |
21 |
Correct |
656 ms |
10832 KB |
Output is correct |
22 |
Correct |
507 ms |
10832 KB |
Output is correct |
23 |
Correct |
431 ms |
10796 KB |
Output is correct |
24 |
Correct |
386 ms |
10832 KB |
Output is correct |
25 |
Correct |
862 ms |
10836 KB |
Output is correct |
26 |
Correct |
539 ms |
10792 KB |
Output is correct |
27 |
Correct |
654 ms |
10804 KB |
Output is correct |
28 |
Correct |
99 ms |
10580 KB |
Output is correct |
29 |
Correct |
413 ms |
10544 KB |
Output is correct |
30 |
Correct |
62 ms |
10324 KB |
Output is correct |
31 |
Correct |
604 ms |
10788 KB |
Output is correct |
32 |
Correct |
670 ms |
10796 KB |
Output is correct |
33 |
Correct |
650 ms |
10832 KB |
Output is correct |
34 |
Correct |
483 ms |
10800 KB |
Output is correct |
35 |
Correct |
404 ms |
10840 KB |
Output is correct |
36 |
Correct |
352 ms |
10796 KB |
Output is correct |
37 |
Correct |
598 ms |
10796 KB |
Output is correct |
38 |
Correct |
644 ms |
10836 KB |
Output is correct |
39 |
Correct |
597 ms |
10832 KB |
Output is correct |
40 |
Correct |
107 ms |
10792 KB |
Output is correct |
41 |
Correct |
406 ms |
10532 KB |
Output is correct |
42 |
Correct |
64 ms |
10320 KB |
Output is correct |
43 |
Correct |
595 ms |
10800 KB |
Output is correct |
44 |
Correct |
596 ms |
10792 KB |
Output is correct |
45 |
Correct |
679 ms |
10792 KB |
Output is correct |
46 |
Correct |
494 ms |
10824 KB |
Output is correct |
47 |
Correct |
400 ms |
10796 KB |
Output is correct |
48 |
Correct |
341 ms |
10580 KB |
Output is correct |
49 |
Correct |
869 ms |
10820 KB |
Output is correct |
50 |
Correct |
491 ms |
10792 KB |
Output is correct |
51 |
Correct |
599 ms |
10796 KB |
Output is correct |
52 |
Correct |
110 ms |
10580 KB |
Output is correct |
53 |
Correct |
418 ms |
10580 KB |
Output is correct |