#pragma GCC optimize("Ofast","unroll-all-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef complex<int> point;
int cross_product(point a,const point &b) {
a.imag(-a.imag());
return (a*b).imag();
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin >> N >> M;
vector<pair<point,int>> dragons(N);
for(auto&[a,b]:dragons) {
int u,v;cin>>u>>v>>b;
a = {u,v};
}
point d1,d2;
{
int a,b;cin>>a>>b;
d1 = {a,b};
cin>>a>>b;
d2 = {a,b};
}
vector<vector<point>> left(M+1),right(M+1);
for(auto&[a,b]:dragons) {
if(cross_product(d2-d1,a-d1)<0)left[b].emplace_back(a);
else right[b].emplace_back(a);
}
map<pair<int,int>,int> lookup;
int Q;
cin >> Q;
for(int i=1;i<=Q;i++) {
int u,v;cin>>u>>v;
if(lookup.count({u,v})) {
cout << lookup[{u,v}] << '\n';
continue;
}
int ans = 0;
for(point&x:left[u]) {
for(point&y:left[v]) {
if(cross_product(y-x,d1-x)>0 and cross_product(y-x,d2-x)<0)ans++;
}
for(point&y:right[v]) {
if(cross_product(y-x,d1-x)>0 and cross_product(y-x,d2-x)<0)ans++;
}
}
for(point&x:right[u]) {
for(point&y:left[v]) {
if(cross_product(y-x,d1-x)<0 and cross_product(y-x,d2-x)>0)ans++;
}
for(point&y:right[v]) {
if(cross_product(y-x,d1-x)<0 and cross_product(y-x,d2-x)>0)ans++;
}
}
cout << ans << '\n';
lookup[{u,v}]=ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
600 KB |
Output is correct |
2 |
Correct |
9 ms |
604 KB |
Output is correct |
3 |
Correct |
19 ms |
860 KB |
Output is correct |
4 |
Correct |
72 ms |
7864 KB |
Output is correct |
5 |
Correct |
84 ms |
7860 KB |
Output is correct |
6 |
Correct |
2 ms |
720 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
5 ms |
592 KB |
Output is correct |
9 |
Correct |
5 ms |
652 KB |
Output is correct |
10 |
Correct |
6 ms |
680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
641 ms |
2340 KB |
Output is correct |
2 |
Correct |
953 ms |
2516 KB |
Output is correct |
3 |
Correct |
24 ms |
2396 KB |
Output is correct |
4 |
Correct |
8 ms |
2396 KB |
Output is correct |
5 |
Correct |
14 ms |
4096 KB |
Output is correct |
6 |
Correct |
773 ms |
2264 KB |
Output is correct |
7 |
Correct |
795 ms |
2348 KB |
Output is correct |
8 |
Correct |
375 ms |
2264 KB |
Output is correct |
9 |
Correct |
395 ms |
2248 KB |
Output is correct |
10 |
Correct |
429 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
600 KB |
Output is correct |
2 |
Correct |
9 ms |
604 KB |
Output is correct |
3 |
Correct |
19 ms |
860 KB |
Output is correct |
4 |
Correct |
72 ms |
7864 KB |
Output is correct |
5 |
Correct |
84 ms |
7860 KB |
Output is correct |
6 |
Correct |
2 ms |
720 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
5 ms |
592 KB |
Output is correct |
9 |
Correct |
5 ms |
652 KB |
Output is correct |
10 |
Correct |
6 ms |
680 KB |
Output is correct |
11 |
Correct |
641 ms |
2340 KB |
Output is correct |
12 |
Correct |
953 ms |
2516 KB |
Output is correct |
13 |
Correct |
24 ms |
2396 KB |
Output is correct |
14 |
Correct |
8 ms |
2396 KB |
Output is correct |
15 |
Correct |
14 ms |
4096 KB |
Output is correct |
16 |
Correct |
773 ms |
2264 KB |
Output is correct |
17 |
Correct |
795 ms |
2348 KB |
Output is correct |
18 |
Correct |
375 ms |
2264 KB |
Output is correct |
19 |
Correct |
395 ms |
2248 KB |
Output is correct |
20 |
Correct |
429 ms |
2260 KB |
Output is correct |
21 |
Correct |
604 ms |
2332 KB |
Output is correct |
22 |
Correct |
944 ms |
2416 KB |
Output is correct |
23 |
Correct |
892 ms |
2392 KB |
Output is correct |
24 |
Correct |
396 ms |
9540 KB |
Output is correct |
25 |
Correct |
75 ms |
9792 KB |
Output is correct |
26 |
Correct |
77 ms |
11092 KB |
Output is correct |
27 |
Correct |
17 ms |
5212 KB |
Output is correct |
28 |
Correct |
13 ms |
5212 KB |
Output is correct |
29 |
Correct |
1527 ms |
10732 KB |
Output is correct |
30 |
Correct |
82 ms |
10700 KB |
Output is correct |
31 |
Correct |
68 ms |
11092 KB |
Output is correct |
32 |
Correct |
80 ms |
10832 KB |
Output is correct |
33 |
Correct |
352 ms |
10708 KB |
Output is correct |
34 |
Correct |
70 ms |
11004 KB |
Output is correct |
35 |
Correct |
74 ms |
10832 KB |
Output is correct |
36 |
Correct |
70 ms |
10756 KB |
Output is correct |
37 |
Correct |
68 ms |
11092 KB |
Output is correct |
38 |
Correct |
496 ms |
10840 KB |
Output is correct |
39 |
Correct |
456 ms |
10836 KB |
Output is correct |
40 |
Correct |
351 ms |
10776 KB |
Output is correct |
41 |
Correct |
1508 ms |
10668 KB |
Output is correct |
42 |
Correct |
957 ms |
10708 KB |
Output is correct |
43 |
Correct |
665 ms |
11200 KB |
Output is correct |
44 |
Correct |
1008 ms |
4144 KB |
Output is correct |
45 |
Correct |
514 ms |
4436 KB |
Output is correct |
46 |
Correct |
341 ms |
4180 KB |
Output is correct |
47 |
Correct |
730 ms |
4208 KB |
Output is correct |
48 |
Correct |
389 ms |
4244 KB |
Output is correct |
49 |
Correct |
241 ms |
4180 KB |
Output is correct |