#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
using cp = complex<long double>;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m;
cin >> n >> m;
vector<cp> dragon[m];
for(int i=0;i<n;i++) {
int a, b, c;
cin >> a >> b >> c;
dragon[c-1].push_back({a,b});
}
if(1) {
cp st, nd;
int d1, e1, d2, e2;
cin >> d1 >> e1 >> d2 >> e2;
st = cp(d1,e1);
nd = cp(d2,e2);
for(int i=0;i<m;i++)
for(auto &j: dragon[i])
j = (j - st) / (nd - st);
}
map<pair<int,int>,int> memo;
int q;
cin >> q;
for(int f,g;q--;) {
cin >> f >> g;
f--; g--;
if(!memo.count({f,g})) {
int cur = 0;
for(auto c1: dragon[f])
for(auto c2: dragon[g])
if((c2 / c1).imag() * c1.imag() < 0 && ((c2 - cp(1)) / (c1 - cp(1))).imag() * c1.imag() > 0)
cur++;
memo[{f,g}]=cur;
}
cout << memo[{f,g}] << "\n";
}
}
Compilation message (stderr)
dragon2.cpp: In function 'int main()':
dragon2.cpp:13:40: warning: narrowing conversion of 'a' from 'int' to 'long double' [-Wnarrowing]
13 | dragon[c-1].push_back({a,b});
| ^
dragon2.cpp:13:42: warning: narrowing conversion of 'b' from 'int' to 'long double' [-Wnarrowing]
13 | dragon[c-1].push_back({a,b});
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |