#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
const ll N = 2e5 + 5;
const ll blocksz = 505;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
ll n, q;
ll cnt[N], ans[N];
map<ll, ll> mp;
struct Info{
ll x, y, z, id;
} a[N];
struct BIT{
ll b[N];
void upd(ll i, ll x){
for (; i <= n + q; i += i & (-i)) b[i] += x;
}
ll get(ll i){
ll ans = 0;
for (; i; i -= i & (-i)) ans += b[i];
return ans;
}
} ft;
vector<ll> record;
vector<Info> tmp;
void CDQ(ll l, ll r){
if (l == r) return;
ll m = l + r >> 1;
CDQ(l, m); CDQ(m + 1, r);
ll i = l, j = m + 1, sum = 0;
while (i <= m && j <= r){
if (a[i].y > a[j].y){
if (a[i].id <= n){
++sum; ft.upd(a[i].z, 1); record.push_back(a[i].z);
}
tmp.push_back(a[i++]);
}else{
ans[a[j].id] += sum - ft.get(a[j].z); tmp.push_back(a[j++]);
}
}
while (i <= m) tmp.push_back(a[i++]);
while (j <= r) ans[a[j].id] += sum - ft.get(a[j].z), tmp.push_back(a[j++]);
for (int i = l; i <= r; ++i) a[i] = tmp[i - l];
for (int i : record) ft.upd(i, -1);
vector<ll> ().swap(record);
vector<Info> ().swap(tmp);
}
void solve(){
cin >> n >> q;
vector<ll> v;
for (int i = 1; i <= n; ++i){
cin >> a[i].x >> a[i].y; a[i].z = a[i].x + a[i].y; a[i].id = i;
v.push_back(a[i].z);
}
for (int i = n + 1; i <= n + q; ++i){
cin >> a[i].x >> a[i].y >> a[i].z; a[i].id = i;
--a[i].x; --a[i].y; --a[i].z;
v.push_back(a[i].z);
}
sort(all(v));
v.erase(unique(all(v)), v.end());
for (int i = 0; i < v.size(); ++i) mp[v[i]] = i + 1;
for (int i = 1; i <= n + q; ++i) a[i].z = mp[a[i].z];
sort(a + 1, a + n + q + 1, [&](Info A, Info B){
return (A.x == B.x ? (A.y == B.y ? A.z < B.z : A.y < B.y) : A.x > B.x);
});
CDQ(1, n + q);
for (int i = n + 1; i <= n + q; ++i) cout << ans[i] << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll run_case = 1; // cin >> run_case;
while (run_case--){
solve();
}
}
Compilation message
examination.cpp: In function 'void CDQ(ll, ll)':
examination.cpp:42:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | ll m = l + r >> 1;
| ~~^~~
examination.cpp: In function 'void solve()':
examination.cpp:82:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for (int i = 0; i < v.size(); ++i) mp[v[i]] = i + 1;
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
1692 KB |
Output is correct |
8 |
Correct |
6 ms |
1564 KB |
Output is correct |
9 |
Correct |
6 ms |
1688 KB |
Output is correct |
10 |
Correct |
6 ms |
1852 KB |
Output is correct |
11 |
Correct |
8 ms |
1688 KB |
Output is correct |
12 |
Correct |
4 ms |
1200 KB |
Output is correct |
13 |
Correct |
5 ms |
1428 KB |
Output is correct |
14 |
Correct |
6 ms |
1464 KB |
Output is correct |
15 |
Correct |
5 ms |
1432 KB |
Output is correct |
16 |
Correct |
4 ms |
1360 KB |
Output is correct |
17 |
Correct |
6 ms |
1688 KB |
Output is correct |
18 |
Correct |
3 ms |
1208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
240 ms |
30864 KB |
Output is correct |
2 |
Correct |
261 ms |
30948 KB |
Output is correct |
3 |
Correct |
267 ms |
30988 KB |
Output is correct |
4 |
Correct |
226 ms |
29660 KB |
Output is correct |
5 |
Correct |
197 ms |
29652 KB |
Output is correct |
6 |
Correct |
129 ms |
24948 KB |
Output is correct |
7 |
Correct |
223 ms |
30984 KB |
Output is correct |
8 |
Correct |
231 ms |
31072 KB |
Output is correct |
9 |
Correct |
215 ms |
30736 KB |
Output is correct |
10 |
Correct |
172 ms |
29696 KB |
Output is correct |
11 |
Correct |
213 ms |
29792 KB |
Output is correct |
12 |
Correct |
114 ms |
24936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
240 ms |
30864 KB |
Output is correct |
2 |
Correct |
261 ms |
30948 KB |
Output is correct |
3 |
Correct |
267 ms |
30988 KB |
Output is correct |
4 |
Correct |
226 ms |
29660 KB |
Output is correct |
5 |
Correct |
197 ms |
29652 KB |
Output is correct |
6 |
Correct |
129 ms |
24948 KB |
Output is correct |
7 |
Correct |
223 ms |
30984 KB |
Output is correct |
8 |
Correct |
231 ms |
31072 KB |
Output is correct |
9 |
Correct |
215 ms |
30736 KB |
Output is correct |
10 |
Correct |
172 ms |
29696 KB |
Output is correct |
11 |
Correct |
213 ms |
29792 KB |
Output is correct |
12 |
Correct |
114 ms |
24936 KB |
Output is correct |
13 |
Correct |
291 ms |
34796 KB |
Output is correct |
14 |
Correct |
276 ms |
34136 KB |
Output is correct |
15 |
Correct |
216 ms |
30940 KB |
Output is correct |
16 |
Correct |
276 ms |
31572 KB |
Output is correct |
17 |
Correct |
220 ms |
31700 KB |
Output is correct |
18 |
Correct |
129 ms |
25092 KB |
Output is correct |
19 |
Correct |
274 ms |
34776 KB |
Output is correct |
20 |
Correct |
290 ms |
34048 KB |
Output is correct |
21 |
Correct |
300 ms |
34844 KB |
Output is correct |
22 |
Correct |
170 ms |
29692 KB |
Output is correct |
23 |
Correct |
189 ms |
29664 KB |
Output is correct |
24 |
Correct |
107 ms |
25348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
1692 KB |
Output is correct |
8 |
Correct |
6 ms |
1564 KB |
Output is correct |
9 |
Correct |
6 ms |
1688 KB |
Output is correct |
10 |
Correct |
6 ms |
1852 KB |
Output is correct |
11 |
Correct |
8 ms |
1688 KB |
Output is correct |
12 |
Correct |
4 ms |
1200 KB |
Output is correct |
13 |
Correct |
5 ms |
1428 KB |
Output is correct |
14 |
Correct |
6 ms |
1464 KB |
Output is correct |
15 |
Correct |
5 ms |
1432 KB |
Output is correct |
16 |
Correct |
4 ms |
1360 KB |
Output is correct |
17 |
Correct |
6 ms |
1688 KB |
Output is correct |
18 |
Correct |
3 ms |
1208 KB |
Output is correct |
19 |
Correct |
240 ms |
30864 KB |
Output is correct |
20 |
Correct |
261 ms |
30948 KB |
Output is correct |
21 |
Correct |
267 ms |
30988 KB |
Output is correct |
22 |
Correct |
226 ms |
29660 KB |
Output is correct |
23 |
Correct |
197 ms |
29652 KB |
Output is correct |
24 |
Correct |
129 ms |
24948 KB |
Output is correct |
25 |
Correct |
223 ms |
30984 KB |
Output is correct |
26 |
Correct |
231 ms |
31072 KB |
Output is correct |
27 |
Correct |
215 ms |
30736 KB |
Output is correct |
28 |
Correct |
172 ms |
29696 KB |
Output is correct |
29 |
Correct |
213 ms |
29792 KB |
Output is correct |
30 |
Correct |
114 ms |
24936 KB |
Output is correct |
31 |
Correct |
291 ms |
34796 KB |
Output is correct |
32 |
Correct |
276 ms |
34136 KB |
Output is correct |
33 |
Correct |
216 ms |
30940 KB |
Output is correct |
34 |
Correct |
276 ms |
31572 KB |
Output is correct |
35 |
Correct |
220 ms |
31700 KB |
Output is correct |
36 |
Correct |
129 ms |
25092 KB |
Output is correct |
37 |
Correct |
274 ms |
34776 KB |
Output is correct |
38 |
Correct |
290 ms |
34048 KB |
Output is correct |
39 |
Correct |
300 ms |
34844 KB |
Output is correct |
40 |
Correct |
170 ms |
29692 KB |
Output is correct |
41 |
Correct |
189 ms |
29664 KB |
Output is correct |
42 |
Correct |
107 ms |
25348 KB |
Output is correct |
43 |
Correct |
329 ms |
42452 KB |
Output is correct |
44 |
Correct |
355 ms |
42724 KB |
Output is correct |
45 |
Correct |
320 ms |
42196 KB |
Output is correct |
46 |
Correct |
335 ms |
41204 KB |
Output is correct |
47 |
Correct |
284 ms |
41220 KB |
Output is correct |
48 |
Correct |
133 ms |
25048 KB |
Output is correct |
49 |
Correct |
318 ms |
40840 KB |
Output is correct |
50 |
Correct |
315 ms |
40920 KB |
Output is correct |
51 |
Correct |
331 ms |
40916 KB |
Output is correct |
52 |
Correct |
266 ms |
40152 KB |
Output is correct |
53 |
Correct |
215 ms |
33156 KB |
Output is correct |