#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 30001;
int N,M,C[MX],ans[MX];
vi mem[MX];
pi A[MX], c,d;
vpi q[MX];
int co[MX];
pi operator-(const pi& l, const pi& r) { return {l.f-r.f,l.s-r.s}; }
bool ok(pi x, pi y, pi z) {
ld X = atan2((ld)x.s,(ld)x.f), Y = atan2((ld)y.s,(ld)y.f), Z = atan2((ld)z.s,(ld)z.f);
while (Z < Y) Z += 2*M_PIl;
if (Y+M_PIl < Z) {
Y += 2*M_PIl;
swap(Y,Z);
}
while (Y > X) {
Y -= 2*M_PIl, Z -= 2*M_PIl;
}
while (Z < X) {
Y += 2*M_PIl, Z += 2*M_PIl;
}
return Y <= X;
}
void process(int x) {
for (int i: mem[x]) FOR(j,1,N+1) if (j != i && ok(A[j]-A[i],c-A[i],d-A[i])) co[C[j]] ++;
for (auto a: q[x]) ans[a.s] = co[a.f];
memset(co,0,sizeof co);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> M;
FOR(i,1,N+1) {
cin >> A[i].f >> A[i].s >> C[i];
mem[C[i]].pb(i);
}
cin >> c.f >> c.s >> d.f >> d.s;
int Q; cin >> Q;
F0R(i,Q) {
int f,g; cin >> f >> g;
q[f].pb({g,i});
}
FOR(i,1,M+1) process(i);
F0R(i,Q) cout << ans[i] << "\n";
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2610 ms |
2104 KB |
Output is correct |
2 |
Correct |
2605 ms |
2408 KB |
Output is correct |
3 |
Correct |
2597 ms |
2480 KB |
Output is correct |
4 |
Runtime error |
33 ms |
7192 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4013 ms |
7192 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2610 ms |
2104 KB |
Output is correct |
2 |
Correct |
2605 ms |
2408 KB |
Output is correct |
3 |
Correct |
2597 ms |
2480 KB |
Output is correct |
4 |
Runtime error |
33 ms |
7192 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |