#include <bits/stdc++.h>
#define debug printf
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x.size() )
#define ll long long
const int MAXN = 2e5+10 ;
using namespace std ;
struct SparseSeg
{
vector< int > _sum, e , d ;
int create()
{
_sum.push_back(0) ;
e.push_back(0) ;
d.push_back(0) ;
return sz(e)-1 ;
}
int m(int l, int r) { return (l+r)>>1 ; }
void upd(int pos, int l, int r, int idx )
{
_sum[pos]++ ;
if( l == r ) return ;
int aux ;
if( idx <= m(l,r) )
{
if(e[pos] == 0 ) { aux = create() ; e[pos] = aux ; }
upd(e[pos] , l ,m(l,r), idx ) ;
}
else
{
if(d[pos] == 0 ) { aux = create() ; d[pos] = aux ; }
upd(d[pos] , m(l,r)+1, r, idx ) ;
}
}
int qry(int pos, int l, int r, int bValue )
{
if( r < bValue || !pos ) return 0 ;
if( l >= bValue ) return _sum[pos] ;
int al = qry(e[pos] , l , m(l,r) , bValue ) ;
int ar = qry(d[pos] , m(l,r) + 1 , r , bValue ) ;
return al + ar ;
}
} ;
int N , Q , keyA, keyB ;
vector<int> compressA, compressB ;
SparseSeg bit[MAXN] ;
void upd(int aValue, int bValue )
{
for(; aValue <= keyA ; aValue += aValue & -aValue)
bit[aValue].upd(1,1,keyB, bValue ) ;
}
int qry(int aValue, int bValue )
{
int tot = 0 ;
for(; aValue > 0 ; aValue -= aValue & -aValue )
tot += bit[aValue].qry(1,1,keyB, bValue ) ;
return tot ;
}
int main()
{
scanf("%d %d", &N, &Q ) ;
vector< pair<int,int> > sweep ;
vector< pair<int,int> > student(N+1) ;
vector< pair<int,int> > queries(Q+1) ;
vector<int> ansQueries(Q+1,0) ;
for(int i = 1 ; i <= N ; i++ )
{
scanf("%d %d", &student[i].first, &student[i].second ) ;
compressA.push_back(student[i].first) ;
compressB.push_back(student[i].second) ;
sweep.push_back( make_pair(student[i].first + student[i].second , i) ) ;
}
for(int i = 1 , C ; i <= Q ; i++ )
{
scanf("%d %d %d", &queries[i].first ,&queries[i].second, &C ) ;
compressA.push_back(queries[i].first) ;
compressB.push_back(queries[i].second) ;
sweep.push_back( make_pair(C, -i ) );
}
sort(all(compressA)) ; compressA.erase(unique(all(compressA) ) , compressA.end() ) ;
sort(all(compressB) ) ; compressB.erase(unique(all(compressB) ), compressB.end() ) ;
keyA = sz(compressA) ;
keyB = sz(compressB) ;
sort(all(sweep) ) ;
for(int i = 1 ; i <= keyA ; i++ ) bit[i].create() , bit[i].create() ;
for(int i = sz(sweep)-1 ; i >= 0 ; i-- )
{
auto e = sweep[i] ;
if( e.second > 0 )
{
int A = student[ e.second ].first ;
int B = student[ e.second ].second ;
A = lower_bound(all(compressA) , A ) - compressA.begin() + 1 ;
B = lower_bound(all(compressB) , B ) - compressB.begin() + 1 ;
upd( A , B ) ;
}
else
{
int idQuery = -e.second ;
int A = queries[idQuery].first ;
int B = queries[idQuery].second ;
A = lower_bound(all(compressA) , A ) - compressA.begin() + 1 ;
B = lower_bound(all(compressB) , B ) - compressB.begin() + 1;
ansQueries[idQuery] = qry(keyA, B) - qry(A-1, B) ;
}
}
for(int i = 1 ; i <= Q ; i++ ) printf("%d\n" , ansQueries[i]) ;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:85:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
85 | scanf("%d %d", &N, &Q ) ;
| ~~~~~^~~~~~~~~~~~~~~~~~
examination.cpp:94:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
94 | scanf("%d %d", &student[i].first, &student[i].second ) ;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:102:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
102 | scanf("%d %d %d", &queries[i].first ,&queries[i].second, &C ) ;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
11 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
30 ms |
17900 KB |
Output is correct |
8 |
Correct |
30 ms |
18028 KB |
Output is correct |
9 |
Correct |
30 ms |
18028 KB |
Output is correct |
10 |
Correct |
20 ms |
15724 KB |
Output is correct |
11 |
Correct |
16 ms |
15212 KB |
Output is correct |
12 |
Correct |
13 ms |
14700 KB |
Output is correct |
13 |
Correct |
31 ms |
18028 KB |
Output is correct |
14 |
Correct |
31 ms |
18028 KB |
Output is correct |
15 |
Correct |
31 ms |
18156 KB |
Output is correct |
16 |
Correct |
15 ms |
15212 KB |
Output is correct |
17 |
Correct |
18 ms |
15212 KB |
Output is correct |
18 |
Correct |
13 ms |
14700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1681 ms |
159792 KB |
Output is correct |
2 |
Correct |
1673 ms |
159952 KB |
Output is correct |
3 |
Correct |
1680 ms |
162000 KB |
Output is correct |
4 |
Correct |
340 ms |
39760 KB |
Output is correct |
5 |
Correct |
352 ms |
31692 KB |
Output is correct |
6 |
Correct |
119 ms |
21200 KB |
Output is correct |
7 |
Correct |
1286 ms |
157144 KB |
Output is correct |
8 |
Correct |
1486 ms |
154420 KB |
Output is correct |
9 |
Correct |
1163 ms |
150864 KB |
Output is correct |
10 |
Correct |
203 ms |
27984 KB |
Output is correct |
11 |
Correct |
206 ms |
29776 KB |
Output is correct |
12 |
Correct |
93 ms |
20816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1681 ms |
159792 KB |
Output is correct |
2 |
Correct |
1673 ms |
159952 KB |
Output is correct |
3 |
Correct |
1680 ms |
162000 KB |
Output is correct |
4 |
Correct |
340 ms |
39760 KB |
Output is correct |
5 |
Correct |
352 ms |
31692 KB |
Output is correct |
6 |
Correct |
119 ms |
21200 KB |
Output is correct |
7 |
Correct |
1286 ms |
157144 KB |
Output is correct |
8 |
Correct |
1486 ms |
154420 KB |
Output is correct |
9 |
Correct |
1163 ms |
150864 KB |
Output is correct |
10 |
Correct |
203 ms |
27984 KB |
Output is correct |
11 |
Correct |
206 ms |
29776 KB |
Output is correct |
12 |
Correct |
93 ms |
20816 KB |
Output is correct |
13 |
Correct |
1523 ms |
162648 KB |
Output is correct |
14 |
Correct |
1712 ms |
162552 KB |
Output is correct |
15 |
Correct |
1661 ms |
162128 KB |
Output is correct |
16 |
Correct |
365 ms |
40144 KB |
Output is correct |
17 |
Correct |
305 ms |
33232 KB |
Output is correct |
18 |
Correct |
129 ms |
21200 KB |
Output is correct |
19 |
Correct |
1484 ms |
162128 KB |
Output is correct |
20 |
Correct |
1591 ms |
162384 KB |
Output is correct |
21 |
Correct |
1289 ms |
157264 KB |
Output is correct |
22 |
Correct |
209 ms |
27984 KB |
Output is correct |
23 |
Correct |
207 ms |
29776 KB |
Output is correct |
24 |
Correct |
96 ms |
20816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
11 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
30 ms |
17900 KB |
Output is correct |
8 |
Correct |
30 ms |
18028 KB |
Output is correct |
9 |
Correct |
30 ms |
18028 KB |
Output is correct |
10 |
Correct |
20 ms |
15724 KB |
Output is correct |
11 |
Correct |
16 ms |
15212 KB |
Output is correct |
12 |
Correct |
13 ms |
14700 KB |
Output is correct |
13 |
Correct |
31 ms |
18028 KB |
Output is correct |
14 |
Correct |
31 ms |
18028 KB |
Output is correct |
15 |
Correct |
31 ms |
18156 KB |
Output is correct |
16 |
Correct |
15 ms |
15212 KB |
Output is correct |
17 |
Correct |
18 ms |
15212 KB |
Output is correct |
18 |
Correct |
13 ms |
14700 KB |
Output is correct |
19 |
Correct |
1681 ms |
159792 KB |
Output is correct |
20 |
Correct |
1673 ms |
159952 KB |
Output is correct |
21 |
Correct |
1680 ms |
162000 KB |
Output is correct |
22 |
Correct |
340 ms |
39760 KB |
Output is correct |
23 |
Correct |
352 ms |
31692 KB |
Output is correct |
24 |
Correct |
119 ms |
21200 KB |
Output is correct |
25 |
Correct |
1286 ms |
157144 KB |
Output is correct |
26 |
Correct |
1486 ms |
154420 KB |
Output is correct |
27 |
Correct |
1163 ms |
150864 KB |
Output is correct |
28 |
Correct |
203 ms |
27984 KB |
Output is correct |
29 |
Correct |
206 ms |
29776 KB |
Output is correct |
30 |
Correct |
93 ms |
20816 KB |
Output is correct |
31 |
Correct |
1523 ms |
162648 KB |
Output is correct |
32 |
Correct |
1712 ms |
162552 KB |
Output is correct |
33 |
Correct |
1661 ms |
162128 KB |
Output is correct |
34 |
Correct |
365 ms |
40144 KB |
Output is correct |
35 |
Correct |
305 ms |
33232 KB |
Output is correct |
36 |
Correct |
129 ms |
21200 KB |
Output is correct |
37 |
Correct |
1484 ms |
162128 KB |
Output is correct |
38 |
Correct |
1591 ms |
162384 KB |
Output is correct |
39 |
Correct |
1289 ms |
157264 KB |
Output is correct |
40 |
Correct |
209 ms |
27984 KB |
Output is correct |
41 |
Correct |
207 ms |
29776 KB |
Output is correct |
42 |
Correct |
96 ms |
20816 KB |
Output is correct |
43 |
Correct |
1775 ms |
210384 KB |
Output is correct |
44 |
Correct |
1775 ms |
210036 KB |
Output is correct |
45 |
Correct |
1978 ms |
210104 KB |
Output is correct |
46 |
Correct |
451 ms |
54736 KB |
Output is correct |
47 |
Correct |
335 ms |
35024 KB |
Output is correct |
48 |
Correct |
136 ms |
20312 KB |
Output is correct |
49 |
Correct |
1674 ms |
195212 KB |
Output is correct |
50 |
Correct |
1515 ms |
203304 KB |
Output is correct |
51 |
Correct |
1418 ms |
187472 KB |
Output is correct |
52 |
Correct |
244 ms |
31312 KB |
Output is correct |
53 |
Correct |
264 ms |
38864 KB |
Output is correct |