#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 of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | for(int k=0;k<V[a].size();k++){
| ~^~~~~~~~~~~~
dragon2.cpp:145:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
145 | for(int k=0;k<V[a].size();k++){
| ~^~~~~~~~~~~~
dragon2.cpp:162:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
162 | for(int k=0;k<V2[b].size();k++){
| ~^~~~~~~~~~~~~
dragon2.cpp:171:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
171 | for(int k=0;k<V2[b].size();k++){
| ~^~~~~~~~~~~~~
dragon2.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
dragon2.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | scanf("%lld%lld%d",&x,&y,C+i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
78 | scanf("%lld%lld%lld%lld",&d1,&e1,&d2,&e2);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:105:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | scanf("%d",&Q);
| ~~~~~^~~~~~~~~
dragon2.cpp:108:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
108 | scanf("%d%d",as+i,bs+i);
| ~~~~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3412 KB |
Output is correct |
2 |
Correct |
6 ms |
3412 KB |
Output is correct |
3 |
Correct |
27 ms |
3700 KB |
Output is correct |
4 |
Correct |
86 ms |
6412 KB |
Output is correct |
5 |
Correct |
47 ms |
6564 KB |
Output is correct |
6 |
Correct |
4 ms |
3540 KB |
Output is correct |
7 |
Correct |
4 ms |
3540 KB |
Output is correct |
8 |
Correct |
4 ms |
3412 KB |
Output is correct |
9 |
Correct |
3 ms |
3412 KB |
Output is correct |
10 |
Correct |
3 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
6216 KB |
Output is correct |
2 |
Correct |
56 ms |
6220 KB |
Output is correct |
3 |
Correct |
33 ms |
6220 KB |
Output is correct |
4 |
Correct |
26 ms |
6156 KB |
Output is correct |
5 |
Correct |
27 ms |
6340 KB |
Output is correct |
6 |
Correct |
26 ms |
6008 KB |
Output is correct |
7 |
Correct |
25 ms |
6036 KB |
Output is correct |
8 |
Correct |
26 ms |
6044 KB |
Output is correct |
9 |
Correct |
20 ms |
6064 KB |
Output is correct |
10 |
Correct |
19 ms |
6100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3412 KB |
Output is correct |
2 |
Correct |
6 ms |
3412 KB |
Output is correct |
3 |
Correct |
27 ms |
3700 KB |
Output is correct |
4 |
Correct |
86 ms |
6412 KB |
Output is correct |
5 |
Correct |
47 ms |
6564 KB |
Output is correct |
6 |
Correct |
4 ms |
3540 KB |
Output is correct |
7 |
Correct |
4 ms |
3540 KB |
Output is correct |
8 |
Correct |
4 ms |
3412 KB |
Output is correct |
9 |
Correct |
3 ms |
3412 KB |
Output is correct |
10 |
Correct |
3 ms |
3412 KB |
Output is correct |
11 |
Correct |
30 ms |
6216 KB |
Output is correct |
12 |
Correct |
56 ms |
6220 KB |
Output is correct |
13 |
Correct |
33 ms |
6220 KB |
Output is correct |
14 |
Correct |
26 ms |
6156 KB |
Output is correct |
15 |
Correct |
27 ms |
6340 KB |
Output is correct |
16 |
Correct |
26 ms |
6008 KB |
Output is correct |
17 |
Correct |
25 ms |
6036 KB |
Output is correct |
18 |
Correct |
26 ms |
6044 KB |
Output is correct |
19 |
Correct |
20 ms |
6064 KB |
Output is correct |
20 |
Correct |
19 ms |
6100 KB |
Output is correct |
21 |
Correct |
29 ms |
6252 KB |
Output is correct |
22 |
Correct |
52 ms |
6160 KB |
Output is correct |
23 |
Correct |
326 ms |
6364 KB |
Output is correct |
24 |
Correct |
661 ms |
9316 KB |
Output is correct |
25 |
Correct |
124 ms |
9520 KB |
Output is correct |
26 |
Correct |
91 ms |
10284 KB |
Output is correct |
27 |
Correct |
30 ms |
7372 KB |
Output is correct |
28 |
Correct |
34 ms |
7508 KB |
Output is correct |
29 |
Correct |
93 ms |
11768 KB |
Output is correct |
30 |
Correct |
471 ms |
11676 KB |
Output is correct |
31 |
Correct |
83 ms |
12124 KB |
Output is correct |
32 |
Correct |
117 ms |
13372 KB |
Output is correct |
33 |
Correct |
776 ms |
11828 KB |
Output is correct |
34 |
Correct |
88 ms |
12080 KB |
Output is correct |
35 |
Correct |
87 ms |
13312 KB |
Output is correct |
36 |
Correct |
95 ms |
11784 KB |
Output is correct |
37 |
Correct |
104 ms |
12184 KB |
Output is correct |
38 |
Correct |
304 ms |
13168 KB |
Output is correct |
39 |
Correct |
725 ms |
12696 KB |
Output is correct |
40 |
Correct |
753 ms |
11872 KB |
Output is correct |
41 |
Correct |
88 ms |
13132 KB |
Output is correct |
42 |
Correct |
100 ms |
13040 KB |
Output is correct |
43 |
Correct |
102 ms |
13140 KB |
Output is correct |
44 |
Correct |
37 ms |
8544 KB |
Output is correct |
45 |
Correct |
35 ms |
8424 KB |
Output is correct |
46 |
Correct |
38 ms |
8468 KB |
Output is correct |
47 |
Correct |
37 ms |
8272 KB |
Output is correct |
48 |
Correct |
35 ms |
8244 KB |
Output is correct |
49 |
Correct |
36 ms |
8268 KB |
Output is correct |