Submission #484489

#TimeUsernameProblemLanguageResultExecution timeMemory
484489jhnah917Dragon 2 (JOI17_dragon2)C++14
100 / 100
3038 ms2636 KiB
#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"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...