#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 |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
11 ms |
3676 KB |
Output is correct |
8 |
Correct |
13 ms |
3720 KB |
Output is correct |
9 |
Correct |
12 ms |
3648 KB |
Output is correct |
10 |
Correct |
9 ms |
3388 KB |
Output is correct |
11 |
Correct |
10 ms |
3432 KB |
Output is correct |
12 |
Correct |
5 ms |
2844 KB |
Output is correct |
13 |
Correct |
10 ms |
3532 KB |
Output is correct |
14 |
Correct |
10 ms |
3508 KB |
Output is correct |
15 |
Correct |
10 ms |
3648 KB |
Output is correct |
16 |
Correct |
6 ms |
3132 KB |
Output is correct |
17 |
Correct |
8 ms |
3232 KB |
Output is correct |
18 |
Correct |
4 ms |
2844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
449 ms |
27092 KB |
Output is correct |
2 |
Correct |
445 ms |
26764 KB |
Output is correct |
3 |
Correct |
449 ms |
27016 KB |
Output is correct |
4 |
Correct |
326 ms |
25008 KB |
Output is correct |
5 |
Correct |
307 ms |
24964 KB |
Output is correct |
6 |
Correct |
129 ms |
17944 KB |
Output is correct |
7 |
Correct |
432 ms |
26828 KB |
Output is correct |
8 |
Correct |
461 ms |
26920 KB |
Output is correct |
9 |
Correct |
380 ms |
27448 KB |
Output is correct |
10 |
Correct |
274 ms |
22664 KB |
Output is correct |
11 |
Correct |
313 ms |
22996 KB |
Output is correct |
12 |
Correct |
116 ms |
18656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
449 ms |
27092 KB |
Output is correct |
2 |
Correct |
445 ms |
26764 KB |
Output is correct |
3 |
Correct |
449 ms |
27016 KB |
Output is correct |
4 |
Correct |
326 ms |
25008 KB |
Output is correct |
5 |
Correct |
307 ms |
24964 KB |
Output is correct |
6 |
Correct |
129 ms |
17944 KB |
Output is correct |
7 |
Correct |
432 ms |
26828 KB |
Output is correct |
8 |
Correct |
461 ms |
26920 KB |
Output is correct |
9 |
Correct |
380 ms |
27448 KB |
Output is correct |
10 |
Correct |
274 ms |
22664 KB |
Output is correct |
11 |
Correct |
313 ms |
22996 KB |
Output is correct |
12 |
Correct |
116 ms |
18656 KB |
Output is correct |
13 |
Correct |
535 ms |
27744 KB |
Output is correct |
14 |
Correct |
480 ms |
27012 KB |
Output is correct |
15 |
Correct |
485 ms |
26600 KB |
Output is correct |
16 |
Correct |
360 ms |
25664 KB |
Output is correct |
17 |
Correct |
351 ms |
25420 KB |
Output is correct |
18 |
Correct |
158 ms |
18456 KB |
Output is correct |
19 |
Correct |
488 ms |
28036 KB |
Output is correct |
20 |
Correct |
493 ms |
26932 KB |
Output is correct |
21 |
Correct |
465 ms |
27524 KB |
Output is correct |
22 |
Correct |
276 ms |
21888 KB |
Output is correct |
23 |
Correct |
322 ms |
22836 KB |
Output is correct |
24 |
Correct |
102 ms |
18436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
11 ms |
3676 KB |
Output is correct |
8 |
Correct |
13 ms |
3720 KB |
Output is correct |
9 |
Correct |
12 ms |
3648 KB |
Output is correct |
10 |
Correct |
9 ms |
3388 KB |
Output is correct |
11 |
Correct |
10 ms |
3432 KB |
Output is correct |
12 |
Correct |
5 ms |
2844 KB |
Output is correct |
13 |
Correct |
10 ms |
3532 KB |
Output is correct |
14 |
Correct |
10 ms |
3508 KB |
Output is correct |
15 |
Correct |
10 ms |
3648 KB |
Output is correct |
16 |
Correct |
6 ms |
3132 KB |
Output is correct |
17 |
Correct |
8 ms |
3232 KB |
Output is correct |
18 |
Correct |
4 ms |
2844 KB |
Output is correct |
19 |
Correct |
449 ms |
27092 KB |
Output is correct |
20 |
Correct |
445 ms |
26764 KB |
Output is correct |
21 |
Correct |
449 ms |
27016 KB |
Output is correct |
22 |
Correct |
326 ms |
25008 KB |
Output is correct |
23 |
Correct |
307 ms |
24964 KB |
Output is correct |
24 |
Correct |
129 ms |
17944 KB |
Output is correct |
25 |
Correct |
432 ms |
26828 KB |
Output is correct |
26 |
Correct |
461 ms |
26920 KB |
Output is correct |
27 |
Correct |
380 ms |
27448 KB |
Output is correct |
28 |
Correct |
274 ms |
22664 KB |
Output is correct |
29 |
Correct |
313 ms |
22996 KB |
Output is correct |
30 |
Correct |
116 ms |
18656 KB |
Output is correct |
31 |
Correct |
535 ms |
27744 KB |
Output is correct |
32 |
Correct |
480 ms |
27012 KB |
Output is correct |
33 |
Correct |
485 ms |
26600 KB |
Output is correct |
34 |
Correct |
360 ms |
25664 KB |
Output is correct |
35 |
Correct |
351 ms |
25420 KB |
Output is correct |
36 |
Correct |
158 ms |
18456 KB |
Output is correct |
37 |
Correct |
488 ms |
28036 KB |
Output is correct |
38 |
Correct |
493 ms |
26932 KB |
Output is correct |
39 |
Correct |
465 ms |
27524 KB |
Output is correct |
40 |
Correct |
276 ms |
21888 KB |
Output is correct |
41 |
Correct |
322 ms |
22836 KB |
Output is correct |
42 |
Correct |
102 ms |
18436 KB |
Output is correct |
43 |
Correct |
803 ms |
49024 KB |
Output is correct |
44 |
Correct |
806 ms |
48040 KB |
Output is correct |
45 |
Correct |
773 ms |
48820 KB |
Output is correct |
46 |
Correct |
533 ms |
38972 KB |
Output is correct |
47 |
Correct |
560 ms |
39076 KB |
Output is correct |
48 |
Correct |
172 ms |
17940 KB |
Output is correct |
49 |
Correct |
810 ms |
48800 KB |
Output is correct |
50 |
Correct |
867 ms |
48992 KB |
Output is correct |
51 |
Correct |
851 ms |
48796 KB |
Output is correct |
52 |
Correct |
466 ms |
34184 KB |
Output is correct |
53 |
Correct |
377 ms |
30596 KB |
Output is correct |