#include <bits/stdc++.h>
#define eb emplace_back
#define iter(a) a.begin(), a.end()
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
using namespace std;
typedef long long ll;
vector<int> BIT;
int lowbit(int x){
return x & -x;
}
void modify(int x, int v){
for(; x < BIT.size(); x += lowbit(x)){
BIT[x] += v;
}
}
int query(int x){
int ans = 0;
for(; x > 0; x -= lowbit(x)){
ans += BIT[x];
}
return ans;
}
vector<int> tv;
struct OAO{
int x = 0, y = 0, z = 0, type = -1;
OAO(int x = 0, int y = 0, int z = 0, int type = -1):
x(x), y(y), z(z), type(type) {}
void upd(){
x = lower_bound(iter(tv), x, greater<>()) - tv.begin() + 1;
y = lower_bound(iter(tv), y, greater<>()) - tv.begin() + 1;
z = lower_bound(iter(tv), z, greater<>()) - tv.begin() + 1;
}
};
bool comp(OAO a, OAO b){
if(a.x == b.x) return a.type < b.type;
return a.x < b.x;
}
ostream& operator<<(ostream& o, OAO oao){
return o << '(' << oao.x << ',' << oao.y << ',' << oao.z << ',' << oao.type << ')';
}
vector<int> ans;
void cdq(vector<OAO>& a, int l, int r){
if(l >= r) return;
int m = (l + r) / 2;
cdq(a, l, m);
cdq(a, m + 1, r);
//cerr << "test " << l << " " << r << "\n";
//printv(a, cerr);
//for(int i = 1; i < BIT.size(); i++) cerr << query(i) << " ";
//cerr << "\n";
vector<OAO> b;
int lp = l, rp = m + 1;
while(lp <= m && rp <= r){
if(a[lp].y <= a[rp].y){
if(a[lp].type == -1){
modify(a[lp].z, 1);
}
b.eb(a[lp]);
lp++;
}
else{
if(a[rp].type != -1){
ans[a[rp].type] += query(a[rp].z);
}
b.eb(a[rp]);
rp++;
}
}
while(lp <= m){
if(a[lp].type == -1){
modify(a[lp].z, 1);
}
b.eb(a[lp]);
lp++;
}
while(rp <= r){
if(a[rp].type != -1){
ans[a[rp].type] += query(a[rp].z);
}
b.eb(a[rp]);
rp++;
}
for(int i = l; i <= m; i++){
if(a[i].type == -1) modify(a[i].z, -1);
}
for(int i = l; i <= r; i++) a[i] = b[i - l];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
ans.resize(q);
vector<OAO> a;
for(int i = 0; i < n; i++){
int s, t;
cin >> s >> t;
a.eb(OAO(s, t, s + t, -1));
tv.eb(s);
tv.eb(t);
tv.eb(s + t);
}
for(int i = 0; i < q; i++){
int x, y, z;
cin >> x >> y >> z;
a.eb(OAO(x, y, z, i));
tv.eb(x);
tv.eb(y);
tv.eb(z);
}
sort(iter(tv), greater<>());
tv.resize(unique(iter(tv)) - tv.begin());
BIT.resize(tv.size() + 1);
for(auto& i : a){
i.upd();
}
sort(iter(a), comp);
//printv(tv, cerr);
cdq(a, 0, (int)a.size() - 1);
for(int i = 0; i < q; i++) cout << ans[i] << "\n";
return 0;
}
Compilation message
examination.cpp: In function 'void modify(int, int)':
examination.cpp:21:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(; x < BIT.size(); x += lowbit(x)){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
10 ms |
848 KB |
Output is correct |
8 |
Correct |
10 ms |
876 KB |
Output is correct |
9 |
Correct |
10 ms |
876 KB |
Output is correct |
10 |
Correct |
9 ms |
876 KB |
Output is correct |
11 |
Correct |
9 ms |
876 KB |
Output is correct |
12 |
Correct |
6 ms |
748 KB |
Output is correct |
13 |
Correct |
9 ms |
876 KB |
Output is correct |
14 |
Correct |
9 ms |
876 KB |
Output is correct |
15 |
Correct |
9 ms |
876 KB |
Output is correct |
16 |
Correct |
7 ms |
876 KB |
Output is correct |
17 |
Correct |
8 ms |
876 KB |
Output is correct |
18 |
Correct |
4 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
366 ms |
12940 KB |
Output is correct |
2 |
Correct |
368 ms |
13032 KB |
Output is correct |
3 |
Correct |
365 ms |
12924 KB |
Output is correct |
4 |
Correct |
309 ms |
12824 KB |
Output is correct |
5 |
Correct |
294 ms |
12804 KB |
Output is correct |
6 |
Correct |
182 ms |
12424 KB |
Output is correct |
7 |
Correct |
340 ms |
12880 KB |
Output is correct |
8 |
Correct |
345 ms |
13080 KB |
Output is correct |
9 |
Correct |
330 ms |
13060 KB |
Output is correct |
10 |
Correct |
275 ms |
12932 KB |
Output is correct |
11 |
Correct |
282 ms |
12956 KB |
Output is correct |
12 |
Correct |
150 ms |
12580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
366 ms |
12940 KB |
Output is correct |
2 |
Correct |
368 ms |
13032 KB |
Output is correct |
3 |
Correct |
365 ms |
12924 KB |
Output is correct |
4 |
Correct |
309 ms |
12824 KB |
Output is correct |
5 |
Correct |
294 ms |
12804 KB |
Output is correct |
6 |
Correct |
182 ms |
12424 KB |
Output is correct |
7 |
Correct |
340 ms |
12880 KB |
Output is correct |
8 |
Correct |
345 ms |
13080 KB |
Output is correct |
9 |
Correct |
330 ms |
13060 KB |
Output is correct |
10 |
Correct |
275 ms |
12932 KB |
Output is correct |
11 |
Correct |
282 ms |
12956 KB |
Output is correct |
12 |
Correct |
150 ms |
12580 KB |
Output is correct |
13 |
Correct |
402 ms |
13180 KB |
Output is correct |
14 |
Correct |
402 ms |
12924 KB |
Output is correct |
15 |
Correct |
368 ms |
12964 KB |
Output is correct |
16 |
Correct |
338 ms |
12804 KB |
Output is correct |
17 |
Correct |
330 ms |
12804 KB |
Output is correct |
18 |
Correct |
198 ms |
12424 KB |
Output is correct |
19 |
Correct |
398 ms |
13220 KB |
Output is correct |
20 |
Correct |
401 ms |
13160 KB |
Output is correct |
21 |
Correct |
382 ms |
13060 KB |
Output is correct |
22 |
Correct |
274 ms |
12676 KB |
Output is correct |
23 |
Correct |
281 ms |
12836 KB |
Output is correct |
24 |
Correct |
148 ms |
12424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
10 ms |
848 KB |
Output is correct |
8 |
Correct |
10 ms |
876 KB |
Output is correct |
9 |
Correct |
10 ms |
876 KB |
Output is correct |
10 |
Correct |
9 ms |
876 KB |
Output is correct |
11 |
Correct |
9 ms |
876 KB |
Output is correct |
12 |
Correct |
6 ms |
748 KB |
Output is correct |
13 |
Correct |
9 ms |
876 KB |
Output is correct |
14 |
Correct |
9 ms |
876 KB |
Output is correct |
15 |
Correct |
9 ms |
876 KB |
Output is correct |
16 |
Correct |
7 ms |
876 KB |
Output is correct |
17 |
Correct |
8 ms |
876 KB |
Output is correct |
18 |
Correct |
4 ms |
748 KB |
Output is correct |
19 |
Correct |
366 ms |
12940 KB |
Output is correct |
20 |
Correct |
368 ms |
13032 KB |
Output is correct |
21 |
Correct |
365 ms |
12924 KB |
Output is correct |
22 |
Correct |
309 ms |
12824 KB |
Output is correct |
23 |
Correct |
294 ms |
12804 KB |
Output is correct |
24 |
Correct |
182 ms |
12424 KB |
Output is correct |
25 |
Correct |
340 ms |
12880 KB |
Output is correct |
26 |
Correct |
345 ms |
13080 KB |
Output is correct |
27 |
Correct |
330 ms |
13060 KB |
Output is correct |
28 |
Correct |
275 ms |
12932 KB |
Output is correct |
29 |
Correct |
282 ms |
12956 KB |
Output is correct |
30 |
Correct |
150 ms |
12580 KB |
Output is correct |
31 |
Correct |
402 ms |
13180 KB |
Output is correct |
32 |
Correct |
402 ms |
12924 KB |
Output is correct |
33 |
Correct |
368 ms |
12964 KB |
Output is correct |
34 |
Correct |
338 ms |
12804 KB |
Output is correct |
35 |
Correct |
330 ms |
12804 KB |
Output is correct |
36 |
Correct |
198 ms |
12424 KB |
Output is correct |
37 |
Correct |
398 ms |
13220 KB |
Output is correct |
38 |
Correct |
401 ms |
13160 KB |
Output is correct |
39 |
Correct |
382 ms |
13060 KB |
Output is correct |
40 |
Correct |
274 ms |
12676 KB |
Output is correct |
41 |
Correct |
281 ms |
12836 KB |
Output is correct |
42 |
Correct |
148 ms |
12424 KB |
Output is correct |
43 |
Correct |
446 ms |
14856 KB |
Output is correct |
44 |
Correct |
457 ms |
14796 KB |
Output is correct |
45 |
Correct |
451 ms |
14728 KB |
Output is correct |
46 |
Correct |
367 ms |
13984 KB |
Output is correct |
47 |
Correct |
362 ms |
13984 KB |
Output is correct |
48 |
Correct |
203 ms |
12496 KB |
Output is correct |
49 |
Correct |
426 ms |
15016 KB |
Output is correct |
50 |
Correct |
422 ms |
14856 KB |
Output is correct |
51 |
Correct |
418 ms |
14788 KB |
Output is correct |
52 |
Correct |
340 ms |
13572 KB |
Output is correct |
53 |
Correct |
298 ms |
13180 KB |
Output is correct |