#include <iostream>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#define ll long long
using namespace std;
map <ll, ll> mp;
vector <array<ll, 4>> Q;
ll n, q, a, b, c, F[100000];
struct BIT{
vector <ll> val{vector <ll> (200001, 0)};
vector <ll> lazy{vector <ll> (200001, 0)};
void add(ll id, ll cur) {
while (id <= mp.size()) {
if (lazy[id] != cur) {
lazy[id] = cur, val[id] = 0;
}
++val[id];
id += id&-id;
}
}
ll sum(ll id, ll cur) {
ll res = 0;
while (id) {
if (lazy[id] != cur) {
lazy[id] = cur, val[id] = 0;
}
res += val[id];
id -= id&-id;
}
return res;
}
}bit;
void cdq(ll id, ll l, ll r) {
if (l == r) return;
ll mid = (l+r)/2;
cdq(id*2, l, mid);
cdq(id*2+1, mid+1, r);
int i=l, j=mid+1;
vector <array<ll, 4>> tmp;
while (i <= mid && j <= r) {
if (Q[i][1] >= Q[j][1]) {
if (Q[i][3] == -1) bit.add(mp.size()-Q[i][2], id);
tmp.push_back(Q[i++]);
}
else {
if (Q[j][3] != -1) F[Q[j][3]] += bit.sum(mp.size()-Q[j][2], id);
tmp.push_back(Q[j++]);
}
}
while (i <= mid) tmp.push_back(Q[i++]);
while (j <= r) {
if (Q[j][3] != -1) F[Q[j][3]] += bit.sum(mp.size()-Q[j][2], id);
tmp.push_back(Q[j++]);
}
for (int i=l; i<=r; ++i) swap(Q[i], tmp[i-l]);
}
int main() {
cin >> n >> q;
for (int i=0; i<n; ++i) {
cin >> a >> b;
c = a+b;
++mp[c];
Q.push_back({a, b, c, -1});
}
for (int i=0; i<q; ++i) {
cin >> a >> b >> c;
++mp[c];
Q.push_back({a, b, c, i});
}
sort(Q.begin(), Q.end(), [](auto a, auto b) {
return a[0] > b[0] || (a[0] == b[0] && a[3] < b[3]);
});
int i=0;
for (auto &[x, y] : mp) {
y = i++;
}
for (auto &[a, b, c, d] : Q) {
c = mp[c];
}
cdq(1, 0, Q.size()-1);
for (int i=0; i<q; ++i) cout << F[i] << '\n';
}
Compilation message
examination.cpp: In member function 'void BIT::add(long long int, long long int)':
examination.cpp:18:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | while (id <= mp.size()) {
| ~~~^~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:81:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
81 | for (auto &[x, y] : mp) {
| ^
examination.cpp:84:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
84 | for (auto &[a, b, c, d] : Q) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3420 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
11 ms |
4556 KB |
Output is correct |
8 |
Correct |
11 ms |
4568 KB |
Output is correct |
9 |
Correct |
10 ms |
4568 KB |
Output is correct |
10 |
Correct |
9 ms |
4376 KB |
Output is correct |
11 |
Correct |
9 ms |
4568 KB |
Output is correct |
12 |
Correct |
6 ms |
4120 KB |
Output is correct |
13 |
Correct |
9 ms |
4384 KB |
Output is correct |
14 |
Correct |
11 ms |
4380 KB |
Output is correct |
15 |
Correct |
9 ms |
4384 KB |
Output is correct |
16 |
Correct |
9 ms |
4384 KB |
Output is correct |
17 |
Correct |
9 ms |
4568 KB |
Output is correct |
18 |
Correct |
5 ms |
4112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
298 ms |
30064 KB |
Output is correct |
2 |
Correct |
310 ms |
33840 KB |
Output is correct |
3 |
Correct |
287 ms |
33640 KB |
Output is correct |
4 |
Correct |
242 ms |
29496 KB |
Output is correct |
5 |
Correct |
246 ms |
31952 KB |
Output is correct |
6 |
Correct |
142 ms |
25684 KB |
Output is correct |
7 |
Correct |
277 ms |
30664 KB |
Output is correct |
8 |
Correct |
287 ms |
32816 KB |
Output is correct |
9 |
Correct |
279 ms |
30508 KB |
Output is correct |
10 |
Correct |
273 ms |
31428 KB |
Output is correct |
11 |
Correct |
257 ms |
29128 KB |
Output is correct |
12 |
Correct |
135 ms |
27740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
298 ms |
30064 KB |
Output is correct |
2 |
Correct |
310 ms |
33840 KB |
Output is correct |
3 |
Correct |
287 ms |
33640 KB |
Output is correct |
4 |
Correct |
242 ms |
29496 KB |
Output is correct |
5 |
Correct |
246 ms |
31952 KB |
Output is correct |
6 |
Correct |
142 ms |
25684 KB |
Output is correct |
7 |
Correct |
277 ms |
30664 KB |
Output is correct |
8 |
Correct |
287 ms |
32816 KB |
Output is correct |
9 |
Correct |
279 ms |
30508 KB |
Output is correct |
10 |
Correct |
273 ms |
31428 KB |
Output is correct |
11 |
Correct |
257 ms |
29128 KB |
Output is correct |
12 |
Correct |
135 ms |
27740 KB |
Output is correct |
13 |
Correct |
403 ms |
37364 KB |
Output is correct |
14 |
Correct |
388 ms |
33452 KB |
Output is correct |
15 |
Correct |
291 ms |
31520 KB |
Output is correct |
16 |
Correct |
330 ms |
33340 KB |
Output is correct |
17 |
Correct |
330 ms |
31036 KB |
Output is correct |
18 |
Correct |
152 ms |
24580 KB |
Output is correct |
19 |
Correct |
362 ms |
33704 KB |
Output is correct |
20 |
Correct |
388 ms |
35000 KB |
Output is correct |
21 |
Correct |
397 ms |
36920 KB |
Output is correct |
22 |
Correct |
247 ms |
30044 KB |
Output is correct |
23 |
Correct |
229 ms |
30164 KB |
Output is correct |
24 |
Correct |
123 ms |
26868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3420 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
11 ms |
4556 KB |
Output is correct |
8 |
Correct |
11 ms |
4568 KB |
Output is correct |
9 |
Correct |
10 ms |
4568 KB |
Output is correct |
10 |
Correct |
9 ms |
4376 KB |
Output is correct |
11 |
Correct |
9 ms |
4568 KB |
Output is correct |
12 |
Correct |
6 ms |
4120 KB |
Output is correct |
13 |
Correct |
9 ms |
4384 KB |
Output is correct |
14 |
Correct |
11 ms |
4380 KB |
Output is correct |
15 |
Correct |
9 ms |
4384 KB |
Output is correct |
16 |
Correct |
9 ms |
4384 KB |
Output is correct |
17 |
Correct |
9 ms |
4568 KB |
Output is correct |
18 |
Correct |
5 ms |
4112 KB |
Output is correct |
19 |
Correct |
298 ms |
30064 KB |
Output is correct |
20 |
Correct |
310 ms |
33840 KB |
Output is correct |
21 |
Correct |
287 ms |
33640 KB |
Output is correct |
22 |
Correct |
242 ms |
29496 KB |
Output is correct |
23 |
Correct |
246 ms |
31952 KB |
Output is correct |
24 |
Correct |
142 ms |
25684 KB |
Output is correct |
25 |
Correct |
277 ms |
30664 KB |
Output is correct |
26 |
Correct |
287 ms |
32816 KB |
Output is correct |
27 |
Correct |
279 ms |
30508 KB |
Output is correct |
28 |
Correct |
273 ms |
31428 KB |
Output is correct |
29 |
Correct |
257 ms |
29128 KB |
Output is correct |
30 |
Correct |
135 ms |
27740 KB |
Output is correct |
31 |
Correct |
403 ms |
37364 KB |
Output is correct |
32 |
Correct |
388 ms |
33452 KB |
Output is correct |
33 |
Correct |
291 ms |
31520 KB |
Output is correct |
34 |
Correct |
330 ms |
33340 KB |
Output is correct |
35 |
Correct |
330 ms |
31036 KB |
Output is correct |
36 |
Correct |
152 ms |
24580 KB |
Output is correct |
37 |
Correct |
362 ms |
33704 KB |
Output is correct |
38 |
Correct |
388 ms |
35000 KB |
Output is correct |
39 |
Correct |
397 ms |
36920 KB |
Output is correct |
40 |
Correct |
247 ms |
30044 KB |
Output is correct |
41 |
Correct |
229 ms |
30164 KB |
Output is correct |
42 |
Correct |
123 ms |
26868 KB |
Output is correct |
43 |
Correct |
457 ms |
42552 KB |
Output is correct |
44 |
Correct |
485 ms |
41220 KB |
Output is correct |
45 |
Correct |
470 ms |
43556 KB |
Output is correct |
46 |
Correct |
443 ms |
41916 KB |
Output is correct |
47 |
Correct |
428 ms |
39060 KB |
Output is correct |
48 |
Correct |
160 ms |
27448 KB |
Output is correct |
49 |
Correct |
498 ms |
41396 KB |
Output is correct |
50 |
Correct |
499 ms |
42292 KB |
Output is correct |
51 |
Correct |
518 ms |
41740 KB |
Output is correct |
52 |
Correct |
444 ms |
39988 KB |
Output is correct |
53 |
Correct |
252 ms |
32824 KB |
Output is correct |