#include <bits/stdc++.h>
using namespace std;
#define name "aaaaaa"
using ll = long long;
void file(){
ios_base::sync_with_stdio(0); cin.tie(0);
if(fopen(name".inp", "r")) {
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
}
struct node {
int x, y, z, i, val;
};
const int maxn = 1e6 + 5;
struct BIT {
int b[maxn], n;
void build(int _n) {
n = _n;
fill(b, b + n + 1, 0);
}
int lowbit(int x){
return x & (-x);
}
void update(int x, int v){
for(int i = x; i <= n; i += lowbit(i)){
b[i] += v;
}
}
int query(int x) {
int ans = 0;
for(int i = x; i > 0; i -= lowbit(i)){
ans += b[i];
}
return ans;
}
} bit;
vector<node> v;
int n, q, ans[maxn];
void cdq(int l, int r) {
if(l == r) return;
int m = (l + r) / 2;
cdq(l, m); cdq(m + 1, r);
int a = l, b = m + 1, sum = 0;
vector<pair<int, int>> record;
vector<node> tmp;
while(a <= m && b <= r){
if(v[a].y >= v[b].y){
int add = v[a].val;
bit.update(v[a].z, add), sum += add, record.push_back({v[a].z, add}), tmp.push_back(v[a]);
a++;
}else{
ans[v[b].i] += sum - bit.query(v[b].z - 1), tmp.push_back(v[b]);
b++;
}
}
while(a <= m){
tmp.push_back(v[a]);
a++;
}
while(b <= r){
ans[v[b].i] += sum - bit.query(v[b].z - 1), tmp.push_back(v[b]);
b++;
}
for(int i = l; i <= r; i++){
v[i] = tmp[i - l];
}
for(auto i : record) bit.update(i.first, -i.second);
}
bool comp(node a, node b){
if(a.x == b.x){
return a.val > b.val;
}
return (a.x == b.x ? (a.y == b.y ? a.z < b.z : a.y < b.y) : a.x > b.x);
}
map<int, int> mp;
void solve() {
cin >> n >> q;
for(int i = 0; i < n; i++){
int a, b, c;
cin >> a >> b;
c = a + b;
mp[a] = true;
mp[b] = true;
mp[c] = true;
v.push_back({a, b, c, i, 1});
}
for(int i = n; i < n + q; i++){
int x, y, z;
cin >> x >> y >> z;
mp[x] = true;
mp[y] = true;
mp[z] = true;
v.push_back({x, y, z, i, 0});
}
int id = 1;
for(auto i : mp){
mp[i.first] = id;
id++;
}
for(int i = 0; i < v.size(); i++){
v[i].x = mp[v[i].x];
v[i].y = mp[v[i].y];
v[i].z = mp[v[i].z];
}
bit.build(id);
sort(v.begin(), v.end(), comp);
cdq(0, n + q - 1);
for(int i = n; i < n + q; i++) cout << ans[i] << '\n';
}
int main() {
file();
solve();
}
Compilation message
examination.cpp: In function 'void solve()':
examination.cpp:112:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for(int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
examination.cpp: In function 'void file()':
examination.cpp:9:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | freopen(name".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:10:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | freopen(name".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 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 |
12 ms |
1916 KB |
Output is correct |
8 |
Correct |
11 ms |
1860 KB |
Output is correct |
9 |
Correct |
12 ms |
1856 KB |
Output is correct |
10 |
Correct |
9 ms |
1848 KB |
Output is correct |
11 |
Correct |
9 ms |
1592 KB |
Output is correct |
12 |
Correct |
4 ms |
800 KB |
Output is correct |
13 |
Correct |
10 ms |
1592 KB |
Output is correct |
14 |
Correct |
10 ms |
1664 KB |
Output is correct |
15 |
Correct |
10 ms |
1644 KB |
Output is correct |
16 |
Correct |
6 ms |
1116 KB |
Output is correct |
17 |
Correct |
8 ms |
1320 KB |
Output is correct |
18 |
Correct |
3 ms |
796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
426 ms |
23424 KB |
Output is correct |
2 |
Correct |
436 ms |
23596 KB |
Output is correct |
3 |
Correct |
432 ms |
23424 KB |
Output is correct |
4 |
Correct |
312 ms |
20796 KB |
Output is correct |
5 |
Correct |
305 ms |
20688 KB |
Output is correct |
6 |
Correct |
128 ms |
15124 KB |
Output is correct |
7 |
Correct |
427 ms |
23236 KB |
Output is correct |
8 |
Correct |
437 ms |
23284 KB |
Output is correct |
9 |
Correct |
378 ms |
23168 KB |
Output is correct |
10 |
Correct |
275 ms |
20308 KB |
Output is correct |
11 |
Correct |
289 ms |
20624 KB |
Output is correct |
12 |
Correct |
116 ms |
15416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
426 ms |
23424 KB |
Output is correct |
2 |
Correct |
436 ms |
23596 KB |
Output is correct |
3 |
Correct |
432 ms |
23424 KB |
Output is correct |
4 |
Correct |
312 ms |
20796 KB |
Output is correct |
5 |
Correct |
305 ms |
20688 KB |
Output is correct |
6 |
Correct |
128 ms |
15124 KB |
Output is correct |
7 |
Correct |
427 ms |
23236 KB |
Output is correct |
8 |
Correct |
437 ms |
23284 KB |
Output is correct |
9 |
Correct |
378 ms |
23168 KB |
Output is correct |
10 |
Correct |
275 ms |
20308 KB |
Output is correct |
11 |
Correct |
289 ms |
20624 KB |
Output is correct |
12 |
Correct |
116 ms |
15416 KB |
Output is correct |
13 |
Correct |
485 ms |
25216 KB |
Output is correct |
14 |
Correct |
439 ms |
23940 KB |
Output is correct |
15 |
Correct |
444 ms |
23428 KB |
Output is correct |
16 |
Correct |
340 ms |
21164 KB |
Output is correct |
17 |
Correct |
361 ms |
21268 KB |
Output is correct |
18 |
Correct |
151 ms |
15128 KB |
Output is correct |
19 |
Correct |
505 ms |
25216 KB |
Output is correct |
20 |
Correct |
489 ms |
24444 KB |
Output is correct |
21 |
Correct |
461 ms |
25212 KB |
Output is correct |
22 |
Correct |
290 ms |
20356 KB |
Output is correct |
23 |
Correct |
276 ms |
20536 KB |
Output is correct |
24 |
Correct |
103 ms |
15236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 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 |
12 ms |
1916 KB |
Output is correct |
8 |
Correct |
11 ms |
1860 KB |
Output is correct |
9 |
Correct |
12 ms |
1856 KB |
Output is correct |
10 |
Correct |
9 ms |
1848 KB |
Output is correct |
11 |
Correct |
9 ms |
1592 KB |
Output is correct |
12 |
Correct |
4 ms |
800 KB |
Output is correct |
13 |
Correct |
10 ms |
1592 KB |
Output is correct |
14 |
Correct |
10 ms |
1664 KB |
Output is correct |
15 |
Correct |
10 ms |
1644 KB |
Output is correct |
16 |
Correct |
6 ms |
1116 KB |
Output is correct |
17 |
Correct |
8 ms |
1320 KB |
Output is correct |
18 |
Correct |
3 ms |
796 KB |
Output is correct |
19 |
Correct |
426 ms |
23424 KB |
Output is correct |
20 |
Correct |
436 ms |
23596 KB |
Output is correct |
21 |
Correct |
432 ms |
23424 KB |
Output is correct |
22 |
Correct |
312 ms |
20796 KB |
Output is correct |
23 |
Correct |
305 ms |
20688 KB |
Output is correct |
24 |
Correct |
128 ms |
15124 KB |
Output is correct |
25 |
Correct |
427 ms |
23236 KB |
Output is correct |
26 |
Correct |
437 ms |
23284 KB |
Output is correct |
27 |
Correct |
378 ms |
23168 KB |
Output is correct |
28 |
Correct |
275 ms |
20308 KB |
Output is correct |
29 |
Correct |
289 ms |
20624 KB |
Output is correct |
30 |
Correct |
116 ms |
15416 KB |
Output is correct |
31 |
Correct |
485 ms |
25216 KB |
Output is correct |
32 |
Correct |
439 ms |
23940 KB |
Output is correct |
33 |
Correct |
444 ms |
23428 KB |
Output is correct |
34 |
Correct |
340 ms |
21164 KB |
Output is correct |
35 |
Correct |
361 ms |
21268 KB |
Output is correct |
36 |
Correct |
151 ms |
15128 KB |
Output is correct |
37 |
Correct |
505 ms |
25216 KB |
Output is correct |
38 |
Correct |
489 ms |
24444 KB |
Output is correct |
39 |
Correct |
461 ms |
25212 KB |
Output is correct |
40 |
Correct |
290 ms |
20356 KB |
Output is correct |
41 |
Correct |
276 ms |
20536 KB |
Output is correct |
42 |
Correct |
103 ms |
15236 KB |
Output is correct |
43 |
Correct |
777 ms |
49468 KB |
Output is correct |
44 |
Correct |
765 ms |
49388 KB |
Output is correct |
45 |
Correct |
789 ms |
49540 KB |
Output is correct |
46 |
Correct |
536 ms |
37436 KB |
Output is correct |
47 |
Correct |
509 ms |
37224 KB |
Output is correct |
48 |
Correct |
148 ms |
15132 KB |
Output is correct |
49 |
Correct |
919 ms |
49288 KB |
Output is correct |
50 |
Correct |
971 ms |
49404 KB |
Output is correct |
51 |
Correct |
960 ms |
49136 KB |
Output is correct |
52 |
Correct |
506 ms |
32576 KB |
Output is correct |
53 |
Correct |
378 ms |
26976 KB |
Output is correct |