// 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 int maxn = 1e5 + 5;
const ll inf = 1e9 + 7;
int n, q, cur, arr[maxn], ans[maxn];
pll a[maxn];
vector<ll> vec[maxn * 2], fen[maxn * 2];
struct B{
ll A, B, Z, ind;
} b[maxn];
bool cmp(int i, int j){
return a[i].F + a[i].S < a[j].F + a[j].S;
}
bool cmp2(B i, B j){
return i.Z < j.Z;
}
void upd(int p, ll x, int d){
for(; p; p /= 2){
int j = lower_bound(all(vec[p]), x) - vec[p].begin();
for(j++; j < fen[p].size(); j += j & -j) fen[p][j] += d;
}
}
int get__(int i, int j){
int res = 0;
for(; j; j &= j - 1) res += fen[i][j];
return res;
}
int get_(int i, ll x){
int j = lower_bound(all(vec[i]), x) - vec[i].begin();
return get__(i, vec[i].size()) - get__(i, j);
}
int get(int l, int r, ll x){
int res = 0;
for(l += n, r += n; l < r; l /= 2, r /= 2){
if(l & 1) res += get_(l++, x);
if(r & 1) res += get_(--r, x);
}
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 >> a[i].S;
arr[i] = i;
}
sort(a, a + n);
sort(arr, arr + n, cmp);
for(int i = 0; i < n; i++){
vec[i + n].pb(a[i].S);
fen[i + n].resize(2);
}
for(int i = n - 1; i; i--){
vec[i].resize(vec[i * 2].size() + vec[i * 2 + 1].size());
merge(all(vec[i * 2]), all(vec[i * 2 + 1]), vec[i].begin());
vec[i].resize(unique(all(vec[i])) - vec[i].begin());
fen[i].resize(vec[i].size() + 1);
}
for(int i = 0; i < n; i++) upd(i + n, a[i].S, 1);
for(int i = 0; i < q; i++){
cin >> b[i].A >> b[i].B >> b[i].Z;
b[i].ind = i;
}
sort(b, b + q, cmp2);
for(int i = 0; i < q; i++){
while(cur < n && a[arr[cur]].F + a[arr[cur]].S < b[i].Z){
upd(arr[cur] + n, a[arr[cur]].S, -1);
cur++;
}
int j = lower_bound(a, a + n, mp(b[i].A, 0ll)) - a;
ans[b[i].ind] += get(j, n, b[i].B);
}
for(int i = 0; i < q; i++) cout << ans[i] << '\n';
return 0;
}
Compilation message
examination.cpp: In function 'void upd(int, ll, int)':
examination.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(j++; j < fen[p].size(); j += j & -j) fen[p][j] += d;
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12636 KB |
Output is correct |
2 |
Correct |
4 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
4 ms |
12636 KB |
Output is correct |
5 |
Correct |
4 ms |
12636 KB |
Output is correct |
6 |
Correct |
4 ms |
12636 KB |
Output is correct |
7 |
Correct |
11 ms |
13660 KB |
Output is correct |
8 |
Correct |
11 ms |
13656 KB |
Output is correct |
9 |
Correct |
11 ms |
13660 KB |
Output is correct |
10 |
Correct |
8 ms |
13404 KB |
Output is correct |
11 |
Correct |
13 ms |
13660 KB |
Output is correct |
12 |
Correct |
7 ms |
13256 KB |
Output is correct |
13 |
Correct |
11 ms |
13912 KB |
Output is correct |
14 |
Correct |
9 ms |
13660 KB |
Output is correct |
15 |
Correct |
9 ms |
13660 KB |
Output is correct |
16 |
Correct |
9 ms |
13708 KB |
Output is correct |
17 |
Correct |
8 ms |
13148 KB |
Output is correct |
18 |
Correct |
6 ms |
13148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
484 ms |
50288 KB |
Output is correct |
2 |
Correct |
453 ms |
50256 KB |
Output is correct |
3 |
Correct |
466 ms |
50324 KB |
Output is correct |
4 |
Correct |
209 ms |
31820 KB |
Output is correct |
5 |
Correct |
249 ms |
49492 KB |
Output is correct |
6 |
Correct |
88 ms |
28248 KB |
Output is correct |
7 |
Correct |
390 ms |
50168 KB |
Output is correct |
8 |
Correct |
390 ms |
50324 KB |
Output is correct |
9 |
Correct |
347 ms |
50260 KB |
Output is correct |
10 |
Correct |
185 ms |
42576 KB |
Output is correct |
11 |
Correct |
129 ms |
27984 KB |
Output is correct |
12 |
Correct |
67 ms |
27980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
484 ms |
50288 KB |
Output is correct |
2 |
Correct |
453 ms |
50256 KB |
Output is correct |
3 |
Correct |
466 ms |
50324 KB |
Output is correct |
4 |
Correct |
209 ms |
31820 KB |
Output is correct |
5 |
Correct |
249 ms |
49492 KB |
Output is correct |
6 |
Correct |
88 ms |
28248 KB |
Output is correct |
7 |
Correct |
390 ms |
50168 KB |
Output is correct |
8 |
Correct |
390 ms |
50324 KB |
Output is correct |
9 |
Correct |
347 ms |
50260 KB |
Output is correct |
10 |
Correct |
185 ms |
42576 KB |
Output is correct |
11 |
Correct |
129 ms |
27984 KB |
Output is correct |
12 |
Correct |
67 ms |
27980 KB |
Output is correct |
13 |
Correct |
782 ms |
50332 KB |
Output is correct |
14 |
Correct |
636 ms |
50312 KB |
Output is correct |
15 |
Correct |
515 ms |
50412 KB |
Output is correct |
16 |
Correct |
241 ms |
31992 KB |
Output is correct |
17 |
Correct |
447 ms |
49636 KB |
Output is correct |
18 |
Correct |
117 ms |
28356 KB |
Output is correct |
19 |
Correct |
861 ms |
50332 KB |
Output is correct |
20 |
Correct |
879 ms |
50296 KB |
Output is correct |
21 |
Correct |
780 ms |
50392 KB |
Output is correct |
22 |
Correct |
202 ms |
42620 KB |
Output is correct |
23 |
Correct |
147 ms |
28088 KB |
Output is correct |
24 |
Correct |
67 ms |
27984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12636 KB |
Output is correct |
2 |
Correct |
4 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
4 ms |
12636 KB |
Output is correct |
5 |
Correct |
4 ms |
12636 KB |
Output is correct |
6 |
Correct |
4 ms |
12636 KB |
Output is correct |
7 |
Correct |
11 ms |
13660 KB |
Output is correct |
8 |
Correct |
11 ms |
13656 KB |
Output is correct |
9 |
Correct |
11 ms |
13660 KB |
Output is correct |
10 |
Correct |
8 ms |
13404 KB |
Output is correct |
11 |
Correct |
13 ms |
13660 KB |
Output is correct |
12 |
Correct |
7 ms |
13256 KB |
Output is correct |
13 |
Correct |
11 ms |
13912 KB |
Output is correct |
14 |
Correct |
9 ms |
13660 KB |
Output is correct |
15 |
Correct |
9 ms |
13660 KB |
Output is correct |
16 |
Correct |
9 ms |
13708 KB |
Output is correct |
17 |
Correct |
8 ms |
13148 KB |
Output is correct |
18 |
Correct |
6 ms |
13148 KB |
Output is correct |
19 |
Correct |
484 ms |
50288 KB |
Output is correct |
20 |
Correct |
453 ms |
50256 KB |
Output is correct |
21 |
Correct |
466 ms |
50324 KB |
Output is correct |
22 |
Correct |
209 ms |
31820 KB |
Output is correct |
23 |
Correct |
249 ms |
49492 KB |
Output is correct |
24 |
Correct |
88 ms |
28248 KB |
Output is correct |
25 |
Correct |
390 ms |
50168 KB |
Output is correct |
26 |
Correct |
390 ms |
50324 KB |
Output is correct |
27 |
Correct |
347 ms |
50260 KB |
Output is correct |
28 |
Correct |
185 ms |
42576 KB |
Output is correct |
29 |
Correct |
129 ms |
27984 KB |
Output is correct |
30 |
Correct |
67 ms |
27980 KB |
Output is correct |
31 |
Correct |
782 ms |
50332 KB |
Output is correct |
32 |
Correct |
636 ms |
50312 KB |
Output is correct |
33 |
Correct |
515 ms |
50412 KB |
Output is correct |
34 |
Correct |
241 ms |
31992 KB |
Output is correct |
35 |
Correct |
447 ms |
49636 KB |
Output is correct |
36 |
Correct |
117 ms |
28356 KB |
Output is correct |
37 |
Correct |
861 ms |
50332 KB |
Output is correct |
38 |
Correct |
879 ms |
50296 KB |
Output is correct |
39 |
Correct |
780 ms |
50392 KB |
Output is correct |
40 |
Correct |
202 ms |
42620 KB |
Output is correct |
41 |
Correct |
147 ms |
28088 KB |
Output is correct |
42 |
Correct |
67 ms |
27984 KB |
Output is correct |
43 |
Correct |
846 ms |
51540 KB |
Output is correct |
44 |
Correct |
903 ms |
51436 KB |
Output is correct |
45 |
Correct |
630 ms |
51540 KB |
Output is correct |
46 |
Correct |
222 ms |
31996 KB |
Output is correct |
47 |
Correct |
415 ms |
51308 KB |
Output is correct |
48 |
Correct |
107 ms |
28096 KB |
Output is correct |
49 |
Correct |
555 ms |
51276 KB |
Output is correct |
50 |
Correct |
718 ms |
51284 KB |
Output is correct |
51 |
Correct |
485 ms |
51536 KB |
Output is correct |
52 |
Correct |
346 ms |
51224 KB |
Output is correct |
53 |
Correct |
156 ms |
28208 KB |
Output is correct |