#include<bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
using namespace std;
const int mxn=2e5+4;
struct BIT
{
int bit[mxn]={};
void update(int i,int v)
{
for(;i>0;i-=i&-i)
{
bit[i]+=v;
}
}
int query(int i)
{
ll s=0;
for(;i<=mxn;i+=i&-i)
{
s+=bit[i];
}
return s;
}
}bt;
struct score{
int a,b,tot;
int type;
int id;
score(int _a,int _b,int tt,int tp,int i):a(_a),b(_b),tot(tt),type(tp),id(i){};
};
int ans[mxn]={};
vector<score> sc;
void solve(int l ,int r)
{
if(l==r)return;
int mid=l+r>>1;
vector<score> tmp;
for(int i=l;i<=mid;i++)
{
if(sc[i].type==0)tmp.push_back(sc[i]);
}
for(int i=mid+1;i<=r;i++)
if(sc[i].type==1)tmp.push_back(sc[i]);
sort(tmp.begin(),tmp.end(),[](score a,score b)
{
if(a.a==b.a)return a.type<b.type;
return a.a>b.a;
});
for(int i=0;i<tmp.size();i++)
{
if(tmp[i].type==0)
{
bt.update(tmp[i].b,1);
}
else
{
ans[tmp[i].id]+=bt.query(tmp[i].b);
}
}
for(int i=0;i<tmp.size();i++)
if(tmp[i].type==0)bt.update(tmp[i].b,-1);
solve(l,mid);
solve(mid+1,r);
}
int main()
{
int n,q;
cin>>n>>q;
vector<int> A,B;
for(int i=0;i<n;i++)
{
int a,b;
scanf("%d%d",&a,&b);
sc.push_back(score(a,b,a+b,0,-1));
A.push_back(a);
B.push_back(b);
}
for(int i=0;i<q;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
sc.push_back(score(a,b,c,1,i));
}
sort(A.begin(),A.end());
sort(B.begin(),B.end());
sort(sc.begin(),sc.end(),[](score a,score b)
{
return (a.tot==b.tot)?a.type<b.type : a.tot>b.tot;
});
A.erase(unique(A.begin(),A.end()),A.end());
B.erase(unique(B.begin(),B.end()),B.end());
for(int i=0;i<sc.size();i++)
{
sc[i].a=lower_bound(A.begin(),A.end(),sc[i].a)-A.begin()+1;
sc[i].b=lower_bound(B.begin(),B.end(),sc[i].b)-B.begin()+1;
}
solve(0,sc.size()-1);
for(int i=0;i<q;i++)
{
printf("%d\n",ans[i]);
}
return 0;
}
Compilation message
examination.cpp: In function 'void solve(int, int)':
examination.cpp:46:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=l+r>>1;
~^~
examination.cpp:65:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<tmp.size();i++)
~^~~~~~~~~~~
examination.cpp:77:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<tmp.size();i++)
~^~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:125:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<sc.size();i++)
~^~~~~~~~~~
examination.cpp:96:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&a,&b);
~~~~~^~~~~~~~~~~~~~
examination.cpp:105:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&a,&b,&c);
~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
14 ms |
768 KB |
Output is correct |
8 |
Correct |
14 ms |
768 KB |
Output is correct |
9 |
Correct |
14 ms |
768 KB |
Output is correct |
10 |
Correct |
12 ms |
768 KB |
Output is correct |
11 |
Correct |
13 ms |
768 KB |
Output is correct |
12 |
Correct |
10 ms |
640 KB |
Output is correct |
13 |
Correct |
13 ms |
896 KB |
Output is correct |
14 |
Correct |
13 ms |
896 KB |
Output is correct |
15 |
Correct |
13 ms |
896 KB |
Output is correct |
16 |
Correct |
11 ms |
884 KB |
Output is correct |
17 |
Correct |
12 ms |
768 KB |
Output is correct |
18 |
Correct |
9 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
369 ms |
17536 KB |
Output is correct |
2 |
Correct |
352 ms |
17404 KB |
Output is correct |
3 |
Correct |
356 ms |
17532 KB |
Output is correct |
4 |
Correct |
288 ms |
16376 KB |
Output is correct |
5 |
Correct |
285 ms |
16760 KB |
Output is correct |
6 |
Correct |
235 ms |
15608 KB |
Output is correct |
7 |
Correct |
346 ms |
17272 KB |
Output is correct |
8 |
Correct |
348 ms |
17276 KB |
Output is correct |
9 |
Correct |
346 ms |
17148 KB |
Output is correct |
10 |
Correct |
236 ms |
16636 KB |
Output is correct |
11 |
Correct |
258 ms |
16380 KB |
Output is correct |
12 |
Correct |
180 ms |
15612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
369 ms |
17536 KB |
Output is correct |
2 |
Correct |
352 ms |
17404 KB |
Output is correct |
3 |
Correct |
356 ms |
17532 KB |
Output is correct |
4 |
Correct |
288 ms |
16376 KB |
Output is correct |
5 |
Correct |
285 ms |
16760 KB |
Output is correct |
6 |
Correct |
235 ms |
15608 KB |
Output is correct |
7 |
Correct |
346 ms |
17272 KB |
Output is correct |
8 |
Correct |
348 ms |
17276 KB |
Output is correct |
9 |
Correct |
346 ms |
17148 KB |
Output is correct |
10 |
Correct |
236 ms |
16636 KB |
Output is correct |
11 |
Correct |
258 ms |
16380 KB |
Output is correct |
12 |
Correct |
180 ms |
15612 KB |
Output is correct |
13 |
Correct |
385 ms |
13820 KB |
Output is correct |
14 |
Correct |
394 ms |
16764 KB |
Output is correct |
15 |
Correct |
360 ms |
17408 KB |
Output is correct |
16 |
Correct |
323 ms |
12792 KB |
Output is correct |
17 |
Correct |
329 ms |
13048 KB |
Output is correct |
18 |
Correct |
240 ms |
14588 KB |
Output is correct |
19 |
Correct |
387 ms |
13816 KB |
Output is correct |
20 |
Correct |
395 ms |
13960 KB |
Output is correct |
21 |
Correct |
380 ms |
13824 KB |
Output is correct |
22 |
Correct |
238 ms |
16636 KB |
Output is correct |
23 |
Correct |
258 ms |
16544 KB |
Output is correct |
24 |
Correct |
175 ms |
15608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
14 ms |
768 KB |
Output is correct |
8 |
Correct |
14 ms |
768 KB |
Output is correct |
9 |
Correct |
14 ms |
768 KB |
Output is correct |
10 |
Correct |
12 ms |
768 KB |
Output is correct |
11 |
Correct |
13 ms |
768 KB |
Output is correct |
12 |
Correct |
10 ms |
640 KB |
Output is correct |
13 |
Correct |
13 ms |
896 KB |
Output is correct |
14 |
Correct |
13 ms |
896 KB |
Output is correct |
15 |
Correct |
13 ms |
896 KB |
Output is correct |
16 |
Correct |
11 ms |
884 KB |
Output is correct |
17 |
Correct |
12 ms |
768 KB |
Output is correct |
18 |
Correct |
9 ms |
640 KB |
Output is correct |
19 |
Correct |
369 ms |
17536 KB |
Output is correct |
20 |
Correct |
352 ms |
17404 KB |
Output is correct |
21 |
Correct |
356 ms |
17532 KB |
Output is correct |
22 |
Correct |
288 ms |
16376 KB |
Output is correct |
23 |
Correct |
285 ms |
16760 KB |
Output is correct |
24 |
Correct |
235 ms |
15608 KB |
Output is correct |
25 |
Correct |
346 ms |
17272 KB |
Output is correct |
26 |
Correct |
348 ms |
17276 KB |
Output is correct |
27 |
Correct |
346 ms |
17148 KB |
Output is correct |
28 |
Correct |
236 ms |
16636 KB |
Output is correct |
29 |
Correct |
258 ms |
16380 KB |
Output is correct |
30 |
Correct |
180 ms |
15612 KB |
Output is correct |
31 |
Correct |
385 ms |
13820 KB |
Output is correct |
32 |
Correct |
394 ms |
16764 KB |
Output is correct |
33 |
Correct |
360 ms |
17408 KB |
Output is correct |
34 |
Correct |
323 ms |
12792 KB |
Output is correct |
35 |
Correct |
329 ms |
13048 KB |
Output is correct |
36 |
Correct |
240 ms |
14588 KB |
Output is correct |
37 |
Correct |
387 ms |
13816 KB |
Output is correct |
38 |
Correct |
395 ms |
13960 KB |
Output is correct |
39 |
Correct |
380 ms |
13824 KB |
Output is correct |
40 |
Correct |
238 ms |
16636 KB |
Output is correct |
41 |
Correct |
258 ms |
16544 KB |
Output is correct |
42 |
Correct |
175 ms |
15608 KB |
Output is correct |
43 |
Correct |
409 ms |
15992 KB |
Output is correct |
44 |
Correct |
418 ms |
15868 KB |
Output is correct |
45 |
Correct |
425 ms |
19064 KB |
Output is correct |
46 |
Correct |
326 ms |
13948 KB |
Output is correct |
47 |
Correct |
341 ms |
14348 KB |
Output is correct |
48 |
Correct |
219 ms |
10744 KB |
Output is correct |
49 |
Correct |
406 ms |
18812 KB |
Output is correct |
50 |
Correct |
405 ms |
15740 KB |
Output is correct |
51 |
Correct |
399 ms |
18684 KB |
Output is correct |
52 |
Correct |
288 ms |
14204 KB |
Output is correct |
53 |
Correct |
262 ms |
17148 KB |
Output is correct |