#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
struct xnode{
int yroot,L,R;
xnode(){
yroot=-1,L=-1,R=-1;
}
};
struct ynode{
int val,L,R;
ynode(){
val=0;
L=-1,R=-1;
}
};
int nx,ny;
vector<xnode> xtree;
vector<ynode> ytree;
int xinit(){
xnode x;
xtree.pb(x);
return xtree.size()-1;
}
int yinit(){
ynode y;
ytree.pb(y);
return ytree.size()-1;
}
void yupd(int node,int S,int E,int y)
{
ytree[node].val++;
if(S==E)return;
int M=(S+E)>>1;
if(y<=M)
{
if(ytree[node].L==-1)
{
int next=yinit();
ytree[node].L=next;
}
yupd(ytree[node].L,S,M,y);
}
else
{
if(ytree[node].R==-1)
{
int next=yinit();
ytree[node].R=next;
}
yupd(ytree[node].R,M+1,E,y);
}
}
void upd(int node,int S,int E,int x,int y)//(x,y)좌표값 1증가
{
if(xtree[node].yroot==-1)
{
int next=yinit();
xtree[node].yroot=next;
}
yupd(xtree[node].yroot,0,ny-1,y);
if(S==E)return;
int M=(S+E)>>1;
if(x<=M)
{
if(xtree[node].L==-1)
{
int next=xinit();
xtree[node].L=next;
}
upd(xtree[node].L,S,M,x,y);
}
else
{
if(xtree[node].R==-1)
{
int next=xinit();
xtree[node].R=next;
}
upd(xtree[node].R,M+1,E,x,y);
}
}
int yfind(int node,int S,int E,int y1,int y2)
{
if(y1>E || y2<S)return 0;
if(y1<=S && y2>=E)return ytree[node].val;
int res=0;
if(~ytree[node].L)res+=yfind(ytree[node].L,S,(S+E)/2,y1,y2);
if(~ytree[node].R)res+=yfind(ytree[node].R,(S+E)/2+1,E,y1,y2);
return res;
}
int find(int node,int S,int E,int x1,int x2,int y1,int y2)
{
if(x1>E || x2<S)return 0;
if(x1<=S && x2>=E)
{
if(xtree[node].yroot==-1)return 0;
return yfind(xtree[node].yroot,0,ny-1,y1,y2);
}
int res=0;
if(~xtree[node].L)res+=find(xtree[node].L,S,(S+E)/2,x1,x2,y1,y2);
if(~xtree[node].R)res+=find(xtree[node].R,(S+E)/2+1,E,x1,x2,y1,y2);
return res;
}
struct query{
int x,y,z,i;
bool operator <(const query &O)const{
return z>O.z;
}
}q[100000];
Pi p[100000];
int ans[100000];
int main() {
Vi xx,yy;
xinit();
int n,Q;
scanf("%d%d",&n,&Q);
fup(i,0,n-1,1)
{
scanf("%d%d",&p[i].X,&p[i].Y);
xx.pb(p[i].X);
yy.pb(p[i].Y);
}
sort(ALL(xx));xx.resize(unique(ALL(xx))-xx.begin());
sort(ALL(yy));yy.resize(unique(ALL(yy))-yy.begin());
nx=xx.size(),ny=yy.size();
sort(p,p+n,[&](Pi p1,Pi p2){return p1.X+p1.Y>p2.X+p2.Y;});
fup(i,0,Q-1,1)
{
scanf("%d%d%d",&q[i].x,&q[i].y,&q[i].z);
q[i].i=i;
}
sort(q,q+Q);
for(int i=0,j=0;i<Q;i++)
{
while(j<n && p[j].X+p[j].Y>=q[i].z)
{
upd(0,0,nx-1,lower_bound(ALL(xx),p[j].X)-xx.begin(),lower_bound(ALL(yy),p[j].Y)-yy.begin());
j++;
}
ans[q[i].i]=find(0,0,nx-1,lower_bound(ALL(xx),q[i].x)-xx.begin(),nx-1,lower_bound(ALL(yy),q[i].y)-yy.begin(),ny-1);
}
fup(i,0,Q-1,1)printf("%d\n",ans[i]);
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:177:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&Q);
~~~~~^~~~~~~~~~~~~~
examination.cpp:180:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&p[i].X,&p[i].Y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:190:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&q[i].x,&q[i].y,&q[i].z);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
22 ms |
6896 KB |
Output is correct |
8 |
Correct |
22 ms |
6896 KB |
Output is correct |
9 |
Correct |
22 ms |
6892 KB |
Output is correct |
10 |
Correct |
10 ms |
1432 KB |
Output is correct |
11 |
Correct |
9 ms |
1532 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
23 ms |
6892 KB |
Output is correct |
14 |
Correct |
23 ms |
6896 KB |
Output is correct |
15 |
Correct |
23 ms |
6768 KB |
Output is correct |
16 |
Correct |
6 ms |
760 KB |
Output is correct |
17 |
Correct |
7 ms |
760 KB |
Output is correct |
18 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1611 ms |
205624 KB |
Output is correct |
2 |
Correct |
1753 ms |
205748 KB |
Output is correct |
3 |
Correct |
1724 ms |
205872 KB |
Output is correct |
4 |
Correct |
339 ms |
32968 KB |
Output is correct |
5 |
Correct |
285 ms |
30396 KB |
Output is correct |
6 |
Correct |
96 ms |
5612 KB |
Output is correct |
7 |
Correct |
1605 ms |
205716 KB |
Output is correct |
8 |
Correct |
1604 ms |
205732 KB |
Output is correct |
9 |
Correct |
1364 ms |
205592 KB |
Output is correct |
10 |
Correct |
128 ms |
7944 KB |
Output is correct |
11 |
Correct |
165 ms |
9580 KB |
Output is correct |
12 |
Correct |
59 ms |
5228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1611 ms |
205624 KB |
Output is correct |
2 |
Correct |
1753 ms |
205748 KB |
Output is correct |
3 |
Correct |
1724 ms |
205872 KB |
Output is correct |
4 |
Correct |
339 ms |
32968 KB |
Output is correct |
5 |
Correct |
285 ms |
30396 KB |
Output is correct |
6 |
Correct |
96 ms |
5612 KB |
Output is correct |
7 |
Correct |
1605 ms |
205716 KB |
Output is correct |
8 |
Correct |
1604 ms |
205732 KB |
Output is correct |
9 |
Correct |
1364 ms |
205592 KB |
Output is correct |
10 |
Correct |
128 ms |
7944 KB |
Output is correct |
11 |
Correct |
165 ms |
9580 KB |
Output is correct |
12 |
Correct |
59 ms |
5228 KB |
Output is correct |
13 |
Correct |
1494 ms |
206560 KB |
Output is correct |
14 |
Correct |
1604 ms |
206616 KB |
Output is correct |
15 |
Correct |
1737 ms |
205880 KB |
Output is correct |
16 |
Correct |
301 ms |
33612 KB |
Output is correct |
17 |
Correct |
259 ms |
31036 KB |
Output is correct |
18 |
Correct |
103 ms |
5648 KB |
Output is correct |
19 |
Correct |
1458 ms |
206612 KB |
Output is correct |
20 |
Correct |
1576 ms |
206564 KB |
Output is correct |
21 |
Correct |
1430 ms |
206596 KB |
Output is correct |
22 |
Correct |
132 ms |
8028 KB |
Output is correct |
23 |
Correct |
164 ms |
9528 KB |
Output is correct |
24 |
Correct |
60 ms |
5228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
22 ms |
6896 KB |
Output is correct |
8 |
Correct |
22 ms |
6896 KB |
Output is correct |
9 |
Correct |
22 ms |
6892 KB |
Output is correct |
10 |
Correct |
10 ms |
1432 KB |
Output is correct |
11 |
Correct |
9 ms |
1532 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
23 ms |
6892 KB |
Output is correct |
14 |
Correct |
23 ms |
6896 KB |
Output is correct |
15 |
Correct |
23 ms |
6768 KB |
Output is correct |
16 |
Correct |
6 ms |
760 KB |
Output is correct |
17 |
Correct |
7 ms |
760 KB |
Output is correct |
18 |
Correct |
4 ms |
504 KB |
Output is correct |
19 |
Correct |
1611 ms |
205624 KB |
Output is correct |
20 |
Correct |
1753 ms |
205748 KB |
Output is correct |
21 |
Correct |
1724 ms |
205872 KB |
Output is correct |
22 |
Correct |
339 ms |
32968 KB |
Output is correct |
23 |
Correct |
285 ms |
30396 KB |
Output is correct |
24 |
Correct |
96 ms |
5612 KB |
Output is correct |
25 |
Correct |
1605 ms |
205716 KB |
Output is correct |
26 |
Correct |
1604 ms |
205732 KB |
Output is correct |
27 |
Correct |
1364 ms |
205592 KB |
Output is correct |
28 |
Correct |
128 ms |
7944 KB |
Output is correct |
29 |
Correct |
165 ms |
9580 KB |
Output is correct |
30 |
Correct |
59 ms |
5228 KB |
Output is correct |
31 |
Correct |
1494 ms |
206560 KB |
Output is correct |
32 |
Correct |
1604 ms |
206616 KB |
Output is correct |
33 |
Correct |
1737 ms |
205880 KB |
Output is correct |
34 |
Correct |
301 ms |
33612 KB |
Output is correct |
35 |
Correct |
259 ms |
31036 KB |
Output is correct |
36 |
Correct |
103 ms |
5648 KB |
Output is correct |
37 |
Correct |
1458 ms |
206612 KB |
Output is correct |
38 |
Correct |
1576 ms |
206564 KB |
Output is correct |
39 |
Correct |
1430 ms |
206596 KB |
Output is correct |
40 |
Correct |
132 ms |
8028 KB |
Output is correct |
41 |
Correct |
164 ms |
9528 KB |
Output is correct |
42 |
Correct |
60 ms |
5228 KB |
Output is correct |
43 |
Correct |
1780 ms |
404048 KB |
Output is correct |
44 |
Correct |
1777 ms |
408328 KB |
Output is correct |
45 |
Correct |
1937 ms |
408232 KB |
Output is correct |
46 |
Correct |
304 ms |
36416 KB |
Output is correct |
47 |
Correct |
299 ms |
32276 KB |
Output is correct |
48 |
Correct |
97 ms |
5612 KB |
Output is correct |
49 |
Correct |
1864 ms |
408224 KB |
Output is correct |
50 |
Correct |
1625 ms |
408184 KB |
Output is correct |
51 |
Correct |
1535 ms |
408100 KB |
Output is correct |
52 |
Correct |
157 ms |
10680 KB |
Output is correct |
53 |
Correct |
186 ms |
12084 KB |
Output is correct |