#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<complex>
using namespace std;
const int MN=30000,MQ=100000,BS=15,RQ=300;
typedef complex<long long> point;
long long op(point P1,point P2)
{
return imag((conj(P1)*P2));
}
namespace std{
bool operator<(point P1,point P2)
{
return op(P1,P2)>0;
}
};
template<class T> class sumBIT
{
private:
T *bit;
int S;
public:
sumBIT(int S0){
S=S0;
bit=(T *)calloc(sizeof(T),1<<S);
}
void add(int i,T k){
int p=i+1;
while(p<1<<S){
bit[p]+=k;
p+=p&-p;
}
}
T sum(int p){
T ret=0;
while(p>0){
ret+=bit[p];
p-=p&-p;
}
return ret;
}
T rag(int a,int b){
return sum(b)-sum(a);
}
};
int main()
{
int n,m;
scanf("%d%d",&n,&m);
static point P[MN];
static int C[MN];
for(int i=0;i<n;i++){
long long x,y;
scanf("%lld%lld%d",&x,&y,C+i);
P[i]=point(x,y);
C[i]--;
}
long long d1,e1,d2,e2;
scanf("%lld%lld%lld%lld",&d1,&e1,&d2,&e2);
point X=point(d1,e1),Y=point(d2,e2);
static bool F[MN];
for(int i=0;i<n;i++){
F[i]=(op(Y-X,P[i]-X)>0);
}
static point A[MN];
static pair<int,point> AA[MN];
for(int i=0;i<n;i++){
A[i]=(F[i]?P[i]-Y:Y-P[i]);
AA[i]=make_pair(C[i],A[i]);
}
sort(AA,AA+n);
static int D[MN];
for(int i=0;i<n;i++){
D[i]=lower_bound(AA,AA+n,make_pair(C[i],A[i]))-AA;
}
static int T[MN+1];
for(int i=0;i<=m;i++){
T[i]=lower_bound(AA,AA+n,make_pair(i,Y-X))-AA;
}
static pair<point,int> Pr[MN];
for(int i=0;i<n;i++){
Pr[i]=make_pair(F[i]?P[i]-X:X-P[i],i);
}
sort(Pr,Pr+n);
int Q;
scanf("%d",&Q);
static int as[MQ],bs[MQ];
for(int i=0;i<Q;i++){
scanf("%d%d",as+i,bs+i);
as[i]--,bs[i]--;
}
static vector<int> V[MN],VN[MN];
for(int i=0;i<Q;i++){
V[as[i]].push_back(bs[i]);
VN[as[i]].push_back(i);
}
static vector<int> V2[MN],VN2[MN];
for(int i=0;i<Q;i++){
if(V[as[i]].size()>=RQ){
V2[bs[i]].push_back(as[i]);
VN2[bs[i]].push_back(i);
}
}
static long long ans[MQ]={0};
sumBIT<int> seg0(BS),seg1(BS);
for(int i=0;i<n;i++){
if(!F[i]){
seg1.add(D[i],1);
}
}
for(int t=0;t<n;t++){
int i=Pr[t].second;
int a=C[i];
if(F[i]){
if(V[a].size()<RQ){
for(int k=0;k<V[a].size();k++){
int b=V[a][k],l=VN[a][k];
int L=lower_bound(AA,AA+n,make_pair(b,A[i]))-AA;
ans[l]+=seg0.rag(L,T[b+1])+seg1.rag(T[b],L);
}
}
seg0.add(D[i],1);
}
else{
if(V[a].size()<RQ){
for(int k=0;k<V[a].size();k++){
int b=V[a][k],l=VN[a][k];
int L=lower_bound(AA,AA+n,make_pair(b,A[i]))-AA;
ans[l]+=seg0.rag(L,T[b+1])+seg1.rag(T[b],L);
}
}
seg1.add(D[i],-1);
}
}
sumBIT<int> seg2(BS),seg3(BS);
for(int i=0;i<n;i++){
seg2.add(D[i],1);
}
for(int t=0;t<n;t++){
int i=Pr[t].second;
int b=C[i];
if(F[i]){
for(int k=0;k<V2[b].size();k++){
int a=V2[b][k],l=VN2[b][k];
int L=lower_bound(AA,AA+n,make_pair(a,A[i]))-AA;
ans[l]+=seg2.rag(T[a],L);
}
seg2.add(D[i],-1);
seg3.add(D[i],1);
}
else{
for(int k=0;k<V2[b].size();k++){
int a=V2[b][k],l=VN2[b][k];
int L=lower_bound(AA,AA+n,make_pair(a,A[i]))-AA;
ans[l]+=seg3.rag(L,T[a+1]);
}
seg2.add(D[i],-1);
seg3.add(D[i],1);
}
}
for(int t=0;t<Q;t++){
printf("%lld\n",ans[t]);
}
return 0;
}
Compilation message
dragon2.cpp: In function 'int main()':
dragon2.cpp:135:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=0;k<V[a].size();k++){
^
dragon2.cpp:145:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=0;k<V[a].size();k++){
^
dragon2.cpp:162:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=0;k<V2[b].size();k++){
^
dragon2.cpp:171:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=0;k<V2[b].size();k++){
^
dragon2.cpp:68:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
^
dragon2.cpp:73:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%d",&x,&y,C+i);
^
dragon2.cpp:78:44: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld%lld",&d1,&e1,&d2,&e2);
^
dragon2.cpp:105:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&Q);
^
dragon2.cpp:108:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",as+i,bs+i);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8816 KB |
Output is correct |
2 |
Correct |
6 ms |
8816 KB |
Output is correct |
3 |
Correct |
29 ms |
8948 KB |
Output is correct |
4 |
Correct |
96 ms |
10004 KB |
Output is correct |
5 |
Correct |
83 ms |
10268 KB |
Output is correct |
6 |
Correct |
6 ms |
8948 KB |
Output is correct |
7 |
Correct |
3 ms |
8948 KB |
Output is correct |
8 |
Correct |
3 ms |
8816 KB |
Output is correct |
9 |
Correct |
3 ms |
8816 KB |
Output is correct |
10 |
Correct |
3 ms |
8816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
8816 KB |
Output is correct |
2 |
Correct |
69 ms |
8816 KB |
Output is correct |
3 |
Correct |
43 ms |
8816 KB |
Output is correct |
4 |
Correct |
33 ms |
8816 KB |
Output is correct |
5 |
Correct |
33 ms |
8816 KB |
Output is correct |
6 |
Correct |
33 ms |
8816 KB |
Output is correct |
7 |
Correct |
33 ms |
8816 KB |
Output is correct |
8 |
Correct |
33 ms |
8816 KB |
Output is correct |
9 |
Correct |
16 ms |
8816 KB |
Output is correct |
10 |
Correct |
19 ms |
8816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8816 KB |
Output is correct |
2 |
Correct |
6 ms |
8816 KB |
Output is correct |
3 |
Correct |
29 ms |
8948 KB |
Output is correct |
4 |
Correct |
96 ms |
10004 KB |
Output is correct |
5 |
Correct |
83 ms |
10268 KB |
Output is correct |
6 |
Correct |
6 ms |
8948 KB |
Output is correct |
7 |
Correct |
3 ms |
8948 KB |
Output is correct |
8 |
Correct |
3 ms |
8816 KB |
Output is correct |
9 |
Correct |
3 ms |
8816 KB |
Output is correct |
10 |
Correct |
3 ms |
8816 KB |
Output is correct |
11 |
Correct |
36 ms |
8816 KB |
Output is correct |
12 |
Correct |
69 ms |
8816 KB |
Output is correct |
13 |
Correct |
43 ms |
8816 KB |
Output is correct |
14 |
Correct |
33 ms |
8816 KB |
Output is correct |
15 |
Correct |
33 ms |
8816 KB |
Output is correct |
16 |
Correct |
33 ms |
8816 KB |
Output is correct |
17 |
Correct |
33 ms |
8816 KB |
Output is correct |
18 |
Correct |
33 ms |
8816 KB |
Output is correct |
19 |
Correct |
16 ms |
8816 KB |
Output is correct |
20 |
Correct |
19 ms |
8816 KB |
Output is correct |
21 |
Correct |
33 ms |
8816 KB |
Output is correct |
22 |
Correct |
69 ms |
8816 KB |
Output is correct |
23 |
Correct |
416 ms |
8948 KB |
Output is correct |
24 |
Correct |
879 ms |
10004 KB |
Output is correct |
25 |
Correct |
169 ms |
10400 KB |
Output is correct |
26 |
Correct |
133 ms |
11060 KB |
Output is correct |
27 |
Correct |
33 ms |
9740 KB |
Output is correct |
28 |
Correct |
43 ms |
9740 KB |
Output is correct |
29 |
Correct |
109 ms |
12540 KB |
Output is correct |
30 |
Correct |
466 ms |
10796 KB |
Output is correct |
31 |
Correct |
113 ms |
11060 KB |
Output is correct |
32 |
Correct |
106 ms |
12540 KB |
Output is correct |
33 |
Correct |
1008 ms |
10796 KB |
Output is correct |
34 |
Correct |
113 ms |
11060 KB |
Output is correct |
35 |
Correct |
113 ms |
12564 KB |
Output is correct |
36 |
Correct |
109 ms |
10796 KB |
Output is correct |
37 |
Correct |
113 ms |
11060 KB |
Output is correct |
38 |
Correct |
353 ms |
12248 KB |
Output is correct |
39 |
Correct |
913 ms |
11720 KB |
Output is correct |
40 |
Correct |
1043 ms |
10796 KB |
Output is correct |
41 |
Correct |
126 ms |
12284 KB |
Output is correct |
42 |
Correct |
136 ms |
12292 KB |
Output is correct |
43 |
Correct |
139 ms |
12128 KB |
Output is correct |
44 |
Correct |
56 ms |
9900 KB |
Output is correct |
45 |
Correct |
36 ms |
9872 KB |
Output is correct |
46 |
Correct |
43 ms |
9900 KB |
Output is correct |
47 |
Correct |
49 ms |
9740 KB |
Output is correct |
48 |
Correct |
46 ms |
9740 KB |
Output is correct |
49 |
Correct |
49 ms |
9740 KB |
Output is correct |