#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
/*
#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")*/
#define I inline void
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pii pair<int,int>
#define pll pair<ll,ll>
using namespace std ;
using namespace __gnu_pbds;
typedef tree<pii, null_type , less<pii> , rb_tree_tag , tree_order_statistics_node_update> indexed_set ;
using ll = long long ;
using ld = long double ;
const int N = 2e5 + 7 , mod = 1e9 + 7 ;
const int inf = N ;
// How interesting!
int n , k;
vector< pair<pii , pii> > v ;
int ans[N] ;
int A[N] , B[N] , S[N] ;
int qA[N] , qB[N] , qS[N] ;
vector<int> v1 , v2 ;
void cmp(vector<int> &x){
sort(x.begin() , x.end()) ;
x.erase(unique(x.begin() , x.end()) , x.end()) ;
}
indexed_set mst[N] ;
int t = 0 ;
void add(int x , int y){
for(;x < N ; x += x&-x)
mst[x].insert({y , ++ t}) ;
}
int upto(int x , int y){
int ret = 0 ;
for(;x;x-=x&-x){
int j = mst[x].order_of_key({y , -1}) ;
ret += (int) mst[x].size() - j ;
}
return ret ;
}
int get(int l ,int r , int x){
return upto(r , x) - upto(l - 1 ,x) ;
}
int main(){
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
//freopen("in.in" , "r" , stdin) ;
cin >> n >> k ;
for(int i = 0 ;i < n;i ++ ){
cin >> A[i] >> B[i] ;
S[i] = A[i] + B[i] ;
v1.push_back(A[i]) ;
v2.push_back(B[i]) ;
}
for(int i = 0 ;i < k ;i ++){
cin >> qA[i] >> qB[i] >> qS[i] ;
v1.push_back(qA[i]) ;
v2.push_back(qB[i]) ;
}
cmp(v1) ;
cmp(v2) ;
for(int i = 0 ;i < n;i ++){
A[i] = lower_bound(v1.begin() , v1.end() , A[i]) - v1.begin() + 1 ;
B[i] = lower_bound(v2.begin() , v2.end() , B[i]) - v2.begin() + 1 ;
}
for(int i = 0 ;i < k ; ++ i){
qA[i] = lower_bound(v1.begin() , v1.end() , qA[i]) - v1.begin() + 1 ;
qB[i] = lower_bound(v2.begin() , v2.end() , qB[i]) - v2.begin() + 1 ;
}
for(int i = 0 ;i < n;i ++ ){
v.push_back({{-S[i] , - 1 } , {A[i] , B[i]} }) ;
}
for(int i = 0 ;i < k; ++ i){
v.push_back({{-qS[i] , i } , {qA[i] , qB[i]} }) ;
}
sort(v.begin() , v.end()) ;
vector< pii> aux ;
for(int i = 0 ;i < n + k ; ++ i){
if(v[i].first.second < 0){
assert(v[i].second.first && v[i].second.second) ;
add(v[i].second.first , v[i].second.second) ;
}
else{
int ret = get(v[i].second.first , N - 1 , v[i].second.second) ;
ans[v[i].first.second] = ret ;
}
}
for(int i = 0 ;i < k ; ++ i)
cout<< ans[i] <<"\n" ;
return 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
19200 KB |
Output is correct |
2 |
Correct |
20 ms |
19200 KB |
Output is correct |
3 |
Correct |
19 ms |
19200 KB |
Output is correct |
4 |
Correct |
19 ms |
19200 KB |
Output is correct |
5 |
Correct |
21 ms |
19200 KB |
Output is correct |
6 |
Correct |
19 ms |
19200 KB |
Output is correct |
7 |
Correct |
40 ms |
21624 KB |
Output is correct |
8 |
Correct |
40 ms |
21676 KB |
Output is correct |
9 |
Correct |
42 ms |
21752 KB |
Output is correct |
10 |
Correct |
42 ms |
21632 KB |
Output is correct |
11 |
Correct |
48 ms |
22564 KB |
Output is correct |
12 |
Correct |
45 ms |
22520 KB |
Output is correct |
13 |
Correct |
41 ms |
21632 KB |
Output is correct |
14 |
Correct |
42 ms |
21624 KB |
Output is correct |
15 |
Correct |
43 ms |
21632 KB |
Output is correct |
16 |
Correct |
53 ms |
22776 KB |
Output is correct |
17 |
Correct |
40 ms |
21604 KB |
Output is correct |
18 |
Correct |
53 ms |
22776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1906 ms |
89904 KB |
Output is correct |
2 |
Correct |
1872 ms |
90040 KB |
Output is correct |
3 |
Correct |
1896 ms |
89816 KB |
Output is correct |
4 |
Correct |
1247 ms |
90196 KB |
Output is correct |
5 |
Correct |
1318 ms |
130268 KB |
Output is correct |
6 |
Correct |
1207 ms |
130348 KB |
Output is correct |
7 |
Correct |
1449 ms |
89600 KB |
Output is correct |
8 |
Correct |
1821 ms |
89984 KB |
Output is correct |
9 |
Correct |
1396 ms |
89684 KB |
Output is correct |
10 |
Correct |
1289 ms |
139732 KB |
Output is correct |
11 |
Correct |
983 ms |
89632 KB |
Output is correct |
12 |
Correct |
1855 ms |
139564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1906 ms |
89904 KB |
Output is correct |
2 |
Correct |
1872 ms |
90040 KB |
Output is correct |
3 |
Correct |
1896 ms |
89816 KB |
Output is correct |
4 |
Correct |
1247 ms |
90196 KB |
Output is correct |
5 |
Correct |
1318 ms |
130268 KB |
Output is correct |
6 |
Correct |
1207 ms |
130348 KB |
Output is correct |
7 |
Correct |
1449 ms |
89600 KB |
Output is correct |
8 |
Correct |
1821 ms |
89984 KB |
Output is correct |
9 |
Correct |
1396 ms |
89684 KB |
Output is correct |
10 |
Correct |
1289 ms |
139732 KB |
Output is correct |
11 |
Correct |
983 ms |
89632 KB |
Output is correct |
12 |
Correct |
1855 ms |
139564 KB |
Output is correct |
13 |
Correct |
1616 ms |
89788 KB |
Output is correct |
14 |
Correct |
1877 ms |
89972 KB |
Output is correct |
15 |
Correct |
1913 ms |
90144 KB |
Output is correct |
16 |
Correct |
986 ms |
90020 KB |
Output is correct |
17 |
Correct |
1256 ms |
130276 KB |
Output is correct |
18 |
Correct |
1189 ms |
130280 KB |
Output is correct |
19 |
Correct |
1584 ms |
89816 KB |
Output is correct |
20 |
Correct |
1748 ms |
89812 KB |
Output is correct |
21 |
Correct |
1413 ms |
89752 KB |
Output is correct |
22 |
Correct |
1251 ms |
139740 KB |
Output is correct |
23 |
Correct |
971 ms |
89836 KB |
Output is correct |
24 |
Correct |
1770 ms |
139736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
19200 KB |
Output is correct |
2 |
Correct |
20 ms |
19200 KB |
Output is correct |
3 |
Correct |
19 ms |
19200 KB |
Output is correct |
4 |
Correct |
19 ms |
19200 KB |
Output is correct |
5 |
Correct |
21 ms |
19200 KB |
Output is correct |
6 |
Correct |
19 ms |
19200 KB |
Output is correct |
7 |
Correct |
40 ms |
21624 KB |
Output is correct |
8 |
Correct |
40 ms |
21676 KB |
Output is correct |
9 |
Correct |
42 ms |
21752 KB |
Output is correct |
10 |
Correct |
42 ms |
21632 KB |
Output is correct |
11 |
Correct |
48 ms |
22564 KB |
Output is correct |
12 |
Correct |
45 ms |
22520 KB |
Output is correct |
13 |
Correct |
41 ms |
21632 KB |
Output is correct |
14 |
Correct |
42 ms |
21624 KB |
Output is correct |
15 |
Correct |
43 ms |
21632 KB |
Output is correct |
16 |
Correct |
53 ms |
22776 KB |
Output is correct |
17 |
Correct |
40 ms |
21604 KB |
Output is correct |
18 |
Correct |
53 ms |
22776 KB |
Output is correct |
19 |
Correct |
1906 ms |
89904 KB |
Output is correct |
20 |
Correct |
1872 ms |
90040 KB |
Output is correct |
21 |
Correct |
1896 ms |
89816 KB |
Output is correct |
22 |
Correct |
1247 ms |
90196 KB |
Output is correct |
23 |
Correct |
1318 ms |
130268 KB |
Output is correct |
24 |
Correct |
1207 ms |
130348 KB |
Output is correct |
25 |
Correct |
1449 ms |
89600 KB |
Output is correct |
26 |
Correct |
1821 ms |
89984 KB |
Output is correct |
27 |
Correct |
1396 ms |
89684 KB |
Output is correct |
28 |
Correct |
1289 ms |
139732 KB |
Output is correct |
29 |
Correct |
983 ms |
89632 KB |
Output is correct |
30 |
Correct |
1855 ms |
139564 KB |
Output is correct |
31 |
Correct |
1616 ms |
89788 KB |
Output is correct |
32 |
Correct |
1877 ms |
89972 KB |
Output is correct |
33 |
Correct |
1913 ms |
90144 KB |
Output is correct |
34 |
Correct |
986 ms |
90020 KB |
Output is correct |
35 |
Correct |
1256 ms |
130276 KB |
Output is correct |
36 |
Correct |
1189 ms |
130280 KB |
Output is correct |
37 |
Correct |
1584 ms |
89816 KB |
Output is correct |
38 |
Correct |
1748 ms |
89812 KB |
Output is correct |
39 |
Correct |
1413 ms |
89752 KB |
Output is correct |
40 |
Correct |
1251 ms |
139740 KB |
Output is correct |
41 |
Correct |
971 ms |
89836 KB |
Output is correct |
42 |
Correct |
1770 ms |
139736 KB |
Output is correct |
43 |
Correct |
1638 ms |
85368 KB |
Output is correct |
44 |
Correct |
1622 ms |
90520 KB |
Output is correct |
45 |
Correct |
1929 ms |
90324 KB |
Output is correct |
46 |
Correct |
1002 ms |
88700 KB |
Output is correct |
47 |
Correct |
1275 ms |
133588 KB |
Output is correct |
48 |
Correct |
1109 ms |
131288 KB |
Output is correct |
49 |
Correct |
1512 ms |
87000 KB |
Output is correct |
50 |
Correct |
1382 ms |
90204 KB |
Output is correct |
51 |
Correct |
1219 ms |
87000 KB |
Output is correct |
52 |
Correct |
1922 ms |
143180 KB |
Output is correct |
53 |
Correct |
974 ms |
87836 KB |
Output is correct |