#include <bits/stdc++.h>
#define uwu return 0;
using namespace std;
const int INF = 1e9 + 7, SIZE = 1e5 + 5, LOGC = 400;
struct event{
int id, a, b, sum;
};
bool cmp(event e1, event e2){
return e1.sum != e2.sum ? e1.sum > e2.sum : e1.id < e2.id;
}
vector <int> desa, desb;
int getposa(int a){
return lower_bound(desa.begin(), desa.end(), -a) - desa.begin() + 1;
}
int getposb(int b){
return lower_bound(desb.begin(), desb.end(), b) - desb.begin();
}
vector <event> vec;
int ptr = 0;
struct node{
int l, r, val;
} SEGTree[SIZE * LOGC];
int BIT[2 * SIZE];
#define nd SEGTree[rt]
#define lc SEGTree[rt].l
#define rc SEGTree[rt].r
void modify_SEG(int pos, int L, int R, int rt){
nd.val++;
if(L == R)
return;
int M = (L + R) >> 1;
if(pos <= M){
if(!lc)
lc = ++ptr;
modify_SEG(pos, L, M, lc);
}
else{
if(!rc)
rc = ++ptr;
modify_SEG(pos, M + 1, R, rc);
}
return;
}
int query_SEG(int ql, int qr, int L, int R, int rt){
if(!rt)
return 0;
if(ql <= L && R <= qr)
return nd.val;
int M = (L + R) >> 1;
if(qr<= M)
return query_SEG(ql, qr, L, M, lc);
if(ql > M)
return query_SEG(ql, qr, M + 1, R, rc);
return query_SEG(ql, M, L, M, lc) + query_SEG(M + 1, qr, M + 1, R, rc);
}
void modify_BIT(int posa, int posb){
for (; posa <= desa.size(); posa += (posa & - posa)){
if(!BIT[posa])
BIT[posa] = ++ptr;
modify_SEG(posb, 0, desb.size(), BIT[posa]);
}
return;
}
int query_BIT(int posa, int posb){
int ret = 0;
for (; posa; posa -= (posa & - posa)){
if(BIT[posa]){
ret += query_SEG(posb, desb.size(), 0, desb.size(), BIT[posa]);
}
}
return ret;
}
int N, Q;
int ans[SIZE];
int main(){
cin.tie(0), ios::sync_with_stdio(0);
cin >> N >> Q;
event in_e;
for (int i = 0; i < N; i++){
in_e.id = 0;
cin >> in_e.a >> in_e.b;
in_e.sum = in_e.a + in_e.b;
desa.push_back(-in_e.a);
desb.push_back(in_e.b);
vec.push_back(in_e);
}
for (int i = 0; i < Q; i++){
in_e.id = i + 1;
cin >> in_e.a >> in_e.b >> in_e.sum;
desa.push_back(-in_e.a);
desb.push_back(in_e.b);
vec.push_back(in_e);
}
sort(desa.begin(), desa.end());
sort(desb.begin(), desb.end());
sort(vec.begin(), vec.end(), cmp);
for(auto i:vec){
if(i.id){
ans[i.id] = query_BIT(getposa(i.a), getposb(i.b));
}
else{
modify_BIT(getposa(i.a), getposb(i.b));
}
}
for (int i = 1; i <= Q; i++){
cout << ans[i] << '\n';
}
uwu
}
Compilation message
examination.cpp: In function 'void modify_BIT(int, int)':
examination.cpp:75:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for (; posa <= desa.size(); posa += (posa & - posa)){
| ~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
6 ms |
4956 KB |
Output is correct |
8 |
Correct |
7 ms |
4956 KB |
Output is correct |
9 |
Correct |
6 ms |
4956 KB |
Output is correct |
10 |
Correct |
5 ms |
4804 KB |
Output is correct |
11 |
Correct |
5 ms |
4952 KB |
Output is correct |
12 |
Correct |
4 ms |
2652 KB |
Output is correct |
13 |
Correct |
6 ms |
4956 KB |
Output is correct |
14 |
Correct |
6 ms |
4956 KB |
Output is correct |
15 |
Correct |
8 ms |
4956 KB |
Output is correct |
16 |
Correct |
4 ms |
3160 KB |
Output is correct |
17 |
Correct |
4 ms |
2908 KB |
Output is correct |
18 |
Correct |
4 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
690 ms |
130832 KB |
Output is correct |
2 |
Correct |
637 ms |
131396 KB |
Output is correct |
3 |
Correct |
669 ms |
131032 KB |
Output is correct |
4 |
Correct |
283 ms |
69456 KB |
Output is correct |
5 |
Correct |
239 ms |
72628 KB |
Output is correct |
6 |
Correct |
121 ms |
11088 KB |
Output is correct |
7 |
Correct |
455 ms |
126916 KB |
Output is correct |
8 |
Correct |
428 ms |
124928 KB |
Output is correct |
9 |
Correct |
356 ms |
118200 KB |
Output is correct |
10 |
Correct |
171 ms |
41640 KB |
Output is correct |
11 |
Correct |
138 ms |
35616 KB |
Output is correct |
12 |
Correct |
106 ms |
10184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
690 ms |
130832 KB |
Output is correct |
2 |
Correct |
637 ms |
131396 KB |
Output is correct |
3 |
Correct |
669 ms |
131032 KB |
Output is correct |
4 |
Correct |
283 ms |
69456 KB |
Output is correct |
5 |
Correct |
239 ms |
72628 KB |
Output is correct |
6 |
Correct |
121 ms |
11088 KB |
Output is correct |
7 |
Correct |
455 ms |
126916 KB |
Output is correct |
8 |
Correct |
428 ms |
124928 KB |
Output is correct |
9 |
Correct |
356 ms |
118200 KB |
Output is correct |
10 |
Correct |
171 ms |
41640 KB |
Output is correct |
11 |
Correct |
138 ms |
35616 KB |
Output is correct |
12 |
Correct |
106 ms |
10184 KB |
Output is correct |
13 |
Correct |
542 ms |
131280 KB |
Output is correct |
14 |
Correct |
647 ms |
131200 KB |
Output is correct |
15 |
Correct |
588 ms |
130832 KB |
Output is correct |
16 |
Correct |
227 ms |
66996 KB |
Output is correct |
17 |
Correct |
215 ms |
68904 KB |
Output is correct |
18 |
Correct |
135 ms |
10696 KB |
Output is correct |
19 |
Correct |
460 ms |
131624 KB |
Output is correct |
20 |
Correct |
578 ms |
131156 KB |
Output is correct |
21 |
Correct |
386 ms |
127128 KB |
Output is correct |
22 |
Correct |
148 ms |
33408 KB |
Output is correct |
23 |
Correct |
143 ms |
35416 KB |
Output is correct |
24 |
Correct |
103 ms |
10440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
6 ms |
4956 KB |
Output is correct |
8 |
Correct |
7 ms |
4956 KB |
Output is correct |
9 |
Correct |
6 ms |
4956 KB |
Output is correct |
10 |
Correct |
5 ms |
4804 KB |
Output is correct |
11 |
Correct |
5 ms |
4952 KB |
Output is correct |
12 |
Correct |
4 ms |
2652 KB |
Output is correct |
13 |
Correct |
6 ms |
4956 KB |
Output is correct |
14 |
Correct |
6 ms |
4956 KB |
Output is correct |
15 |
Correct |
8 ms |
4956 KB |
Output is correct |
16 |
Correct |
4 ms |
3160 KB |
Output is correct |
17 |
Correct |
4 ms |
2908 KB |
Output is correct |
18 |
Correct |
4 ms |
2652 KB |
Output is correct |
19 |
Correct |
690 ms |
130832 KB |
Output is correct |
20 |
Correct |
637 ms |
131396 KB |
Output is correct |
21 |
Correct |
669 ms |
131032 KB |
Output is correct |
22 |
Correct |
283 ms |
69456 KB |
Output is correct |
23 |
Correct |
239 ms |
72628 KB |
Output is correct |
24 |
Correct |
121 ms |
11088 KB |
Output is correct |
25 |
Correct |
455 ms |
126916 KB |
Output is correct |
26 |
Correct |
428 ms |
124928 KB |
Output is correct |
27 |
Correct |
356 ms |
118200 KB |
Output is correct |
28 |
Correct |
171 ms |
41640 KB |
Output is correct |
29 |
Correct |
138 ms |
35616 KB |
Output is correct |
30 |
Correct |
106 ms |
10184 KB |
Output is correct |
31 |
Correct |
542 ms |
131280 KB |
Output is correct |
32 |
Correct |
647 ms |
131200 KB |
Output is correct |
33 |
Correct |
588 ms |
130832 KB |
Output is correct |
34 |
Correct |
227 ms |
66996 KB |
Output is correct |
35 |
Correct |
215 ms |
68904 KB |
Output is correct |
36 |
Correct |
135 ms |
10696 KB |
Output is correct |
37 |
Correct |
460 ms |
131624 KB |
Output is correct |
38 |
Correct |
578 ms |
131156 KB |
Output is correct |
39 |
Correct |
386 ms |
127128 KB |
Output is correct |
40 |
Correct |
148 ms |
33408 KB |
Output is correct |
41 |
Correct |
143 ms |
35416 KB |
Output is correct |
42 |
Correct |
103 ms |
10440 KB |
Output is correct |
43 |
Correct |
532 ms |
133240 KB |
Output is correct |
44 |
Correct |
497 ms |
133168 KB |
Output is correct |
45 |
Correct |
618 ms |
134120 KB |
Output is correct |
46 |
Correct |
246 ms |
72076 KB |
Output is correct |
47 |
Correct |
223 ms |
78728 KB |
Output is correct |
48 |
Correct |
134 ms |
10168 KB |
Output is correct |
49 |
Correct |
466 ms |
128952 KB |
Output is correct |
50 |
Correct |
373 ms |
129720 KB |
Output is correct |
51 |
Correct |
375 ms |
122864 KB |
Output is correct |
52 |
Correct |
194 ms |
51368 KB |
Output is correct |
53 |
Correct |
143 ms |
43204 KB |
Output is correct |