#include<bits/stdc++.h>
using namespace std ;
const int mx = 2e5 + 5 ;
int ans[mx] , cnt_a , cnt_b , n , q ;
map<int,int> np , mp ;
set<int> A , B ;
struct BIT
{
vector<int> t ;
BIT(int n)
{
t = vector<int> (n + 5 , 0) ;
}
void update(int ind , int val)
{
while(ind<=mx)
{
t[ind] += val ;
ind += (ind&(-ind)) ;
}
}
int query(int l , int r)
{
--l ;
int left = 0 , right = 0 ;
while(l)
{
left += t[l] ;
l -= (l&(-l)) ;
}
while(r)
{
right += t[r] ;
r -= (r&(-r)) ;
}
return right - left ;
}
} T(mx+5) ;
struct score
{
int a , b , sum , type , idx ;
score(int _a , int _b , int _sum , int _type , int _idx) : a(_a) , b(_b) , sum(_sum) , type(_type) , idx(_idx) {} ;
};
bool cmp1(const score &a , const score &b)
{
if(a.sum==b.sum) return a.type < b.type ;
return a.sum > b.sum ;
}
bool cmp2(const score &a , const score &b)
{
if(a.a==b.a) return a.type < b.type ;
return a.a > b.a ;
}
vector<score> scores ;
void divide(int l , int r)
{
if(l==r) return ;
int mid = (l+r)>>1 ;
vector<score> tmp ;
for(int i = l ; i <= mid ; ++i)
{
if(!scores[i].type) tmp.push_back(scores[i]) ;
}
for(int i = mid + 1 ; i <= r ; ++i)
{
if(scores[i].type) tmp.push_back(scores[i]) ;
}
sort(tmp.begin(),tmp.end() , cmp2) ;
int siz = tmp.size() ;
for(int i = 0 ; i < siz ; ++i)
{
if(!tmp[i].type) T.update(tmp[i].b,1) ;
else ans[tmp[i].idx] += T.query(tmp[i].b,mx) ;
}
for(int i = 0 ; i < siz ; ++i)
{
if(!tmp[i].type) T.update(tmp[i].b,-1) ;
}
divide(l,mid) , divide(mid+1,r) ;
}
int main()
{
scanf("%d%d",&n,&q) ;
for(int i = 1 ; i <= n ; ++i)
{
int s , t ;
scanf("%d%d",&s,&t) ;
A.insert(s) , B.insert(t) ;
scores.push_back(score(s,t,s+t,0,-1)) ;
}
for(int i = 1 ; i <= q ; ++i)
{
int x , y , z ;
scanf("%d%d%d",&x,&y,&z) ;
A.insert(x) , B.insert(y) ;
scores.push_back(score(x,y,z,1,i)) ;
}
for(int i : A) np[i] = ++cnt_a ;
for(int i : B) mp[i] = ++cnt_b ;
for(int i = 0 ; i < (n+q) ; ++i)
{
scores[i].a = np[scores[i].a] , scores[i].b = mp[scores[i].b] ;
}
sort(scores.begin(),scores.end(),cmp1) ;
divide(0,n+q-1) ;
for(int i = 1 ; i <= q ; ++i) printf("%d\n",ans[i]) ;
return 0 ;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:95:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
95 | scanf("%d%d",&n,&q) ;
| ~~~~~^~~~~~~~~~~~~~
examination.cpp:99:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
99 | scanf("%d%d",&s,&t) ;
| ~~~~~^~~~~~~~~~~~~~
examination.cpp:106:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
106 | scanf("%d%d%d",&x,&y,&z) ;
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1132 KB |
Output is correct |
2 |
Correct |
1 ms |
1132 KB |
Output is correct |
3 |
Correct |
1 ms |
1132 KB |
Output is correct |
4 |
Correct |
1 ms |
1132 KB |
Output is correct |
5 |
Correct |
1 ms |
1132 KB |
Output is correct |
6 |
Correct |
1 ms |
1132 KB |
Output is correct |
7 |
Correct |
16 ms |
2668 KB |
Output is correct |
8 |
Correct |
16 ms |
2668 KB |
Output is correct |
9 |
Correct |
18 ms |
2796 KB |
Output is correct |
10 |
Correct |
12 ms |
2028 KB |
Output is correct |
11 |
Correct |
15 ms |
2028 KB |
Output is correct |
12 |
Correct |
10 ms |
1488 KB |
Output is correct |
13 |
Correct |
17 ms |
2768 KB |
Output is correct |
14 |
Correct |
15 ms |
2768 KB |
Output is correct |
15 |
Correct |
15 ms |
2768 KB |
Output is correct |
16 |
Correct |
11 ms |
2156 KB |
Output is correct |
17 |
Correct |
12 ms |
2176 KB |
Output is correct |
18 |
Correct |
7 ms |
1484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
833 ms |
31600 KB |
Output is correct |
2 |
Correct |
790 ms |
31508 KB |
Output is correct |
3 |
Correct |
822 ms |
31512 KB |
Output is correct |
4 |
Correct |
498 ms |
22640 KB |
Output is correct |
5 |
Correct |
465 ms |
22896 KB |
Output is correct |
6 |
Correct |
315 ms |
13780 KB |
Output is correct |
7 |
Correct |
694 ms |
29552 KB |
Output is correct |
8 |
Correct |
722 ms |
29708 KB |
Output is correct |
9 |
Correct |
629 ms |
27912 KB |
Output is correct |
10 |
Correct |
438 ms |
22640 KB |
Output is correct |
11 |
Correct |
475 ms |
22640 KB |
Output is correct |
12 |
Correct |
273 ms |
13776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
833 ms |
31600 KB |
Output is correct |
2 |
Correct |
790 ms |
31508 KB |
Output is correct |
3 |
Correct |
822 ms |
31512 KB |
Output is correct |
4 |
Correct |
498 ms |
22640 KB |
Output is correct |
5 |
Correct |
465 ms |
22896 KB |
Output is correct |
6 |
Correct |
315 ms |
13780 KB |
Output is correct |
7 |
Correct |
694 ms |
29552 KB |
Output is correct |
8 |
Correct |
722 ms |
29708 KB |
Output is correct |
9 |
Correct |
629 ms |
27912 KB |
Output is correct |
10 |
Correct |
438 ms |
22640 KB |
Output is correct |
11 |
Correct |
475 ms |
22640 KB |
Output is correct |
12 |
Correct |
273 ms |
13776 KB |
Output is correct |
13 |
Correct |
838 ms |
29808 KB |
Output is correct |
14 |
Correct |
795 ms |
31856 KB |
Output is correct |
15 |
Correct |
855 ms |
31604 KB |
Output is correct |
16 |
Correct |
508 ms |
21744 KB |
Output is correct |
17 |
Correct |
485 ms |
20840 KB |
Output is correct |
18 |
Correct |
308 ms |
13780 KB |
Output is correct |
19 |
Correct |
829 ms |
29808 KB |
Output is correct |
20 |
Correct |
809 ms |
30832 KB |
Output is correct |
21 |
Correct |
755 ms |
28272 KB |
Output is correct |
22 |
Correct |
403 ms |
22640 KB |
Output is correct |
23 |
Correct |
475 ms |
22664 KB |
Output is correct |
24 |
Correct |
262 ms |
13776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1132 KB |
Output is correct |
2 |
Correct |
1 ms |
1132 KB |
Output is correct |
3 |
Correct |
1 ms |
1132 KB |
Output is correct |
4 |
Correct |
1 ms |
1132 KB |
Output is correct |
5 |
Correct |
1 ms |
1132 KB |
Output is correct |
6 |
Correct |
1 ms |
1132 KB |
Output is correct |
7 |
Correct |
16 ms |
2668 KB |
Output is correct |
8 |
Correct |
16 ms |
2668 KB |
Output is correct |
9 |
Correct |
18 ms |
2796 KB |
Output is correct |
10 |
Correct |
12 ms |
2028 KB |
Output is correct |
11 |
Correct |
15 ms |
2028 KB |
Output is correct |
12 |
Correct |
10 ms |
1488 KB |
Output is correct |
13 |
Correct |
17 ms |
2768 KB |
Output is correct |
14 |
Correct |
15 ms |
2768 KB |
Output is correct |
15 |
Correct |
15 ms |
2768 KB |
Output is correct |
16 |
Correct |
11 ms |
2156 KB |
Output is correct |
17 |
Correct |
12 ms |
2176 KB |
Output is correct |
18 |
Correct |
7 ms |
1484 KB |
Output is correct |
19 |
Correct |
833 ms |
31600 KB |
Output is correct |
20 |
Correct |
790 ms |
31508 KB |
Output is correct |
21 |
Correct |
822 ms |
31512 KB |
Output is correct |
22 |
Correct |
498 ms |
22640 KB |
Output is correct |
23 |
Correct |
465 ms |
22896 KB |
Output is correct |
24 |
Correct |
315 ms |
13780 KB |
Output is correct |
25 |
Correct |
694 ms |
29552 KB |
Output is correct |
26 |
Correct |
722 ms |
29708 KB |
Output is correct |
27 |
Correct |
629 ms |
27912 KB |
Output is correct |
28 |
Correct |
438 ms |
22640 KB |
Output is correct |
29 |
Correct |
475 ms |
22640 KB |
Output is correct |
30 |
Correct |
273 ms |
13776 KB |
Output is correct |
31 |
Correct |
838 ms |
29808 KB |
Output is correct |
32 |
Correct |
795 ms |
31856 KB |
Output is correct |
33 |
Correct |
855 ms |
31604 KB |
Output is correct |
34 |
Correct |
508 ms |
21744 KB |
Output is correct |
35 |
Correct |
485 ms |
20840 KB |
Output is correct |
36 |
Correct |
308 ms |
13780 KB |
Output is correct |
37 |
Correct |
829 ms |
29808 KB |
Output is correct |
38 |
Correct |
809 ms |
30832 KB |
Output is correct |
39 |
Correct |
755 ms |
28272 KB |
Output is correct |
40 |
Correct |
403 ms |
22640 KB |
Output is correct |
41 |
Correct |
475 ms |
22664 KB |
Output is correct |
42 |
Correct |
262 ms |
13776 KB |
Output is correct |
43 |
Correct |
1250 ms |
53096 KB |
Output is correct |
44 |
Correct |
1121 ms |
52976 KB |
Output is correct |
45 |
Correct |
1152 ms |
55152 KB |
Output is correct |
46 |
Correct |
705 ms |
32624 KB |
Output is correct |
47 |
Correct |
655 ms |
33520 KB |
Output is correct |
48 |
Correct |
291 ms |
11092 KB |
Output is correct |
49 |
Correct |
1111 ms |
55156 KB |
Output is correct |
50 |
Correct |
1117 ms |
52976 KB |
Output is correct |
51 |
Correct |
1070 ms |
55092 KB |
Output is correct |
52 |
Correct |
612 ms |
32368 KB |
Output is correct |
53 |
Correct |
622 ms |
34032 KB |
Output is correct |