#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) == 0;
});
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3504 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3592 KB |
Output is correct |
6 |
Correct |
1 ms |
3416 KB |
Output is correct |
7 |
Correct |
7 ms |
4188 KB |
Output is correct |
8 |
Correct |
6 ms |
4304 KB |
Output is correct |
9 |
Correct |
8 ms |
4696 KB |
Output is correct |
10 |
Correct |
5 ms |
3932 KB |
Output is correct |
11 |
Correct |
5 ms |
3932 KB |
Output is correct |
12 |
Runtime error |
6 ms |
7516 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
14724 KB |
Output is correct |
2 |
Correct |
205 ms |
14780 KB |
Output is correct |
3 |
Correct |
205 ms |
15292 KB |
Output is correct |
4 |
Correct |
123 ms |
13756 KB |
Output is correct |
5 |
Correct |
121 ms |
13480 KB |
Output is correct |
6 |
Runtime error |
100 ms |
15036 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
14724 KB |
Output is correct |
2 |
Correct |
205 ms |
14780 KB |
Output is correct |
3 |
Correct |
205 ms |
15292 KB |
Output is correct |
4 |
Correct |
123 ms |
13756 KB |
Output is correct |
5 |
Correct |
121 ms |
13480 KB |
Output is correct |
6 |
Runtime error |
100 ms |
15036 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3504 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Correct |
1 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3592 KB |
Output is correct |
6 |
Correct |
1 ms |
3416 KB |
Output is correct |
7 |
Correct |
7 ms |
4188 KB |
Output is correct |
8 |
Correct |
6 ms |
4304 KB |
Output is correct |
9 |
Correct |
8 ms |
4696 KB |
Output is correct |
10 |
Correct |
5 ms |
3932 KB |
Output is correct |
11 |
Correct |
5 ms |
3932 KB |
Output is correct |
12 |
Runtime error |
6 ms |
7516 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |