#include<bits/stdc++.h>
/*
#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 ll = long long ;
using ld = long double ;
const int N = 1e5 + 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()) ;
}
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){
aux.push_back( v[i].second) ;
}
else{
int ret = 0 ;
for(auto u : aux){
int fr = v[i].second.first ;
int se = v[i].second.second ;
ret += (fr <= u.first && se <= u.second) ;
}
ans[v[i].first.second] = ret ;
}
}
for(int i = 0 ;i < k ; ++ i)
cout<< ans[i] <<"\n" ;
return 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
10 ms |
896 KB |
Output is correct |
8 |
Correct |
10 ms |
896 KB |
Output is correct |
9 |
Correct |
10 ms |
896 KB |
Output is correct |
10 |
Correct |
9 ms |
896 KB |
Output is correct |
11 |
Correct |
10 ms |
896 KB |
Output is correct |
12 |
Correct |
8 ms |
768 KB |
Output is correct |
13 |
Correct |
15 ms |
896 KB |
Output is correct |
14 |
Correct |
14 ms |
896 KB |
Output is correct |
15 |
Correct |
15 ms |
896 KB |
Output is correct |
16 |
Correct |
13 ms |
896 KB |
Output is correct |
17 |
Correct |
9 ms |
896 KB |
Output is correct |
18 |
Correct |
5 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3071 ms |
12148 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3071 ms |
12148 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
10 ms |
896 KB |
Output is correct |
8 |
Correct |
10 ms |
896 KB |
Output is correct |
9 |
Correct |
10 ms |
896 KB |
Output is correct |
10 |
Correct |
9 ms |
896 KB |
Output is correct |
11 |
Correct |
10 ms |
896 KB |
Output is correct |
12 |
Correct |
8 ms |
768 KB |
Output is correct |
13 |
Correct |
15 ms |
896 KB |
Output is correct |
14 |
Correct |
14 ms |
896 KB |
Output is correct |
15 |
Correct |
15 ms |
896 KB |
Output is correct |
16 |
Correct |
13 ms |
896 KB |
Output is correct |
17 |
Correct |
9 ms |
896 KB |
Output is correct |
18 |
Correct |
5 ms |
768 KB |
Output is correct |
19 |
Execution timed out |
3071 ms |
12148 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |