#include <bits/stdc++.h>
#define int long long
#define ll long long
#define pb push_back
using namespace std;
struct point{
int a, b, c, id, val;
};
vector<point> student;
const int maxn = 1e6 + 10;
int ans[maxn];
bool cmp(point x, point y){
if(x.a != y.a) return x.a > y.a;
if(x.b != y.b) return x.b < y.b;
return x.c < y.c;
}
void inv(point &a){
a.a = -a.a;
a.b = -a.b;
a.c = -a.c;
}
int bit[maxn];
int getsum(int i){
ll sum = 0;
while(i > 0){
sum+=bit[i];
i-=(i & (-i));
}
return sum;
}
void update(int i, int v){
while(i < maxn){
bit[i]+=v;
i+=(i & (-i));
}
}
void dnc(int l, int r){
if(l + 1 == r) return;
int mid = (l + r)/2;
dnc(l , mid); dnc(mid, r);
vector<pair<int,int>> rec; vector<point> tmp;
int a = l, b = mid, sum = 0;
while(a < mid && b < r) {
if(student[a].b > student[b].b){
update(student[a].c, student[a].val);
sum+=student[a].val;
rec.push_back({student[a].c,student[a].val});
tmp.push_back(student[a++]);
}
else{
ans[student[b].id] += sum - getsum(student[b].c);
tmp.push_back(student[b++]);
}
}
while(a < mid) tmp.push_back(student[a++]);
while(b < r) ans[student[b].id] += sum - getsum(student[b].c), tmp.push_back(student[b++]);
for(int i = l ; i < r ; ++i) student[i] = tmp[i - l];
for(auto x: rec) update(x.first, -x.second);
vector<pair<int,int>> ().swap(rec);
vector<point> ().swap(tmp);
}
signed main(){
int n, q;
cin >> n >> q;
vector<int> compress;
compress.pb(-1e18); compress.pb(1e18);
for(int i = 0; i < n; i++){
point tmp; cin >> tmp.a >> tmp.b;
tmp.c = tmp.a + tmp.b; tmp.id = 0; tmp.val = 1;
// inv(tmp);
compress.pb(tmp.a);compress.pb(tmp.b);compress.pb(tmp.c);
student.pb(tmp);
}
int cnt = 1;
int _q = q;
while(q--){
point tmp;
cin >> tmp.a >> tmp.b >> tmp.c;
tmp.a--; tmp.b--; tmp.c--;
tmp.val = 0 ;
compress.pb(tmp.a); compress.pb(tmp.b); compress.pb(tmp.c);
tmp.id = cnt;
// inv(tmp);
cnt++;
student.pb(tmp);
}
sort(compress.begin(),compress.end());
for(auto &x : student){
x.a = lower_bound(compress.begin(),compress.end(),x.a) - compress.begin();
x.b = lower_bound(compress.begin(),compress.end(),x.b) - compress.begin();
x.c = lower_bound(compress.begin(),compress.end(),x.c) - compress.begin();
}
sort(student.begin(),student.end(), cmp);
dnc(0, n + _q);
for(int i = 1; i <= _q; i++){
cout << ans[i] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
12 ms |
7632 KB |
Output is correct |
8 |
Correct |
12 ms |
7504 KB |
Output is correct |
9 |
Correct |
12 ms |
7496 KB |
Output is correct |
10 |
Correct |
11 ms |
7500 KB |
Output is correct |
11 |
Correct |
9 ms |
7504 KB |
Output is correct |
12 |
Correct |
7 ms |
7468 KB |
Output is correct |
13 |
Correct |
13 ms |
7632 KB |
Output is correct |
14 |
Correct |
13 ms |
7500 KB |
Output is correct |
15 |
Correct |
17 ms |
7572 KB |
Output is correct |
16 |
Correct |
10 ms |
7504 KB |
Output is correct |
17 |
Correct |
10 ms |
7504 KB |
Output is correct |
18 |
Correct |
5 ms |
7368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
480 ms |
45152 KB |
Output is correct |
2 |
Correct |
482 ms |
43860 KB |
Output is correct |
3 |
Correct |
461 ms |
42396 KB |
Output is correct |
4 |
Correct |
403 ms |
42404 KB |
Output is correct |
5 |
Correct |
300 ms |
39764 KB |
Output is correct |
6 |
Correct |
236 ms |
39016 KB |
Output is correct |
7 |
Correct |
425 ms |
43992 KB |
Output is correct |
8 |
Correct |
452 ms |
43656 KB |
Output is correct |
9 |
Correct |
462 ms |
43372 KB |
Output is correct |
10 |
Correct |
250 ms |
41576 KB |
Output is correct |
11 |
Correct |
338 ms |
41884 KB |
Output is correct |
12 |
Correct |
200 ms |
42276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
480 ms |
45152 KB |
Output is correct |
2 |
Correct |
482 ms |
43860 KB |
Output is correct |
3 |
Correct |
461 ms |
42396 KB |
Output is correct |
4 |
Correct |
403 ms |
42404 KB |
Output is correct |
5 |
Correct |
300 ms |
39764 KB |
Output is correct |
6 |
Correct |
236 ms |
39016 KB |
Output is correct |
7 |
Correct |
425 ms |
43992 KB |
Output is correct |
8 |
Correct |
452 ms |
43656 KB |
Output is correct |
9 |
Correct |
462 ms |
43372 KB |
Output is correct |
10 |
Correct |
250 ms |
41576 KB |
Output is correct |
11 |
Correct |
338 ms |
41884 KB |
Output is correct |
12 |
Correct |
200 ms |
42276 KB |
Output is correct |
13 |
Correct |
476 ms |
44480 KB |
Output is correct |
14 |
Correct |
492 ms |
43788 KB |
Output is correct |
15 |
Correct |
483 ms |
44004 KB |
Output is correct |
16 |
Correct |
387 ms |
45424 KB |
Output is correct |
17 |
Correct |
313 ms |
42916 KB |
Output is correct |
18 |
Correct |
196 ms |
38244 KB |
Output is correct |
19 |
Correct |
481 ms |
46588 KB |
Output is correct |
20 |
Correct |
474 ms |
46448 KB |
Output is correct |
21 |
Correct |
461 ms |
43480 KB |
Output is correct |
22 |
Correct |
267 ms |
42892 KB |
Output is correct |
23 |
Correct |
334 ms |
45868 KB |
Output is correct |
24 |
Correct |
183 ms |
41808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
12 ms |
7632 KB |
Output is correct |
8 |
Correct |
12 ms |
7504 KB |
Output is correct |
9 |
Correct |
12 ms |
7496 KB |
Output is correct |
10 |
Correct |
11 ms |
7500 KB |
Output is correct |
11 |
Correct |
9 ms |
7504 KB |
Output is correct |
12 |
Correct |
7 ms |
7468 KB |
Output is correct |
13 |
Correct |
13 ms |
7632 KB |
Output is correct |
14 |
Correct |
13 ms |
7500 KB |
Output is correct |
15 |
Correct |
17 ms |
7572 KB |
Output is correct |
16 |
Correct |
10 ms |
7504 KB |
Output is correct |
17 |
Correct |
10 ms |
7504 KB |
Output is correct |
18 |
Correct |
5 ms |
7368 KB |
Output is correct |
19 |
Correct |
480 ms |
45152 KB |
Output is correct |
20 |
Correct |
482 ms |
43860 KB |
Output is correct |
21 |
Correct |
461 ms |
42396 KB |
Output is correct |
22 |
Correct |
403 ms |
42404 KB |
Output is correct |
23 |
Correct |
300 ms |
39764 KB |
Output is correct |
24 |
Correct |
236 ms |
39016 KB |
Output is correct |
25 |
Correct |
425 ms |
43992 KB |
Output is correct |
26 |
Correct |
452 ms |
43656 KB |
Output is correct |
27 |
Correct |
462 ms |
43372 KB |
Output is correct |
28 |
Correct |
250 ms |
41576 KB |
Output is correct |
29 |
Correct |
338 ms |
41884 KB |
Output is correct |
30 |
Correct |
200 ms |
42276 KB |
Output is correct |
31 |
Correct |
476 ms |
44480 KB |
Output is correct |
32 |
Correct |
492 ms |
43788 KB |
Output is correct |
33 |
Correct |
483 ms |
44004 KB |
Output is correct |
34 |
Correct |
387 ms |
45424 KB |
Output is correct |
35 |
Correct |
313 ms |
42916 KB |
Output is correct |
36 |
Correct |
196 ms |
38244 KB |
Output is correct |
37 |
Correct |
481 ms |
46588 KB |
Output is correct |
38 |
Correct |
474 ms |
46448 KB |
Output is correct |
39 |
Correct |
461 ms |
43480 KB |
Output is correct |
40 |
Correct |
267 ms |
42892 KB |
Output is correct |
41 |
Correct |
334 ms |
45868 KB |
Output is correct |
42 |
Correct |
183 ms |
41808 KB |
Output is correct |
43 |
Correct |
504 ms |
45360 KB |
Output is correct |
44 |
Correct |
489 ms |
44860 KB |
Output is correct |
45 |
Correct |
518 ms |
47684 KB |
Output is correct |
46 |
Correct |
429 ms |
44108 KB |
Output is correct |
47 |
Correct |
332 ms |
43964 KB |
Output is correct |
48 |
Correct |
208 ms |
40672 KB |
Output is correct |
49 |
Correct |
509 ms |
46676 KB |
Output is correct |
50 |
Correct |
489 ms |
44904 KB |
Output is correct |
51 |
Correct |
481 ms |
45804 KB |
Output is correct |
52 |
Correct |
318 ms |
42932 KB |
Output is correct |
53 |
Correct |
347 ms |
45044 KB |
Output is correct |