#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define maxn 200009
#define fi first
#define se second
#define pb push_back
#define left id<<1
#define right id<<1|1
#define re exit(0);
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1
const int mod = 1e9+7 ;
const int INF = 1e9 ;
const int LOG = 18 ;
typedef vector<int> vi ;
typedef pair<int,int> pii ;
typedef vector<ll> vl ;
typedef vector<pii> vii ;
void add ( int &a , int b )
{
a += b ;
if ( a < 0 ) a += mod ;
if ( a >= mod ) a -= mod ;
}
template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; }
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; }
void rf ()
{
freopen ("bai1.inp","r",stdin) ;
// freopen ("bai1.out","w",stdout) ;
}
int _pow ( int a , int n )
{
if ( n == 0 ) return 1 ;
int res = _pow (a,n/2) ;
if ( n % 2 ) return 1ll*res*res%mod*a%mod ;
else return 1ll*res*res%mod ;
}
int n , nq ;
struct score {
int math , info , sum , id ;
} a [maxn] , q [maxn] , b [maxn] ;
int res [maxn] ;
bool cmp_math ( score u , score v )
{
if (u.math == v.math)
{
return u.id < v.id ;
}
return u.math >= v.math ;
}
bool cmp_info ( score u , score v )
{
if ( u.info == v.info )
{
return u.id < v.id ;
}
return u.info >= v.info ;
}
int num ;
int bit [maxn] ;
void update ( int x , int y )
{
while ( x ) bit [x] += y , x -= (x&-x) ;
}
int get ( int x )
{
int res = 0 ;
while ( x < maxn ) res += bit [x] , x += (x&-x) ;
return res ;
}
void dnc ( int l , int r )
{
if ( l == r ) return ;
int mid = (l+r)/2 ;
dnc (l,mid) ;
dnc (mid+1,r) ;
vector<score> impor ;
for ( int i = l ; i <= mid ; i ++ ) if ( b [i].id == - 1 ) impor.pb (b[i]) ;
for ( int i = mid + 1 ; i <= r ; i ++ ) if ( b[i].id != - 1 ) impor.pb (b[i]) ;
sort (impor.begin(),impor.end(),cmp_info) ;
for ( auto x : impor )
{
int info = x.info , sum = x.sum , id = x.id ;
if ( id == - 1 ) update (sum,1) ;
else res [id] += get (sum) ;
}
for ( auto x : impor ) if ( x.id == - 1 ) update (x.sum,-1) ;
}
void mapping ()
{
vi v ;
for ( int i = 1 ; i <= n ; i ++ ) v . pb (a[i].sum) ;
for ( int i = 1 ; i <= nq ; i ++ ) v . pb (q[i].sum) ;
sort (v.begin(),v.end()) ;
v.resize(unique(v.begin(),v.end())-v.begin()) ;
for ( int i = 1 ; i <= n ; i ++ ) a [i].sum = _lower(a[i].sum) ;
for ( int i = 1 ; i <= nq ; i ++ ) q [i].sum = _lower(q[i].sum) ;
}
int main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0) ;
// rf () ;
cin >> n >> nq ;
for ( int i = 1 ; i <= n ; i ++ )
{
cin >> a [i].math >> a [i].info ; a [i].sum = a [i].math + a [i].info ;
}
for ( int i = 1 ; i <= nq ; i ++ )
{
cin >> q [i].math >> q [i].info >> q [i].sum ;
}
mapping () ;
int num = 0 ;
for ( int i = 1 ; i <= n ; i ++ ) a [i].id = - 1 , b [++num] = a [i] ;
for ( int i = 1 ; i <= nq ; i ++ ) q [i].id = i , b [++num] = q [i] ;
sort (b+1,b+num+1,cmp_math) ;
dnc (1,num) ;
for ( int i = 1 ; i <= nq ; i ++ ) cout << res [i] << "\n" ;
}
// range , error , check speical , ...
// find key , find key
//'-std=c++11' stay hard
// there is no tomorrow
Compilation message
examination.cpp: In function 'void dnc(int, int)':
examination.cpp:99:7: warning: unused variable 'info' [-Wunused-variable]
99 | int info = x.info , sum = x.sum , id = x.id ;
| ^~~~
examination.cpp: In function 'void rf()':
examination.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen ("bai1.inp","r",stdin) ;
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6608 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
7 ms |
6748 KB |
Output is correct |
8 |
Correct |
7 ms |
6748 KB |
Output is correct |
9 |
Correct |
7 ms |
6748 KB |
Output is correct |
10 |
Correct |
6 ms |
6748 KB |
Output is correct |
11 |
Correct |
6 ms |
6748 KB |
Output is correct |
12 |
Correct |
5 ms |
6628 KB |
Output is correct |
13 |
Correct |
6 ms |
6744 KB |
Output is correct |
14 |
Correct |
6 ms |
6812 KB |
Output is correct |
15 |
Correct |
6 ms |
6748 KB |
Output is correct |
16 |
Correct |
6 ms |
6748 KB |
Output is correct |
17 |
Correct |
6 ms |
6748 KB |
Output is correct |
18 |
Correct |
4 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
239 ms |
16256 KB |
Output is correct |
2 |
Correct |
236 ms |
16440 KB |
Output is correct |
3 |
Correct |
240 ms |
16272 KB |
Output is correct |
4 |
Correct |
224 ms |
15508 KB |
Output is correct |
5 |
Correct |
208 ms |
15624 KB |
Output is correct |
6 |
Correct |
177 ms |
14704 KB |
Output is correct |
7 |
Correct |
231 ms |
18160 KB |
Output is correct |
8 |
Correct |
232 ms |
16348 KB |
Output is correct |
9 |
Correct |
228 ms |
18668 KB |
Output is correct |
10 |
Correct |
199 ms |
16196 KB |
Output is correct |
11 |
Correct |
206 ms |
15848 KB |
Output is correct |
12 |
Correct |
129 ms |
14760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
239 ms |
16256 KB |
Output is correct |
2 |
Correct |
236 ms |
16440 KB |
Output is correct |
3 |
Correct |
240 ms |
16272 KB |
Output is correct |
4 |
Correct |
224 ms |
15508 KB |
Output is correct |
5 |
Correct |
208 ms |
15624 KB |
Output is correct |
6 |
Correct |
177 ms |
14704 KB |
Output is correct |
7 |
Correct |
231 ms |
18160 KB |
Output is correct |
8 |
Correct |
232 ms |
16348 KB |
Output is correct |
9 |
Correct |
228 ms |
18668 KB |
Output is correct |
10 |
Correct |
199 ms |
16196 KB |
Output is correct |
11 |
Correct |
206 ms |
15848 KB |
Output is correct |
12 |
Correct |
129 ms |
14760 KB |
Output is correct |
13 |
Correct |
260 ms |
16800 KB |
Output is correct |
14 |
Correct |
260 ms |
16876 KB |
Output is correct |
15 |
Correct |
236 ms |
16264 KB |
Output is correct |
16 |
Correct |
245 ms |
16012 KB |
Output is correct |
17 |
Correct |
230 ms |
16016 KB |
Output is correct |
18 |
Correct |
176 ms |
14732 KB |
Output is correct |
19 |
Correct |
261 ms |
16860 KB |
Output is correct |
20 |
Correct |
258 ms |
16768 KB |
Output is correct |
21 |
Correct |
260 ms |
21136 KB |
Output is correct |
22 |
Correct |
198 ms |
16184 KB |
Output is correct |
23 |
Correct |
201 ms |
15700 KB |
Output is correct |
24 |
Correct |
141 ms |
14748 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 |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6608 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
7 ms |
6748 KB |
Output is correct |
8 |
Correct |
7 ms |
6748 KB |
Output is correct |
9 |
Correct |
7 ms |
6748 KB |
Output is correct |
10 |
Correct |
6 ms |
6748 KB |
Output is correct |
11 |
Correct |
6 ms |
6748 KB |
Output is correct |
12 |
Correct |
5 ms |
6628 KB |
Output is correct |
13 |
Correct |
6 ms |
6744 KB |
Output is correct |
14 |
Correct |
6 ms |
6812 KB |
Output is correct |
15 |
Correct |
6 ms |
6748 KB |
Output is correct |
16 |
Correct |
6 ms |
6748 KB |
Output is correct |
17 |
Correct |
6 ms |
6748 KB |
Output is correct |
18 |
Correct |
4 ms |
6748 KB |
Output is correct |
19 |
Correct |
239 ms |
16256 KB |
Output is correct |
20 |
Correct |
236 ms |
16440 KB |
Output is correct |
21 |
Correct |
240 ms |
16272 KB |
Output is correct |
22 |
Correct |
224 ms |
15508 KB |
Output is correct |
23 |
Correct |
208 ms |
15624 KB |
Output is correct |
24 |
Correct |
177 ms |
14704 KB |
Output is correct |
25 |
Correct |
231 ms |
18160 KB |
Output is correct |
26 |
Correct |
232 ms |
16348 KB |
Output is correct |
27 |
Correct |
228 ms |
18668 KB |
Output is correct |
28 |
Correct |
199 ms |
16196 KB |
Output is correct |
29 |
Correct |
206 ms |
15848 KB |
Output is correct |
30 |
Correct |
129 ms |
14760 KB |
Output is correct |
31 |
Correct |
260 ms |
16800 KB |
Output is correct |
32 |
Correct |
260 ms |
16876 KB |
Output is correct |
33 |
Correct |
236 ms |
16264 KB |
Output is correct |
34 |
Correct |
245 ms |
16012 KB |
Output is correct |
35 |
Correct |
230 ms |
16016 KB |
Output is correct |
36 |
Correct |
176 ms |
14732 KB |
Output is correct |
37 |
Correct |
261 ms |
16860 KB |
Output is correct |
38 |
Correct |
258 ms |
16768 KB |
Output is correct |
39 |
Correct |
260 ms |
21136 KB |
Output is correct |
40 |
Correct |
198 ms |
16184 KB |
Output is correct |
41 |
Correct |
201 ms |
15700 KB |
Output is correct |
42 |
Correct |
141 ms |
14748 KB |
Output is correct |
43 |
Correct |
269 ms |
18828 KB |
Output is correct |
44 |
Correct |
284 ms |
19088 KB |
Output is correct |
45 |
Correct |
266 ms |
18544 KB |
Output is correct |
46 |
Correct |
270 ms |
17268 KB |
Output is correct |
47 |
Correct |
238 ms |
17032 KB |
Output is correct |
48 |
Correct |
182 ms |
14796 KB |
Output is correct |
49 |
Correct |
268 ms |
19872 KB |
Output is correct |
50 |
Correct |
259 ms |
18712 KB |
Output is correct |
51 |
Correct |
259 ms |
20968 KB |
Output is correct |
52 |
Correct |
228 ms |
17696 KB |
Output is correct |
53 |
Correct |
208 ms |
16276 KB |
Output is correct |