#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
struct query{
int x, y, z, id;
};
bool comp(query a, query b){
return a.z > b.z;
}
bool comp2(ii a, ii b){
return a.first + a.second > b.first + b.second;
}
class SegmentTree{
public:
int n;
unordered_map<int,int> tree;
void create(int nn){
n = nn;
}
void update(int i){
i += n;
while(i > 0){
tree[i]++;
i >>= 1;
}
}
int query(int l, int r){
int ans = 0;
for(l += n,r += n;l < r;l >>= 1, r >>= 1){
if(l & 1){
ans += tree[l];
l++;
}
if(r & 1){
r--;
ans += tree[r];
}
}
return ans;
}
};
int main()
{
//freopen("i.txt","r",stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
ii arr[n];
for(int i = 0;i < n;i++){
cin >> arr[i].first >> arr[i].second;
}
query queries[m];
for(int i = 0;i < m;i++){
int x, y, z;
cin >> x >> y >> z;
z = max(z, x + y);
query q;
q.z = z;
q.y = y;
q.x = x;
q.id = i;
queries[i] = q;
}
sort(queries,queries+m,comp);
sort(arr,arr+n,comp2);
SegmentTree x;
SegmentTree y;
x.create(1000000005);
y.create(1000000005);
int ans[m];
int c = 0;
for(int i = 0;i < m;i++){
//cout << queries[i].z << ": ";
while(true){
if(c == n) break;
if(arr[c].first + arr[c].second < queries[i].z) break;
//cout << arr[c].first << " " << arr[c].second << "|";
x.update(arr[c].first);
y.update(arr[c].second);
c++;
}
ans[queries[i].id] = c - x.query(0,queries[i].x) - y.query(0,queries[i].y);
//cout << "\n";
}
for(int i = 0;i < m;i++){
cout << ans[i] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
55 ms |
7548 KB |
Output is correct |
8 |
Correct |
71 ms |
7584 KB |
Output is correct |
9 |
Correct |
57 ms |
7448 KB |
Output is correct |
10 |
Correct |
27 ms |
3976 KB |
Output is correct |
11 |
Correct |
25 ms |
3976 KB |
Output is correct |
12 |
Correct |
7 ms |
428 KB |
Output is correct |
13 |
Correct |
52 ms |
7576 KB |
Output is correct |
14 |
Correct |
51 ms |
7576 KB |
Output is correct |
15 |
Correct |
74 ms |
7572 KB |
Output is correct |
16 |
Correct |
26 ms |
3976 KB |
Output is correct |
17 |
Correct |
26 ms |
3976 KB |
Output is correct |
18 |
Correct |
8 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
634 ms |
20256 KB |
Output is correct |
2 |
Correct |
603 ms |
20348 KB |
Output is correct |
3 |
Correct |
718 ms |
20236 KB |
Output is correct |
4 |
Correct |
247 ms |
12472 KB |
Output is correct |
5 |
Correct |
253 ms |
12472 KB |
Output is correct |
6 |
Correct |
168 ms |
4728 KB |
Output is correct |
7 |
Correct |
666 ms |
19796 KB |
Output is correct |
8 |
Correct |
565 ms |
19836 KB |
Output is correct |
9 |
Correct |
541 ms |
19352 KB |
Output is correct |
10 |
Correct |
244 ms |
12312 KB |
Output is correct |
11 |
Correct |
253 ms |
12344 KB |
Output is correct |
12 |
Correct |
186 ms |
4204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
634 ms |
20256 KB |
Output is correct |
2 |
Correct |
603 ms |
20348 KB |
Output is correct |
3 |
Correct |
718 ms |
20236 KB |
Output is correct |
4 |
Correct |
247 ms |
12472 KB |
Output is correct |
5 |
Correct |
253 ms |
12472 KB |
Output is correct |
6 |
Correct |
168 ms |
4728 KB |
Output is correct |
7 |
Correct |
666 ms |
19796 KB |
Output is correct |
8 |
Correct |
565 ms |
19836 KB |
Output is correct |
9 |
Correct |
541 ms |
19352 KB |
Output is correct |
10 |
Correct |
244 ms |
12312 KB |
Output is correct |
11 |
Correct |
253 ms |
12344 KB |
Output is correct |
12 |
Correct |
186 ms |
4204 KB |
Output is correct |
13 |
Correct |
708 ms |
20656 KB |
Output is correct |
14 |
Correct |
679 ms |
20704 KB |
Output is correct |
15 |
Correct |
718 ms |
20344 KB |
Output is correct |
16 |
Correct |
302 ms |
12888 KB |
Output is correct |
17 |
Correct |
295 ms |
12828 KB |
Output is correct |
18 |
Correct |
169 ms |
4664 KB |
Output is correct |
19 |
Correct |
601 ms |
20604 KB |
Output is correct |
20 |
Correct |
614 ms |
20732 KB |
Output is correct |
21 |
Correct |
746 ms |
20404 KB |
Output is correct |
22 |
Correct |
245 ms |
12448 KB |
Output is correct |
23 |
Correct |
308 ms |
12320 KB |
Output is correct |
24 |
Correct |
183 ms |
4220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
55 ms |
7548 KB |
Output is correct |
8 |
Correct |
71 ms |
7584 KB |
Output is correct |
9 |
Correct |
57 ms |
7448 KB |
Output is correct |
10 |
Correct |
27 ms |
3976 KB |
Output is correct |
11 |
Correct |
25 ms |
3976 KB |
Output is correct |
12 |
Correct |
7 ms |
428 KB |
Output is correct |
13 |
Correct |
52 ms |
7576 KB |
Output is correct |
14 |
Correct |
51 ms |
7576 KB |
Output is correct |
15 |
Correct |
74 ms |
7572 KB |
Output is correct |
16 |
Correct |
26 ms |
3976 KB |
Output is correct |
17 |
Correct |
26 ms |
3976 KB |
Output is correct |
18 |
Correct |
8 ms |
384 KB |
Output is correct |
19 |
Correct |
634 ms |
20256 KB |
Output is correct |
20 |
Correct |
603 ms |
20348 KB |
Output is correct |
21 |
Correct |
718 ms |
20236 KB |
Output is correct |
22 |
Correct |
247 ms |
12472 KB |
Output is correct |
23 |
Correct |
253 ms |
12472 KB |
Output is correct |
24 |
Correct |
168 ms |
4728 KB |
Output is correct |
25 |
Correct |
666 ms |
19796 KB |
Output is correct |
26 |
Correct |
565 ms |
19836 KB |
Output is correct |
27 |
Correct |
541 ms |
19352 KB |
Output is correct |
28 |
Correct |
244 ms |
12312 KB |
Output is correct |
29 |
Correct |
253 ms |
12344 KB |
Output is correct |
30 |
Correct |
186 ms |
4204 KB |
Output is correct |
31 |
Correct |
708 ms |
20656 KB |
Output is correct |
32 |
Correct |
679 ms |
20704 KB |
Output is correct |
33 |
Correct |
718 ms |
20344 KB |
Output is correct |
34 |
Correct |
302 ms |
12888 KB |
Output is correct |
35 |
Correct |
295 ms |
12828 KB |
Output is correct |
36 |
Correct |
169 ms |
4664 KB |
Output is correct |
37 |
Correct |
601 ms |
20604 KB |
Output is correct |
38 |
Correct |
614 ms |
20732 KB |
Output is correct |
39 |
Correct |
746 ms |
20404 KB |
Output is correct |
40 |
Correct |
245 ms |
12448 KB |
Output is correct |
41 |
Correct |
308 ms |
12320 KB |
Output is correct |
42 |
Correct |
183 ms |
4220 KB |
Output is correct |
43 |
Execution timed out |
3038 ms |
148888 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |