#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
struct pt{ll x,y;pt(ll a=0,ll b=0):x(a),y(b){}};
ll cross(pt a,pt b){return a.x*b.y-a.y*b.x;}
bool operator < (pt a,pt b){return cross(a,b)<0;}
pt operator - (pt a,pt b){return pt(a.x-b.x,a.y-b.y);}
const int N=30050;
pt pts[N],X,Y,dir[N];
pair<int,pt> ord[N];
pair<pt,int> srt[N];
int fir[N],las[N],sz[N],c[N],side[N],idx[N],n,m,q;
int Find(pair<int,pt> p){return lower_bound(ord+1,ord+1+n,p)-ord;}
vector<pii> E[N],R[N];
struct BIT{
int sum[N];
void init(){for(int i=0;i<N;i++)sum[i]=0;}
BIT(){init();}
void Add(int i,int f){for(;i<N;i+=i&-i)sum[i]+=f;}
int Get(int i){int ans=0;for(;i;i-=i&-i)ans+=sum[i];return ans;}
int Get(int l,int r){return Get(r)-Get(l-1);}
}BT1,BT2;
const int M=100050;
ll ans[M];
int skip[M];
int main(){
scanf("%i %i",&n,&m);
for(int i=1;i<=n;i++)scanf("%lld %lld %i",&pts[i].x,&pts[i].y,&c[i]);
scanf("%lld %lld",&X.x,&X.y);
scanf("%lld %lld",&Y.x,&Y.y);
for(int i=1;i<=n;i++){
side[i]=(Y-X)<(pts[i]-X);
dir[i]=side[i]?pts[i]-Y:Y-pts[i];
ord[i]={c[i],dir[i]};
}
sort(ord+1,ord+1+n);
for(int i=1;i<=n;i++)idx[i]=Find({c[i],dir[i]});
for(int i=1;i<=m;i++)fir[i]=Find({i,Y-X});fir[m+1]=n+1;
for(int i=1;i<=m;i++)sz[i]=fir[i+1]-fir[i],las[i]=fir[i+1]-1;
for(int i=1;i<=n;i++)srt[i]={side[i]?pts[i]-X:X-pts[i],i};
sort(srt+1,srt+1+n);
scanf("%i",&q);
map<pii,int> was;
for(int i=1,a,b;i<=q;i++){
scanf("%i %i",&a,&b);
if(was[{a,b}]){
skip[i]=was[{a,b}];
continue;
}
was[{a,b}]=i;
if(sz[a]<sz[b])E[a].pb({b,i});
else R[b].pb({a,i});
}
BT1.init();BT2.init();
for(int i=1;i<=n;i++)if(!side[i])BT2.Add(idx[i],1);
for(int j=1;j<=n;j++){
int i=srt[j].second;
for(pii qu:E[c[i]]){
int o=Find({qu.first,dir[i]});
ans[qu.second]+=BT1.Get(o,las[qu.first])+BT2.Get(fir[qu.first],o-1);
}
if(side[i])BT1.Add(idx[i],1);
else BT2.Add(idx[i],-1);
}
BT1.init();BT2.init();
for(int i=1;i<=n;i++)BT1.Add(idx[i],1);
for(int j=1;j<=n;j++){
int i=srt[j].second;
for(pii qu:R[c[i]]){
int o=Find({qu.first,dir[i]});
if(side[i])ans[qu.second]+=BT1.Get(fir[qu.first],o-1);
else ans[qu.second]+=BT2.Get(o,las[qu.first]);
}
BT1.Add(idx[i],-1);
BT2.Add(idx[i],1);
}
for(int i=1;i<=q;i++)printf("%lld\n",ans[skip[i]?skip[i]:i]);
return 0;
}
Compilation message
dragon2.cpp: In function 'int main()':
dragon2.cpp:40:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
40 | for(int i=1;i<=m;i++)fir[i]=Find({i,Y-X});fir[m+1]=n+1;
| ^~~
dragon2.cpp:40:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
40 | for(int i=1;i<=m;i++)fir[i]=Find({i,Y-X});fir[m+1]=n+1;
| ^~~
dragon2.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
29 | scanf("%i %i",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
dragon2.cpp:30:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
30 | for(int i=1;i<=n;i++)scanf("%lld %lld %i",&pts[i].x,&pts[i].y,&c[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
31 | scanf("%lld %lld",&X.x,&X.y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
32 | scanf("%lld %lld",&Y.x,&Y.y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
44 | scanf("%i",&q);
| ~~~~~^~~~~~~~~
dragon2.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
47 | scanf("%i %i",&a,&b);
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4352 KB |
Output is correct |
2 |
Correct |
8 ms |
4352 KB |
Output is correct |
3 |
Correct |
27 ms |
4864 KB |
Output is correct |
4 |
Correct |
191 ms |
12920 KB |
Output is correct |
5 |
Correct |
145 ms |
13048 KB |
Output is correct |
6 |
Correct |
7 ms |
4608 KB |
Output is correct |
7 |
Correct |
8 ms |
4608 KB |
Output is correct |
8 |
Correct |
6 ms |
4480 KB |
Output is correct |
9 |
Correct |
5 ms |
4352 KB |
Output is correct |
10 |
Correct |
6 ms |
4352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
4728 KB |
Output is correct |
2 |
Correct |
66 ms |
4744 KB |
Output is correct |
3 |
Correct |
40 ms |
4736 KB |
Output is correct |
4 |
Correct |
36 ms |
4728 KB |
Output is correct |
5 |
Correct |
37 ms |
5112 KB |
Output is correct |
6 |
Correct |
34 ms |
4640 KB |
Output is correct |
7 |
Correct |
33 ms |
4856 KB |
Output is correct |
8 |
Correct |
35 ms |
4736 KB |
Output is correct |
9 |
Correct |
27 ms |
4728 KB |
Output is correct |
10 |
Correct |
28 ms |
4728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4352 KB |
Output is correct |
2 |
Correct |
8 ms |
4352 KB |
Output is correct |
3 |
Correct |
27 ms |
4864 KB |
Output is correct |
4 |
Correct |
191 ms |
12920 KB |
Output is correct |
5 |
Correct |
145 ms |
13048 KB |
Output is correct |
6 |
Correct |
7 ms |
4608 KB |
Output is correct |
7 |
Correct |
8 ms |
4608 KB |
Output is correct |
8 |
Correct |
6 ms |
4480 KB |
Output is correct |
9 |
Correct |
5 ms |
4352 KB |
Output is correct |
10 |
Correct |
6 ms |
4352 KB |
Output is correct |
11 |
Correct |
35 ms |
4728 KB |
Output is correct |
12 |
Correct |
66 ms |
4744 KB |
Output is correct |
13 |
Correct |
40 ms |
4736 KB |
Output is correct |
14 |
Correct |
36 ms |
4728 KB |
Output is correct |
15 |
Correct |
37 ms |
5112 KB |
Output is correct |
16 |
Correct |
34 ms |
4640 KB |
Output is correct |
17 |
Correct |
33 ms |
4856 KB |
Output is correct |
18 |
Correct |
35 ms |
4736 KB |
Output is correct |
19 |
Correct |
27 ms |
4728 KB |
Output is correct |
20 |
Correct |
28 ms |
4728 KB |
Output is correct |
21 |
Correct |
35 ms |
4728 KB |
Output is correct |
22 |
Correct |
64 ms |
4728 KB |
Output is correct |
23 |
Correct |
322 ms |
5276 KB |
Output is correct |
24 |
Correct |
761 ms |
13452 KB |
Output is correct |
25 |
Correct |
243 ms |
13688 KB |
Output is correct |
26 |
Correct |
202 ms |
14072 KB |
Output is correct |
27 |
Correct |
48 ms |
6648 KB |
Output is correct |
28 |
Correct |
46 ms |
6552 KB |
Output is correct |
29 |
Correct |
208 ms |
14296 KB |
Output is correct |
30 |
Correct |
174 ms |
15480 KB |
Output is correct |
31 |
Correct |
179 ms |
15736 KB |
Output is correct |
32 |
Correct |
204 ms |
15992 KB |
Output is correct |
33 |
Correct |
497 ms |
15736 KB |
Output is correct |
34 |
Correct |
187 ms |
15868 KB |
Output is correct |
35 |
Correct |
193 ms |
15548 KB |
Output is correct |
36 |
Correct |
195 ms |
15608 KB |
Output is correct |
37 |
Correct |
199 ms |
15864 KB |
Output is correct |
38 |
Correct |
457 ms |
15792 KB |
Output is correct |
39 |
Correct |
515 ms |
15812 KB |
Output is correct |
40 |
Correct |
508 ms |
15760 KB |
Output is correct |
41 |
Correct |
203 ms |
15856 KB |
Output is correct |
42 |
Correct |
216 ms |
15892 KB |
Output is correct |
43 |
Correct |
238 ms |
15812 KB |
Output is correct |
44 |
Correct |
55 ms |
7288 KB |
Output is correct |
45 |
Correct |
51 ms |
7288 KB |
Output is correct |
46 |
Correct |
52 ms |
7288 KB |
Output is correct |
47 |
Correct |
53 ms |
7288 KB |
Output is correct |
48 |
Correct |
52 ms |
7288 KB |
Output is correct |
49 |
Correct |
52 ms |
7288 KB |
Output is correct |