///breaker
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define fi first
#define se second
#define ii pair<int,int>
#define mp make_pair
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define bit(x,i) ((x>>i)&1)
#define lc (id<<1)
#define rc ((id<<1)^1)
const int maxn=1e5+7;
const int sz=350;
struct BIT
{
int t[maxn];
void add(int x,int val){for(;x;x-=(x&(-x)))t[x]+=val;}
int get(int x){int res=0;for(;x<maxn;x+=(x&(-x)))res+=t[x];return res;}
}t[sz+7];
struct Data
{
int x,y,z,id;
};
int n,q;
Data a[maxn];
Data qu[maxn];
int ans[maxn];
ordered_set s[maxn];
int pos(int x,vector<int>&v)
{
return lower_bound(v.begin(),v.end(),x)-v.begin()+1;
}
bool cmp(Data a,Data b)
{
return a.z>b.z;
}
void sol(void){
cin>>n>>q;
vector<int>vx;
vector<int>vy;
for(int i=1;i<=n;i++){
cin>>a[i].x>>a[i].y;
vx.push_back(a[i].x);
vy.push_back(a[i].y);
a[i].z=a[i].x+a[i].y;
}
for(int i=1;i<=q;i++){
cin>>qu[i].x>>qu[i].y>>qu[i].z;
vx.push_back(qu[i].x);
vy.push_back(qu[i].y);
qu[i].id=i;
}
sort(vx.begin(),vx.end());
sort(vy.begin(),vy.end());
vx.erase(unique(vx.begin(),vx.end()),vx.end());
vy.erase(unique(vy.begin(),vy.end()),vy.end());
sort(a+1,a+n+1,cmp);
sort(qu+1,qu+q+1,cmp);
int l=1;
for(int i=1;i<=n;i++){
int pos1=pos(a[i].x,vx);
int pos2=pos(a[i].y,vy);
t[(pos1-1)/sz].add(pos2,1);
s[pos1].insert({pos2,i});
while(l<=q&&(i==n||qu[l].z>a[i+1].z)){
if(qu[l].z>a[i].z){
l++;
continue;
}
pos1=pos(qu[l].x,vx);
pos2=pos(qu[l].y,vy);
int tmp=0;
for(int i=(pos1-1)/sz+1; i<=(vx.size()-1)/sz; i++)tmp+=t[i].get(pos2);
for(int i=pos1; i<=((pos1-1)/sz+1)*sz; i++)tmp+=s[i].size()-s[i].order_of_key({pos2,0});
ans[qu[l].id]=tmp;
l++;
}
}
for(int i=1;i<=q;i++){
cout<<ans[i]<<"\n";
}
}
signed main(void)
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
while(t--){
sol();
}
// you should actually read the stuff at the bottom
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Compilation message
examination.cpp: In function 'void sol()':
examination.cpp:83:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int i=(pos1-1)/sz+1; i<=(vx.size()-1)/sz; i++)tmp+=t[i].get(pos2);
| ~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9820 KB |
Output is correct |
2 |
Correct |
6 ms |
9820 KB |
Output is correct |
3 |
Correct |
6 ms |
9864 KB |
Output is correct |
4 |
Correct |
6 ms |
9816 KB |
Output is correct |
5 |
Correct |
6 ms |
9820 KB |
Output is correct |
6 |
Correct |
5 ms |
9820 KB |
Output is correct |
7 |
Correct |
12 ms |
10840 KB |
Output is correct |
8 |
Correct |
13 ms |
10844 KB |
Output is correct |
9 |
Correct |
14 ms |
10844 KB |
Output is correct |
10 |
Correct |
11 ms |
10272 KB |
Output is correct |
11 |
Correct |
11 ms |
10380 KB |
Output is correct |
12 |
Correct |
10 ms |
10276 KB |
Output is correct |
13 |
Correct |
13 ms |
10744 KB |
Output is correct |
14 |
Correct |
13 ms |
10844 KB |
Output is correct |
15 |
Correct |
14 ms |
10844 KB |
Output is correct |
16 |
Correct |
10 ms |
10332 KB |
Output is correct |
17 |
Correct |
11 ms |
10272 KB |
Output is correct |
18 |
Correct |
8 ms |
10032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1484 ms |
108260 KB |
Output is correct |
2 |
Correct |
1428 ms |
108352 KB |
Output is correct |
3 |
Correct |
1413 ms |
108392 KB |
Output is correct |
4 |
Correct |
756 ms |
24684 KB |
Output is correct |
5 |
Correct |
283 ms |
23864 KB |
Output is correct |
6 |
Correct |
199 ms |
22640 KB |
Output is correct |
7 |
Correct |
1603 ms |
89456 KB |
Output is correct |
8 |
Correct |
820 ms |
89700 KB |
Output is correct |
9 |
Correct |
829 ms |
74724 KB |
Output is correct |
10 |
Correct |
170 ms |
23656 KB |
Output is correct |
11 |
Correct |
676 ms |
24500 KB |
Output is correct |
12 |
Correct |
168 ms |
22376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1484 ms |
108260 KB |
Output is correct |
2 |
Correct |
1428 ms |
108352 KB |
Output is correct |
3 |
Correct |
1413 ms |
108392 KB |
Output is correct |
4 |
Correct |
756 ms |
24684 KB |
Output is correct |
5 |
Correct |
283 ms |
23864 KB |
Output is correct |
6 |
Correct |
199 ms |
22640 KB |
Output is correct |
7 |
Correct |
1603 ms |
89456 KB |
Output is correct |
8 |
Correct |
820 ms |
89700 KB |
Output is correct |
9 |
Correct |
829 ms |
74724 KB |
Output is correct |
10 |
Correct |
170 ms |
23656 KB |
Output is correct |
11 |
Correct |
676 ms |
24500 KB |
Output is correct |
12 |
Correct |
168 ms |
22376 KB |
Output is correct |
13 |
Correct |
1058 ms |
108932 KB |
Output is correct |
14 |
Correct |
1409 ms |
108972 KB |
Output is correct |
15 |
Correct |
1458 ms |
108396 KB |
Output is correct |
16 |
Correct |
598 ms |
24872 KB |
Output is correct |
17 |
Correct |
256 ms |
24172 KB |
Output is correct |
18 |
Correct |
196 ms |
22636 KB |
Output is correct |
19 |
Correct |
1103 ms |
109052 KB |
Output is correct |
20 |
Correct |
1229 ms |
109132 KB |
Output is correct |
21 |
Correct |
860 ms |
95336 KB |
Output is correct |
22 |
Correct |
193 ms |
23664 KB |
Output is correct |
23 |
Correct |
681 ms |
24428 KB |
Output is correct |
24 |
Correct |
163 ms |
22452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9820 KB |
Output is correct |
2 |
Correct |
6 ms |
9820 KB |
Output is correct |
3 |
Correct |
6 ms |
9864 KB |
Output is correct |
4 |
Correct |
6 ms |
9816 KB |
Output is correct |
5 |
Correct |
6 ms |
9820 KB |
Output is correct |
6 |
Correct |
5 ms |
9820 KB |
Output is correct |
7 |
Correct |
12 ms |
10840 KB |
Output is correct |
8 |
Correct |
13 ms |
10844 KB |
Output is correct |
9 |
Correct |
14 ms |
10844 KB |
Output is correct |
10 |
Correct |
11 ms |
10272 KB |
Output is correct |
11 |
Correct |
11 ms |
10380 KB |
Output is correct |
12 |
Correct |
10 ms |
10276 KB |
Output is correct |
13 |
Correct |
13 ms |
10744 KB |
Output is correct |
14 |
Correct |
13 ms |
10844 KB |
Output is correct |
15 |
Correct |
14 ms |
10844 KB |
Output is correct |
16 |
Correct |
10 ms |
10332 KB |
Output is correct |
17 |
Correct |
11 ms |
10272 KB |
Output is correct |
18 |
Correct |
8 ms |
10032 KB |
Output is correct |
19 |
Correct |
1484 ms |
108260 KB |
Output is correct |
20 |
Correct |
1428 ms |
108352 KB |
Output is correct |
21 |
Correct |
1413 ms |
108392 KB |
Output is correct |
22 |
Correct |
756 ms |
24684 KB |
Output is correct |
23 |
Correct |
283 ms |
23864 KB |
Output is correct |
24 |
Correct |
199 ms |
22640 KB |
Output is correct |
25 |
Correct |
1603 ms |
89456 KB |
Output is correct |
26 |
Correct |
820 ms |
89700 KB |
Output is correct |
27 |
Correct |
829 ms |
74724 KB |
Output is correct |
28 |
Correct |
170 ms |
23656 KB |
Output is correct |
29 |
Correct |
676 ms |
24500 KB |
Output is correct |
30 |
Correct |
168 ms |
22376 KB |
Output is correct |
31 |
Correct |
1058 ms |
108932 KB |
Output is correct |
32 |
Correct |
1409 ms |
108972 KB |
Output is correct |
33 |
Correct |
1458 ms |
108396 KB |
Output is correct |
34 |
Correct |
598 ms |
24872 KB |
Output is correct |
35 |
Correct |
256 ms |
24172 KB |
Output is correct |
36 |
Correct |
196 ms |
22636 KB |
Output is correct |
37 |
Correct |
1103 ms |
109052 KB |
Output is correct |
38 |
Correct |
1229 ms |
109132 KB |
Output is correct |
39 |
Correct |
860 ms |
95336 KB |
Output is correct |
40 |
Correct |
193 ms |
23664 KB |
Output is correct |
41 |
Correct |
681 ms |
24428 KB |
Output is correct |
42 |
Correct |
163 ms |
22452 KB |
Output is correct |
43 |
Runtime error |
90 ms |
34160 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |