#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;
vector<int> tree;
void create(int nn){
n = nn;
for(int i = 0;i < 2 * n + 5;i++){
tree.push_back(0);
}
}
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;
map<int,int> dis;
ii arr[n];
for(int i = 0;i < n;i++){
cin >> arr[i].first >> arr[i].second;
dis[arr[i].first] = 0;
dis[arr[i].second] = 0;
}
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;
dis[x] = 0;
dis[y] = 0;
q.id = i;
queries[i] = q;
}
int cc = 0;
for(map<int,int>::iterator it = dis.begin();it != dis.end();it++){
it->second = cc;
cc++;
}
sort(queries,queries+m,comp);
sort(arr,arr+n,comp2);
SegmentTree x;
SegmentTree y;
x.create(dis.size());
y.create(dis.size());
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(dis[arr[c].first]);
y.update(dis[arr[c].second]);
c++;
}
ans[queries[i].id] = c - x.query(0,dis[queries[i].x]) - y.query(0,dis[queries[i].y]);
//cout << "\n";
}
for(int i = 0;i < m;i++){
cout << ans[i] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
404 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 |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
11 ms |
1408 KB |
Output is correct |
8 |
Correct |
11 ms |
1280 KB |
Output is correct |
9 |
Correct |
11 ms |
1408 KB |
Output is correct |
10 |
Correct |
7 ms |
896 KB |
Output is correct |
11 |
Correct |
7 ms |
896 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
10 ms |
1408 KB |
Output is correct |
14 |
Correct |
11 ms |
1408 KB |
Output is correct |
15 |
Correct |
11 ms |
1280 KB |
Output is correct |
16 |
Correct |
6 ms |
896 KB |
Output is correct |
17 |
Correct |
7 ms |
896 KB |
Output is correct |
18 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
408 ms |
9940 KB |
Output is correct |
2 |
Correct |
479 ms |
9960 KB |
Output is correct |
3 |
Correct |
455 ms |
9980 KB |
Output is correct |
4 |
Correct |
201 ms |
9320 KB |
Output is correct |
5 |
Correct |
223 ms |
9172 KB |
Output is correct |
6 |
Correct |
63 ms |
3704 KB |
Output is correct |
7 |
Correct |
395 ms |
9900 KB |
Output is correct |
8 |
Correct |
394 ms |
9768 KB |
Output is correct |
9 |
Correct |
352 ms |
9324 KB |
Output is correct |
10 |
Correct |
197 ms |
9064 KB |
Output is correct |
11 |
Correct |
228 ms |
9068 KB |
Output is correct |
12 |
Correct |
54 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
408 ms |
9940 KB |
Output is correct |
2 |
Correct |
479 ms |
9960 KB |
Output is correct |
3 |
Correct |
455 ms |
9980 KB |
Output is correct |
4 |
Correct |
201 ms |
9320 KB |
Output is correct |
5 |
Correct |
223 ms |
9172 KB |
Output is correct |
6 |
Correct |
63 ms |
3704 KB |
Output is correct |
7 |
Correct |
395 ms |
9900 KB |
Output is correct |
8 |
Correct |
394 ms |
9768 KB |
Output is correct |
9 |
Correct |
352 ms |
9324 KB |
Output is correct |
10 |
Correct |
197 ms |
9064 KB |
Output is correct |
11 |
Correct |
228 ms |
9068 KB |
Output is correct |
12 |
Correct |
54 ms |
3320 KB |
Output is correct |
13 |
Correct |
467 ms |
9968 KB |
Output is correct |
14 |
Correct |
445 ms |
9968 KB |
Output is correct |
15 |
Correct |
553 ms |
9936 KB |
Output is correct |
16 |
Correct |
228 ms |
9320 KB |
Output is correct |
17 |
Correct |
233 ms |
9352 KB |
Output is correct |
18 |
Correct |
62 ms |
3676 KB |
Output is correct |
19 |
Correct |
507 ms |
9952 KB |
Output is correct |
20 |
Correct |
516 ms |
10080 KB |
Output is correct |
21 |
Correct |
440 ms |
9772 KB |
Output is correct |
22 |
Correct |
219 ms |
9084 KB |
Output is correct |
23 |
Correct |
222 ms |
9080 KB |
Output is correct |
24 |
Correct |
51 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
404 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 |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
11 ms |
1408 KB |
Output is correct |
8 |
Correct |
11 ms |
1280 KB |
Output is correct |
9 |
Correct |
11 ms |
1408 KB |
Output is correct |
10 |
Correct |
7 ms |
896 KB |
Output is correct |
11 |
Correct |
7 ms |
896 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
10 ms |
1408 KB |
Output is correct |
14 |
Correct |
11 ms |
1408 KB |
Output is correct |
15 |
Correct |
11 ms |
1280 KB |
Output is correct |
16 |
Correct |
6 ms |
896 KB |
Output is correct |
17 |
Correct |
7 ms |
896 KB |
Output is correct |
18 |
Correct |
4 ms |
512 KB |
Output is correct |
19 |
Correct |
408 ms |
9940 KB |
Output is correct |
20 |
Correct |
479 ms |
9960 KB |
Output is correct |
21 |
Correct |
455 ms |
9980 KB |
Output is correct |
22 |
Correct |
201 ms |
9320 KB |
Output is correct |
23 |
Correct |
223 ms |
9172 KB |
Output is correct |
24 |
Correct |
63 ms |
3704 KB |
Output is correct |
25 |
Correct |
395 ms |
9900 KB |
Output is correct |
26 |
Correct |
394 ms |
9768 KB |
Output is correct |
27 |
Correct |
352 ms |
9324 KB |
Output is correct |
28 |
Correct |
197 ms |
9064 KB |
Output is correct |
29 |
Correct |
228 ms |
9068 KB |
Output is correct |
30 |
Correct |
54 ms |
3320 KB |
Output is correct |
31 |
Correct |
467 ms |
9968 KB |
Output is correct |
32 |
Correct |
445 ms |
9968 KB |
Output is correct |
33 |
Correct |
553 ms |
9936 KB |
Output is correct |
34 |
Correct |
228 ms |
9320 KB |
Output is correct |
35 |
Correct |
233 ms |
9352 KB |
Output is correct |
36 |
Correct |
62 ms |
3676 KB |
Output is correct |
37 |
Correct |
507 ms |
9952 KB |
Output is correct |
38 |
Correct |
516 ms |
10080 KB |
Output is correct |
39 |
Correct |
440 ms |
9772 KB |
Output is correct |
40 |
Correct |
219 ms |
9084 KB |
Output is correct |
41 |
Correct |
222 ms |
9080 KB |
Output is correct |
42 |
Correct |
51 ms |
3320 KB |
Output is correct |
43 |
Correct |
978 ms |
30944 KB |
Output is correct |
44 |
Correct |
1002 ms |
35924 KB |
Output is correct |
45 |
Correct |
979 ms |
35728 KB |
Output is correct |
46 |
Correct |
385 ms |
20004 KB |
Output is correct |
47 |
Correct |
381 ms |
20044 KB |
Output is correct |
48 |
Correct |
66 ms |
4472 KB |
Output is correct |
49 |
Correct |
956 ms |
35484 KB |
Output is correct |
50 |
Correct |
942 ms |
35580 KB |
Output is correct |
51 |
Correct |
830 ms |
35544 KB |
Output is correct |
52 |
Correct |
351 ms |
20076 KB |
Output is correct |
53 |
Correct |
313 ms |
19240 KB |
Output is correct |