#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, M, Q, S[30000], E[30000];
alignas(32) ll X[30000], Y[30000];
alignas(32) ll Ax[30000], Ay[30000], Bx[30000], By[30000], Dir[30000];
struct{ ll x, y, c; } V[30000], A, B;
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> N >> M;
for(int i=0; i<N; i++) cin >> V[i].x >> V[i].y >> V[i].c, V[i].c--;
cin >> A.x >> A.y >> B.x >> B.y;
sort(V, V+N, [](auto a, auto b){ return a.c < b.c; });
for(int i=0; i<N; i++) X[i] = V[i].x, Y[i] = V[i].y;
memset(S, 0x3f, sizeof S);
memset(E, 0xc0, sizeof E);
for(int i=0; i<N; i++) S[V[i].c] = min(S[V[i].c], i), E[V[i].c] = max(E[V[i].c], i);
cin >> Q;
while(Q--){
int a, b, res = 0; cin >> a >> b; a--; b--;
int len = E[a] - S[a] + 1;
for(int i=0; i<len; i++) Ax[i] = A.x - X[S[a]+i];
for(int i=0; i<len; i++) Ay[i] = A.y - Y[S[a]+i];
for(int i=0; i<len; i++) Bx[i] = B.x - X[S[a]+i];
for(int i=0; i<len; i++) By[i] = B.y - Y[S[a]+i];
for(int i=0; i<len; i++) Dir[i] = Ax[i]*By[i] - Ay[i]*Bx[i];
for(int i=0; i<len; i++){
for(int j=S[b]; j<=E[b]; j++){
const ll dX = X[j] - X[S[a]+i], dY = Y[j] - Y[S[a]+i];
const ll cA = dX*Ay[i] - dY*Ax[i], cB = dX*By[i] - dY*Bx[i];
if(Dir[i] >= 0) res += cA <= 0 && cB >= 0;
else res += cA >= 0 && cB <= 0;
}
}
cout << res << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
716 KB |
Output is correct |
2 |
Correct |
16 ms |
724 KB |
Output is correct |
3 |
Correct |
19 ms |
728 KB |
Output is correct |
4 |
Correct |
29 ms |
868 KB |
Output is correct |
5 |
Correct |
29 ms |
780 KB |
Output is correct |
6 |
Correct |
2 ms |
588 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
10 ms |
764 KB |
Output is correct |
9 |
Correct |
9 ms |
716 KB |
Output is correct |
10 |
Correct |
10 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
742 ms |
2312 KB |
Output is correct |
2 |
Correct |
1455 ms |
1844 KB |
Output is correct |
3 |
Correct |
53 ms |
1772 KB |
Output is correct |
4 |
Correct |
11 ms |
1740 KB |
Output is correct |
5 |
Correct |
15 ms |
1668 KB |
Output is correct |
6 |
Correct |
721 ms |
2312 KB |
Output is correct |
7 |
Correct |
754 ms |
2316 KB |
Output is correct |
8 |
Correct |
752 ms |
2252 KB |
Output is correct |
9 |
Correct |
731 ms |
2316 KB |
Output is correct |
10 |
Correct |
730 ms |
2312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
716 KB |
Output is correct |
2 |
Correct |
16 ms |
724 KB |
Output is correct |
3 |
Correct |
19 ms |
728 KB |
Output is correct |
4 |
Correct |
29 ms |
868 KB |
Output is correct |
5 |
Correct |
29 ms |
780 KB |
Output is correct |
6 |
Correct |
2 ms |
588 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
10 ms |
764 KB |
Output is correct |
9 |
Correct |
9 ms |
716 KB |
Output is correct |
10 |
Correct |
10 ms |
768 KB |
Output is correct |
11 |
Correct |
742 ms |
2312 KB |
Output is correct |
12 |
Correct |
1455 ms |
1844 KB |
Output is correct |
13 |
Correct |
53 ms |
1772 KB |
Output is correct |
14 |
Correct |
11 ms |
1740 KB |
Output is correct |
15 |
Correct |
15 ms |
1668 KB |
Output is correct |
16 |
Correct |
721 ms |
2312 KB |
Output is correct |
17 |
Correct |
754 ms |
2316 KB |
Output is correct |
18 |
Correct |
752 ms |
2252 KB |
Output is correct |
19 |
Correct |
731 ms |
2316 KB |
Output is correct |
20 |
Correct |
730 ms |
2312 KB |
Output is correct |
21 |
Correct |
736 ms |
2336 KB |
Output is correct |
22 |
Correct |
1445 ms |
1848 KB |
Output is correct |
23 |
Correct |
1458 ms |
1860 KB |
Output is correct |
24 |
Correct |
341 ms |
2116 KB |
Output is correct |
25 |
Correct |
41 ms |
1860 KB |
Output is correct |
26 |
Correct |
37 ms |
1848 KB |
Output is correct |
27 |
Correct |
13 ms |
1740 KB |
Output is correct |
28 |
Correct |
13 ms |
1744 KB |
Output is correct |
29 |
Correct |
3038 ms |
2636 KB |
Output is correct |
30 |
Correct |
61 ms |
2408 KB |
Output is correct |
31 |
Correct |
42 ms |
2472 KB |
Output is correct |
32 |
Correct |
55 ms |
1920 KB |
Output is correct |
33 |
Correct |
413 ms |
2184 KB |
Output is correct |
34 |
Correct |
39 ms |
1860 KB |
Output is correct |
35 |
Correct |
44 ms |
1880 KB |
Output is correct |
36 |
Correct |
36 ms |
1924 KB |
Output is correct |
37 |
Correct |
36 ms |
1916 KB |
Output is correct |
38 |
Correct |
754 ms |
1908 KB |
Output is correct |
39 |
Correct |
612 ms |
1972 KB |
Output is correct |
40 |
Correct |
422 ms |
2008 KB |
Output is correct |
41 |
Correct |
2049 ms |
2408 KB |
Output is correct |
42 |
Correct |
1271 ms |
2000 KB |
Output is correct |
43 |
Correct |
1052 ms |
1968 KB |
Output is correct |
44 |
Correct |
1630 ms |
2444 KB |
Output is correct |
45 |
Correct |
815 ms |
2116 KB |
Output is correct |
46 |
Correct |
522 ms |
1868 KB |
Output is correct |
47 |
Correct |
719 ms |
1776 KB |
Output is correct |
48 |
Correct |
365 ms |
1856 KB |
Output is correct |
49 |
Correct |
251 ms |
1740 KB |
Output is correct |