#include <bits/stdc++.h>
using namespace std;
struct BIT{
vector<int> tree;
int N;
BIT(int _n){
N = _n;
tree.resize(N+1);
}
void upd(int pos, int val){
for(++pos; pos <= N; pos += (pos & (-pos)))
tree[pos] += val;
}
int que(int idx){
int sum = 0;
for(idx++; idx > 0; idx -= (idx & (-idx)))
sum += tree[idx];
return sum;
}
};
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
vector<array<int, 4>> marks(n), query(q);
vector<int> ds(n+q), dt(n+q);
vector<BIT> ft(2, n+q);
for(int i = 0; i < n; i++){
auto& [tot, s, t, idx] = marks[i];
cin >> s >> t;
tot = s + t;
idx = i;
ds[i] = s;
dt[i] = t;
}
for(int i = 0; i < q; i++){
auto& [tot, s, t, idx] = query[i];
cin >> s >> t >> tot;
tot = max(tot, s + t);
idx = i;
ds[i+n] = s;
dt[i+n] = t;
}
sort(ds.begin(), ds.end());
ds.erase(unique(ds.begin(), ds.end()), ds.end());
sort(dt.begin(), dt.end());
dt.erase(unique(dt.begin(), dt.end()), dt.end());
for(auto& [tot, s, t, idx] : marks){
s = lower_bound(ds.begin(), ds.end(), s) - ds.begin();
t = lower_bound(dt.begin(), dt.end(), t) - dt.begin();
}
for(auto& [tot, s, t, idx] : query){
s = lower_bound(ds.begin(), ds.end(), s) - ds.begin();
t = lower_bound(dt.begin(), dt.end(), t) - dt.begin();
}
sort(marks.rbegin(), marks.rend());
sort(query.rbegin(), query.rend());
vector<int> ans(q);
int idx = 0;
for(int i = 0; i < q; i++){
while(marks[idx][0] >= query[i][0]){
ft[0].upd(marks[idx][1], 1);
ft[1].upd(marks[idx][2], 1);
idx++;
}
ans[query[i][3]] = idx - ft[0].que(query[i][1]-1) - ft[1].que(query[i][2]-1);
}
for(int i = 0; i < q; i++)
cout << ans[i] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
6 ms |
620 KB |
Output is correct |
8 |
Correct |
6 ms |
620 KB |
Output is correct |
9 |
Correct |
6 ms |
620 KB |
Output is correct |
10 |
Correct |
5 ms |
620 KB |
Output is correct |
11 |
Correct |
5 ms |
620 KB |
Output is correct |
12 |
Runtime error |
5 ms |
876 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
180 ms |
7644 KB |
Output is correct |
2 |
Correct |
179 ms |
7644 KB |
Output is correct |
3 |
Correct |
180 ms |
7644 KB |
Output is correct |
4 |
Correct |
138 ms |
7644 KB |
Output is correct |
5 |
Correct |
139 ms |
7644 KB |
Output is correct |
6 |
Runtime error |
113 ms |
14044 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
180 ms |
7644 KB |
Output is correct |
2 |
Correct |
179 ms |
7644 KB |
Output is correct |
3 |
Correct |
180 ms |
7644 KB |
Output is correct |
4 |
Correct |
138 ms |
7644 KB |
Output is correct |
5 |
Correct |
139 ms |
7644 KB |
Output is correct |
6 |
Runtime error |
113 ms |
14044 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
6 ms |
620 KB |
Output is correct |
8 |
Correct |
6 ms |
620 KB |
Output is correct |
9 |
Correct |
6 ms |
620 KB |
Output is correct |
10 |
Correct |
5 ms |
620 KB |
Output is correct |
11 |
Correct |
5 ms |
620 KB |
Output is correct |
12 |
Runtime error |
5 ms |
876 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |