#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct pct
{
int x,y,c;
int u1,u2;
}v[30005],s,e;
ll cross(pct a,pct b,pct c)
{
return 1LL*(b.x-a.x)*(c.y-a.y)-1LL*(c.x-a.x)*(b.y-a.y);
}
int stx[30005],sty[30005],edx[30005],edy[30005],n,m;
bool cmp(pct a,pct b)
{
bool ok1,ok2;
ok1=cross(s,e,a)>0;
ok2=cross(s,e,b)>0;
if (ok1!=ok2)
return ok1>ok2;
return cross(s,a,b)>0;
}
bool cmp2(pct a,pct b)
{
bool ok1,ok2;
ok1=cross(s,e,a)>0;
ok2=cross(s,e,b)>0;
if (ok1!=ok2)
return ok1>ok2;
return cross(e,a,b)>0;
}
void calc1()
{
sort(v,v+n,cmp);
int mini=0,i;
for(i=0;i<n;i++){
v[i].u1=i;
if (cross(s,e,v[i])>0)
mini=i+1;
}
int u=0;
for(i=mini;i<n;i++){
while(u<mini && cross(s,v[i],v[u])>0)
u++;
stx[i]=i;
edx[i]=u;
}
u=mini;
for(i=0;i<mini;i++){
while(u<n && cross(s,v[i],v[u])>0)
u++;
stx[i]=u;
edx[i]=i;
}
}
void calc2()
{
sort(v,v+n,cmp2);
int mini=0,i;
for(i=0;i<n;i++){
v[i].u2=i;
if (cross(s,e,v[i])>0)
mini=i+1;
}
int u=0;
for(i=mini;i<n;i++){
while(u<mini && cross(e,v[i],v[u])>0)
u++;
sty[i]=u;
edy[i]=i;
}
u=mini;
for(i=0;i<mini;i++){
while(u<n && cross(e,v[i],v[u])>0)
u++;
sty[i]=i;
edy[i]=u;
}
}
vector<pair<int,int>>g[30005];
map<pair<int,int>,int>mp;
int calc(int x,int y)
{
if (mp.find(make_pair(x,y))!=mp.end())
return mp[make_pair(x,y)];
int ans=0;
for(auto it:g[x])
for(auto it2:g[y]){
bool ok1=0,ok2=0;
if (!(edx[it.first]<=it2.first && it2.first<stx[it.first]))
ok1=1;
if (sty[it.second]<=it2.second && it2.second<edy[it.second])
ok2=1;
if (ok1 && ok2)
ans++;
}
mp[make_pair(x,y)]=ans;
return ans;
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int q,i;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
scanf("%d%d%d",&v[i].x,&v[i].y,&v[i].c);
scanf("%d%d%d%d",&s.x,&s.y,&e.x,&e.y);
calc1();
calc2();
for(i=0;i<n;i++)
g[v[i].c].push_back(make_pair(v[i].u1,v[i].u2));
scanf("%d",&q);
int x,y;
for(i=1;i<=q;i++){
scanf("%d%d",&x,&y);
printf("%d\n",calc(x,y));
}
return 0;
}
Compilation message
dragon2.cpp: In function 'int main()':
dragon2.cpp:105:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
105 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
dragon2.cpp:107:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
107 | scanf("%d%d%d",&v[i].x,&v[i].y,&v[i].c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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%d%d",&s.x,&s.y,&e.x,&e.y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:113:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
113 | scanf("%d",&q);
| ~~~~~^~~~~~~~~
dragon2.cpp:116:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
116 | scanf("%d%d",&x,&y);
| ~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1260 KB |
Output is correct |
2 |
Correct |
15 ms |
1260 KB |
Output is correct |
3 |
Correct |
27 ms |
1644 KB |
Output is correct |
4 |
Correct |
117 ms |
8556 KB |
Output is correct |
5 |
Correct |
117 ms |
8684 KB |
Output is correct |
6 |
Correct |
4 ms |
1388 KB |
Output is correct |
7 |
Correct |
4 ms |
1388 KB |
Output is correct |
8 |
Correct |
6 ms |
1260 KB |
Output is correct |
9 |
Correct |
6 ms |
1260 KB |
Output is correct |
10 |
Correct |
5 ms |
1260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
641 ms |
3112 KB |
Output is correct |
2 |
Correct |
1238 ms |
3184 KB |
Output is correct |
3 |
Correct |
52 ms |
3308 KB |
Output is correct |
4 |
Correct |
34 ms |
3180 KB |
Output is correct |
5 |
Correct |
30 ms |
3436 KB |
Output is correct |
6 |
Correct |
298 ms |
3120 KB |
Output is correct |
7 |
Correct |
258 ms |
3256 KB |
Output is correct |
8 |
Correct |
316 ms |
3052 KB |
Output is correct |
9 |
Correct |
337 ms |
2992 KB |
Output is correct |
10 |
Correct |
264 ms |
3052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1260 KB |
Output is correct |
2 |
Correct |
15 ms |
1260 KB |
Output is correct |
3 |
Correct |
27 ms |
1644 KB |
Output is correct |
4 |
Correct |
117 ms |
8556 KB |
Output is correct |
5 |
Correct |
117 ms |
8684 KB |
Output is correct |
6 |
Correct |
4 ms |
1388 KB |
Output is correct |
7 |
Correct |
4 ms |
1388 KB |
Output is correct |
8 |
Correct |
6 ms |
1260 KB |
Output is correct |
9 |
Correct |
6 ms |
1260 KB |
Output is correct |
10 |
Correct |
5 ms |
1260 KB |
Output is correct |
11 |
Correct |
641 ms |
3112 KB |
Output is correct |
12 |
Correct |
1238 ms |
3184 KB |
Output is correct |
13 |
Correct |
52 ms |
3308 KB |
Output is correct |
14 |
Correct |
34 ms |
3180 KB |
Output is correct |
15 |
Correct |
30 ms |
3436 KB |
Output is correct |
16 |
Correct |
298 ms |
3120 KB |
Output is correct |
17 |
Correct |
258 ms |
3256 KB |
Output is correct |
18 |
Correct |
316 ms |
3052 KB |
Output is correct |
19 |
Correct |
337 ms |
2992 KB |
Output is correct |
20 |
Correct |
264 ms |
3052 KB |
Output is correct |
21 |
Correct |
646 ms |
3060 KB |
Output is correct |
22 |
Correct |
1238 ms |
3308 KB |
Output is correct |
23 |
Correct |
1192 ms |
3608 KB |
Output is correct |
24 |
Correct |
574 ms |
10812 KB |
Output is correct |
25 |
Correct |
180 ms |
10732 KB |
Output is correct |
26 |
Correct |
160 ms |
11116 KB |
Output is correct |
27 |
Correct |
36 ms |
4972 KB |
Output is correct |
28 |
Correct |
37 ms |
4972 KB |
Output is correct |
29 |
Correct |
1612 ms |
10932 KB |
Output is correct |
30 |
Correct |
167 ms |
10732 KB |
Output is correct |
31 |
Correct |
150 ms |
10996 KB |
Output is correct |
32 |
Correct |
161 ms |
10860 KB |
Output is correct |
33 |
Correct |
538 ms |
10860 KB |
Output is correct |
34 |
Correct |
155 ms |
10988 KB |
Output is correct |
35 |
Correct |
135 ms |
10860 KB |
Output is correct |
36 |
Correct |
152 ms |
10860 KB |
Output is correct |
37 |
Correct |
155 ms |
11160 KB |
Output is correct |
38 |
Correct |
834 ms |
11208 KB |
Output is correct |
39 |
Correct |
714 ms |
11068 KB |
Output is correct |
40 |
Correct |
579 ms |
10860 KB |
Output is correct |
41 |
Correct |
1356 ms |
10808 KB |
Output is correct |
42 |
Correct |
982 ms |
10736 KB |
Output is correct |
43 |
Correct |
855 ms |
11148 KB |
Output is correct |
44 |
Correct |
1061 ms |
4496 KB |
Output is correct |
45 |
Correct |
493 ms |
4460 KB |
Output is correct |
46 |
Correct |
319 ms |
4308 KB |
Output is correct |
47 |
Correct |
525 ms |
4460 KB |
Output is correct |
48 |
Correct |
356 ms |
4376 KB |
Output is correct |
49 |
Correct |
265 ms |
4332 KB |
Output is correct |