#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n , q , MAX_S , MAX_T;
vector<int> S(N) , T(N) , X(N) , Y(N) , Z(N) , ans(N);
vector<pair<int , int>> _S , _T;
vector<tuple<int , int , int>> v;
struct node{
node *left , *right;
int sum = 0;
node(int sum = 0) : left(NULL) , right(NULL) , sum(sum) {}
} *t[4 * N];
void UPD(node *&u , int l , int r , int pos , int x){
if(!u){
u = new node();
}
if(l == r){
u->sum += x;
return;
}
int m = (l + r) / 2;
if(pos <= m){
UPD(u->left , l , m , pos , x);
}else{
UPD(u->right , m + 1 , r , pos , x);
}
u->sum = 0;
if(u->left){
u->sum += u->left->sum;
}
if(u->right){
u->sum += u->right->sum;
}
}
int GET(node *&u , int l , int r , int L , int R){
if(l > r || r < L || l > R || u == NULL){
return 0;
}
if(L <= l && r <= R){
return u->sum;
}
int m = (l + r) / 2;
return GET(u->left , l , m , L , R) + GET(u->right , m + 1 , r , L , R);
}
void update(int u , int l , int r , int pos , int t_pos){
if(l == r){
UPD(t[u] , 1 , MAX_T , t_pos , 1);
return;
}
int m = (l + r) / 2;
if(pos <= m){
update(u * 2 , l , m , pos , t_pos);
}else{
update(u * 2 + 1 , m + 1 , r , pos , t_pos);
}
UPD(t[u] , 1 , MAX_T , t_pos , 1);
}
int get(int u , int l , int r , int L , int R , int t_L , int t_R){
if(l > r || r < L || l > R){
return 0;
}
if(L <= l && r <= R){
return GET(t[u] , 1 , MAX_T , t_L , t_R);
}
int m = (l + r) / 2;
return get(u * 2 , l , m , L , R , t_L , t_R) + get(u * 2 + 1 , m + 1 , r , L , R , t_L , t_R);
}
int main(){
cin >> n >> q;
for(int i = 1;i <= n;i ++){
cin >> S[i] >> T[i];
v.push_back({S[i] + T[i] , 1 , i});
_S.push_back({S[i] , i});
_T.push_back({T[i] , i});
}
for(int i = 1;i <= q;i ++){
cin >> X[i] >> Y[i] >> Z[i];
v.push_back({Z[i] , 0 , i});
_S.push_back({X[i] , -i});
_T.push_back({Y[i] , -i});
}
sort(_S.begin() , _S.end());
sort(_T.begin() , _T.end());
for(int i = 0;i < (int)_S.size();i ++){
int lst = (i > 0 ? _S[i - 1].second > 0 ? S[_S[i - 1].second] : X[-_S[i - 1].second] : 1);
if(_S[i].second > 0){
S[_S[i].second] = lst + (i > 0 ? (_S[i].first > _S[i - 1].first) : 0);
}else{
X[-_S[i].second] = lst + (i > 0 ? (_S[i].first > _S[i - 1].first) : 0);
}
}
for(int i = 0;i < (int)_T.size();i ++){
int lst = (i > 0 ? _T[i - 1].second > 0 ? T[_T[i - 1].second] : Y[-_T[i - 1].second] : 1);
if(_T[i].second > 0){
T[_T[i].second] = lst + (i > 0 ? (_T[i].first > _T[i - 1].first) : 0);
}else{
Y[-_T[i].second] = lst + (i > 0 ? (_T[i].first > _T[i - 1].first) : 0);
}
}
MAX_S = max(*max_element(S.begin() , S.end()) , *max_element(X.begin() , X.end()));
MAX_T = max(*max_element(T.begin() , T.end()) , *max_element(Y.begin() , Y.end()));
sort(v.rbegin() , v.rend());
for(auto [value , type , id] : v){
if(type > 0){
update(1 , 1 , MAX_S , S[id] , T[id]);
}else{
ans[id] = get(1 , 1 , MAX_S , X[id] , MAX_S , Y[id] , MAX_T);
}
}
for(int i = 1;i <= q;i ++){
cout << ans[i] << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
21 ms |
16240 KB |
Output is correct |
8 |
Correct |
22 ms |
16220 KB |
Output is correct |
9 |
Correct |
25 ms |
16220 KB |
Output is correct |
10 |
Correct |
10 ms |
7224 KB |
Output is correct |
11 |
Correct |
11 ms |
7004 KB |
Output is correct |
12 |
Correct |
7 ms |
5212 KB |
Output is correct |
13 |
Correct |
23 ms |
16144 KB |
Output is correct |
14 |
Correct |
23 ms |
16220 KB |
Output is correct |
15 |
Correct |
27 ms |
16064 KB |
Output is correct |
16 |
Correct |
9 ms |
5724 KB |
Output is correct |
17 |
Correct |
9 ms |
5980 KB |
Output is correct |
18 |
Correct |
6 ms |
5468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1230 ms |
516204 KB |
Output is correct |
2 |
Correct |
1343 ms |
515868 KB |
Output is correct |
3 |
Correct |
1288 ms |
515944 KB |
Output is correct |
4 |
Correct |
289 ms |
54628 KB |
Output is correct |
5 |
Correct |
296 ms |
52588 KB |
Output is correct |
6 |
Correct |
179 ms |
11500 KB |
Output is correct |
7 |
Correct |
1099 ms |
493456 KB |
Output is correct |
8 |
Correct |
1091 ms |
493716 KB |
Output is correct |
9 |
Correct |
1010 ms |
471892 KB |
Output is correct |
10 |
Correct |
203 ms |
20076 KB |
Output is correct |
11 |
Correct |
211 ms |
22080 KB |
Output is correct |
12 |
Correct |
180 ms |
11116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1230 ms |
516204 KB |
Output is correct |
2 |
Correct |
1343 ms |
515868 KB |
Output is correct |
3 |
Correct |
1288 ms |
515944 KB |
Output is correct |
4 |
Correct |
289 ms |
54628 KB |
Output is correct |
5 |
Correct |
296 ms |
52588 KB |
Output is correct |
6 |
Correct |
179 ms |
11500 KB |
Output is correct |
7 |
Correct |
1099 ms |
493456 KB |
Output is correct |
8 |
Correct |
1091 ms |
493716 KB |
Output is correct |
9 |
Correct |
1010 ms |
471892 KB |
Output is correct |
10 |
Correct |
203 ms |
20076 KB |
Output is correct |
11 |
Correct |
211 ms |
22080 KB |
Output is correct |
12 |
Correct |
180 ms |
11116 KB |
Output is correct |
13 |
Correct |
1170 ms |
516500 KB |
Output is correct |
14 |
Correct |
1253 ms |
516200 KB |
Output is correct |
15 |
Correct |
1232 ms |
515944 KB |
Output is correct |
16 |
Correct |
280 ms |
54632 KB |
Output is correct |
17 |
Correct |
287 ms |
52548 KB |
Output is correct |
18 |
Correct |
184 ms |
11572 KB |
Output is correct |
19 |
Correct |
1145 ms |
516444 KB |
Output is correct |
20 |
Correct |
1209 ms |
515948 KB |
Output is correct |
21 |
Correct |
1018 ms |
499564 KB |
Output is correct |
22 |
Correct |
206 ms |
20020 KB |
Output is correct |
23 |
Correct |
227 ms |
22892 KB |
Output is correct |
24 |
Correct |
194 ms |
11116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
21 ms |
16240 KB |
Output is correct |
8 |
Correct |
22 ms |
16220 KB |
Output is correct |
9 |
Correct |
25 ms |
16220 KB |
Output is correct |
10 |
Correct |
10 ms |
7224 KB |
Output is correct |
11 |
Correct |
11 ms |
7004 KB |
Output is correct |
12 |
Correct |
7 ms |
5212 KB |
Output is correct |
13 |
Correct |
23 ms |
16144 KB |
Output is correct |
14 |
Correct |
23 ms |
16220 KB |
Output is correct |
15 |
Correct |
27 ms |
16064 KB |
Output is correct |
16 |
Correct |
9 ms |
5724 KB |
Output is correct |
17 |
Correct |
9 ms |
5980 KB |
Output is correct |
18 |
Correct |
6 ms |
5468 KB |
Output is correct |
19 |
Correct |
1230 ms |
516204 KB |
Output is correct |
20 |
Correct |
1343 ms |
515868 KB |
Output is correct |
21 |
Correct |
1288 ms |
515944 KB |
Output is correct |
22 |
Correct |
289 ms |
54628 KB |
Output is correct |
23 |
Correct |
296 ms |
52588 KB |
Output is correct |
24 |
Correct |
179 ms |
11500 KB |
Output is correct |
25 |
Correct |
1099 ms |
493456 KB |
Output is correct |
26 |
Correct |
1091 ms |
493716 KB |
Output is correct |
27 |
Correct |
1010 ms |
471892 KB |
Output is correct |
28 |
Correct |
203 ms |
20076 KB |
Output is correct |
29 |
Correct |
211 ms |
22080 KB |
Output is correct |
30 |
Correct |
180 ms |
11116 KB |
Output is correct |
31 |
Correct |
1170 ms |
516500 KB |
Output is correct |
32 |
Correct |
1253 ms |
516200 KB |
Output is correct |
33 |
Correct |
1232 ms |
515944 KB |
Output is correct |
34 |
Correct |
280 ms |
54632 KB |
Output is correct |
35 |
Correct |
287 ms |
52548 KB |
Output is correct |
36 |
Correct |
184 ms |
11572 KB |
Output is correct |
37 |
Correct |
1145 ms |
516444 KB |
Output is correct |
38 |
Correct |
1209 ms |
515948 KB |
Output is correct |
39 |
Correct |
1018 ms |
499564 KB |
Output is correct |
40 |
Correct |
206 ms |
20020 KB |
Output is correct |
41 |
Correct |
227 ms |
22892 KB |
Output is correct |
42 |
Correct |
194 ms |
11116 KB |
Output is correct |
43 |
Correct |
1465 ms |
657776 KB |
Output is correct |
44 |
Correct |
1309 ms |
662412 KB |
Output is correct |
45 |
Correct |
1444 ms |
662056 KB |
Output is correct |
46 |
Correct |
319 ms |
78408 KB |
Output is correct |
47 |
Correct |
319 ms |
74220 KB |
Output is correct |
48 |
Correct |
182 ms |
12360 KB |
Output is correct |
49 |
Correct |
1287 ms |
631260 KB |
Output is correct |
50 |
Correct |
1194 ms |
631472 KB |
Output is correct |
51 |
Correct |
1156 ms |
600028 KB |
Output is correct |
52 |
Correct |
233 ms |
31352 KB |
Output is correct |
53 |
Correct |
234 ms |
34760 KB |
Output is correct |