#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
const int lim = 4e5 + 5;
struct FenwickTree{
int bit[lim];
FenwickTree(){
memset(bit, 0, sizeof(bit));
}
void update(int p){
for(; p < lim; p += p & -p){
bit[p]++;
}
}
int get(int p){
int ans = 0;
for(; p > 0; p -= p & -p){
ans += bit[p];
}
return ans;
}
};
vector<tuple<int, int, int, int>>query;
FenwickTree X, Y;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
int n, q;
cin >> n >> q;
map<int, int>index;
for(int _ = 0; _ < n; _++){
int s, t;
cin >> s >> t;
query.emplace_back(s, t, s + t, index[s] = index[t] = 0);
}
for(int i = 1; i <= n; i++){
int x, y, z;
cin >> x >> y >> z;
index[x] = index[y] = 0;
query.emplace_back(x, y, max(x + y, z), i);
}
sort(query.begin(), query.end(), [&] (auto i, auto j) -> bool{
if(get<2>(i) != get<2>(j)){
return get<2>(i) > get<2>(j);
}
return get<3>(i) < get<3>(j);
});
int cnt = 0;
for(auto& [x, y] : index){
y = ++cnt;
}
cnt = 0;
vector<int>ans(q + 1);
for(auto& [x, y, z, i] : query){
if(i == 0){
X.update(index[x]);
Y.update(index[y]);
cnt++;
}
else{
ans[i] = cnt - X.get(index[x] - 1) - Y.get(index[y] - 1);
}
}
for(int i = 1; i <= q; i++){
cout << ans[i] << "\n";
}
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:51:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
51 | for(auto& [x, y] : index){
| ^
examination.cpp:56:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
56 | for(auto& [x, y, z, i] : query){
| ^
examination.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3416 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
7 ms |
4188 KB |
Output is correct |
8 |
Correct |
7 ms |
4188 KB |
Output is correct |
9 |
Correct |
7 ms |
4188 KB |
Output is correct |
10 |
Correct |
4 ms |
3928 KB |
Output is correct |
11 |
Correct |
4 ms |
3932 KB |
Output is correct |
12 |
Correct |
3 ms |
3696 KB |
Output is correct |
13 |
Correct |
7 ms |
4188 KB |
Output is correct |
14 |
Correct |
7 ms |
4316 KB |
Output is correct |
15 |
Correct |
7 ms |
4188 KB |
Output is correct |
16 |
Correct |
4 ms |
3860 KB |
Output is correct |
17 |
Correct |
5 ms |
3932 KB |
Output is correct |
18 |
Correct |
2 ms |
3676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
13760 KB |
Output is correct |
2 |
Correct |
208 ms |
13760 KB |
Output is correct |
3 |
Correct |
206 ms |
12932 KB |
Output is correct |
4 |
Correct |
119 ms |
11704 KB |
Output is correct |
5 |
Correct |
121 ms |
12544 KB |
Output is correct |
6 |
Correct |
54 ms |
7872 KB |
Output is correct |
7 |
Correct |
200 ms |
14564 KB |
Output is correct |
8 |
Correct |
198 ms |
15516 KB |
Output is correct |
9 |
Correct |
205 ms |
14016 KB |
Output is correct |
10 |
Correct |
118 ms |
13064 KB |
Output is correct |
11 |
Correct |
115 ms |
13468 KB |
Output is correct |
12 |
Correct |
46 ms |
8892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
13760 KB |
Output is correct |
2 |
Correct |
208 ms |
13760 KB |
Output is correct |
3 |
Correct |
206 ms |
12932 KB |
Output is correct |
4 |
Correct |
119 ms |
11704 KB |
Output is correct |
5 |
Correct |
121 ms |
12544 KB |
Output is correct |
6 |
Correct |
54 ms |
7872 KB |
Output is correct |
7 |
Correct |
200 ms |
14564 KB |
Output is correct |
8 |
Correct |
198 ms |
15516 KB |
Output is correct |
9 |
Correct |
205 ms |
14016 KB |
Output is correct |
10 |
Correct |
118 ms |
13064 KB |
Output is correct |
11 |
Correct |
115 ms |
13468 KB |
Output is correct |
12 |
Correct |
46 ms |
8892 KB |
Output is correct |
13 |
Correct |
219 ms |
15176 KB |
Output is correct |
14 |
Correct |
209 ms |
15032 KB |
Output is correct |
15 |
Correct |
209 ms |
14984 KB |
Output is correct |
16 |
Correct |
129 ms |
13680 KB |
Output is correct |
17 |
Correct |
129 ms |
14536 KB |
Output is correct |
18 |
Correct |
56 ms |
10188 KB |
Output is correct |
19 |
Correct |
212 ms |
15032 KB |
Output is correct |
20 |
Correct |
211 ms |
15028 KB |
Output is correct |
21 |
Correct |
210 ms |
15744 KB |
Output is correct |
22 |
Correct |
113 ms |
14020 KB |
Output is correct |
23 |
Correct |
114 ms |
13268 KB |
Output is correct |
24 |
Correct |
45 ms |
8912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3416 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
7 ms |
4188 KB |
Output is correct |
8 |
Correct |
7 ms |
4188 KB |
Output is correct |
9 |
Correct |
7 ms |
4188 KB |
Output is correct |
10 |
Correct |
4 ms |
3928 KB |
Output is correct |
11 |
Correct |
4 ms |
3932 KB |
Output is correct |
12 |
Correct |
3 ms |
3696 KB |
Output is correct |
13 |
Correct |
7 ms |
4188 KB |
Output is correct |
14 |
Correct |
7 ms |
4316 KB |
Output is correct |
15 |
Correct |
7 ms |
4188 KB |
Output is correct |
16 |
Correct |
4 ms |
3860 KB |
Output is correct |
17 |
Correct |
5 ms |
3932 KB |
Output is correct |
18 |
Correct |
2 ms |
3676 KB |
Output is correct |
19 |
Correct |
206 ms |
13760 KB |
Output is correct |
20 |
Correct |
208 ms |
13760 KB |
Output is correct |
21 |
Correct |
206 ms |
12932 KB |
Output is correct |
22 |
Correct |
119 ms |
11704 KB |
Output is correct |
23 |
Correct |
121 ms |
12544 KB |
Output is correct |
24 |
Correct |
54 ms |
7872 KB |
Output is correct |
25 |
Correct |
200 ms |
14564 KB |
Output is correct |
26 |
Correct |
198 ms |
15516 KB |
Output is correct |
27 |
Correct |
205 ms |
14016 KB |
Output is correct |
28 |
Correct |
118 ms |
13064 KB |
Output is correct |
29 |
Correct |
115 ms |
13468 KB |
Output is correct |
30 |
Correct |
46 ms |
8892 KB |
Output is correct |
31 |
Correct |
219 ms |
15176 KB |
Output is correct |
32 |
Correct |
209 ms |
15032 KB |
Output is correct |
33 |
Correct |
209 ms |
14984 KB |
Output is correct |
34 |
Correct |
129 ms |
13680 KB |
Output is correct |
35 |
Correct |
129 ms |
14536 KB |
Output is correct |
36 |
Correct |
56 ms |
10188 KB |
Output is correct |
37 |
Correct |
212 ms |
15032 KB |
Output is correct |
38 |
Correct |
211 ms |
15028 KB |
Output is correct |
39 |
Correct |
210 ms |
15744 KB |
Output is correct |
40 |
Correct |
113 ms |
14020 KB |
Output is correct |
41 |
Correct |
114 ms |
13268 KB |
Output is correct |
42 |
Correct |
45 ms |
8912 KB |
Output is correct |
43 |
Correct |
522 ms |
31104 KB |
Output is correct |
44 |
Correct |
562 ms |
31924 KB |
Output is correct |
45 |
Correct |
502 ms |
31160 KB |
Output is correct |
46 |
Correct |
181 ms |
20316 KB |
Output is correct |
47 |
Correct |
173 ms |
20352 KB |
Output is correct |
48 |
Correct |
56 ms |
9416 KB |
Output is correct |
49 |
Correct |
480 ms |
32160 KB |
Output is correct |
50 |
Correct |
577 ms |
31188 KB |
Output is correct |
51 |
Correct |
485 ms |
31036 KB |
Output is correct |
52 |
Correct |
180 ms |
20412 KB |
Output is correct |
53 |
Correct |
149 ms |
19392 KB |
Output is correct |