#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define rb(x) ((x)&(-(x)))
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
pll operator + (const pll &a, const pll &b) { return pll(a.first+b.first, a.second+b.second); }
pll operator - (const pll &a, const pll &b) { return pll(a.first-b.first, a.second-b.second); }
ll operator * (const pll &a, const pll &b) { return a.first*b.second - b.first*a.second; }
ll ccw(const pll &a, const pll &b, const pll &c) { return a*b + b*c + c*a; }
const int MAXN = 30005;
const int MAXK = 30005;
const int MAXQ = 100005;
const int MX = 60055;
struct EVT {
EVT(int p, int x, int i) : p(p), x(x), i(i) {}
int p, x, i;
bool operator < (const EVT &t) const {
if(x != t.x) return x < t.x;
return p < t.p;
}
};
struct BIT {
int d[MX];
void init() { memset(d, 0, MX<<2); }
void init(int x) {
for(x += 5; x < MX; x += rb(x))
d[x] = 0;
}
void upd(int x, int r) {
for(x += 5; x < MX; x += rb(x))
d[x] += r;
}
int get(int x) {
int r = 0; for(x += 5; x; x -= rb(x))
r += d[x];
return r;
}
int get(int s, int e) { return s > e ? 0 : get(e)-get(s-1); }
} bit;
pll P[MAXN*2];
int A[MAXN], O[MAXN*2];
vector<int> AV[MAXK];
int L[MAXN], LS[MAXN], LE[MAXN];
int R[MAXN], RS[MAXN], RE[MAXN];
int B[MAXQ], C[MAXQ];
int Ans[MAXQ];
int N, K, Q;
void cal(int a, int b, int &ret) {
vector<EVT> EV;
for(int v : AV[b]) EV.eb(0, L[v], v);
for(int v : AV[a]) {
EV.eb(1, LS[v]-1, v);
EV.eb(2, LE[v], v);
}
sorv(EV);
for(auto &ev : EV) {
int t = ev.p, i = ev.i;
if(!t) bit.upd(R[i], 1);
else if(1 == t) ret -= bit.get(RS[i], RE[i]);
else ret += bit.get(RS[i], RE[i]);
}
for(int v : AV[b]) bit.init(R[v]);
}
void precal() {
iota(O, O+(N<<1), 4);
for(int i = 0; i <= N+1; i++)
P[i<<1|1] = P[0] + P[0] - P[i<<1];
sort(O, O+(N<<1), [&](int a, int b) {
bool af = ccw(P[3], P[0], P[a]) < 0;
bool bf = ccw(P[3], P[0], P[b]) < 0;
if(af != bf) return af;
return ccw(P[a], P[0], P[b]) < 0;
});
for(int i = 0, v; i < N; i++) {
v = O[i];
L[(v>>1)-1] = i + ((v&1) ? N : 0);
v >>= 1; v--;
LS[v] = i; LE[v] = i+N;
}
for(int i = 0; i <= N+1; i++)
P[i<<1|1] = P[2] + P[2] - P[i<<1];
sort(O, O+(N<<1), [&](int a, int b) {
bool af = ccw(P[1], P[2], P[a]) < 0;
bool bf = ccw(P[1], P[2], P[b]) < 0;
if(af != bf) return af;
return ccw(P[a], P[2], P[b]) < 0;
});
for(int i = 0, v; i < N; i++) {
v = O[i];
R[(v>>1)-1] = i + ((v&1) ? N : 0);
v >>= 1; v--;
RS[v] = i; RE[v] = i+N;
}
for(int i = 1; i <= N; i++) {
L[i]++; LS[i]++; LE[i]++;
R[i]++; RS[i]++; RE[i]++;
}
}
int main() {
ios::sync_with_stdio(false);
cin >> N >> K;
for(int i = 1; i <= N; i++) {
cin >> P[(i+1)<<1].first >> P[(i+1)<<1].second >> A[i];
AV[A[i]].eb(i);
}
cin >> P[0].first >> P[0].second >> P[2].first >> P[2].second;
cin >> Q;
for(int i = 1; i <= Q; i++) cin >> B[i] >> C[i];
precal();
for(int i = 1; i <= Q; i++) cal(B[i], C[i], Ans[i]);
for(int i = 1; i <= Q; i++) printf("%d\n", Ans[i]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1528 KB |
Output is correct |
2 |
Correct |
12 ms |
1404 KB |
Output is correct |
3 |
Correct |
52 ms |
1528 KB |
Output is correct |
4 |
Correct |
121 ms |
3624 KB |
Output is correct |
5 |
Correct |
69 ms |
3708 KB |
Output is correct |
6 |
Correct |
7 ms |
1660 KB |
Output is correct |
7 |
Correct |
7 ms |
1528 KB |
Output is correct |
8 |
Correct |
7 ms |
1528 KB |
Output is correct |
9 |
Correct |
6 ms |
1528 KB |
Output is correct |
10 |
Correct |
6 ms |
1524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
4788 KB |
Output is correct |
2 |
Correct |
122 ms |
4496 KB |
Output is correct |
3 |
Correct |
63 ms |
4216 KB |
Output is correct |
4 |
Correct |
52 ms |
4216 KB |
Output is correct |
5 |
Correct |
54 ms |
4600 KB |
Output is correct |
6 |
Correct |
47 ms |
4900 KB |
Output is correct |
7 |
Correct |
47 ms |
4900 KB |
Output is correct |
8 |
Correct |
55 ms |
4860 KB |
Output is correct |
9 |
Correct |
41 ms |
4644 KB |
Output is correct |
10 |
Correct |
43 ms |
4660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1528 KB |
Output is correct |
2 |
Correct |
12 ms |
1404 KB |
Output is correct |
3 |
Correct |
52 ms |
1528 KB |
Output is correct |
4 |
Correct |
121 ms |
3624 KB |
Output is correct |
5 |
Correct |
69 ms |
3708 KB |
Output is correct |
6 |
Correct |
7 ms |
1660 KB |
Output is correct |
7 |
Correct |
7 ms |
1528 KB |
Output is correct |
8 |
Correct |
7 ms |
1528 KB |
Output is correct |
9 |
Correct |
6 ms |
1528 KB |
Output is correct |
10 |
Correct |
6 ms |
1524 KB |
Output is correct |
11 |
Correct |
57 ms |
4788 KB |
Output is correct |
12 |
Correct |
122 ms |
4496 KB |
Output is correct |
13 |
Correct |
63 ms |
4216 KB |
Output is correct |
14 |
Correct |
52 ms |
4216 KB |
Output is correct |
15 |
Correct |
54 ms |
4600 KB |
Output is correct |
16 |
Correct |
47 ms |
4900 KB |
Output is correct |
17 |
Correct |
47 ms |
4900 KB |
Output is correct |
18 |
Correct |
55 ms |
4860 KB |
Output is correct |
19 |
Correct |
41 ms |
4644 KB |
Output is correct |
20 |
Correct |
43 ms |
4660 KB |
Output is correct |
21 |
Correct |
59 ms |
4788 KB |
Output is correct |
22 |
Correct |
120 ms |
4468 KB |
Output is correct |
23 |
Correct |
725 ms |
4476 KB |
Output is correct |
24 |
Correct |
1153 ms |
6840 KB |
Output is correct |
25 |
Correct |
186 ms |
6648 KB |
Output is correct |
26 |
Correct |
128 ms |
7060 KB |
Output is correct |
27 |
Correct |
51 ms |
5368 KB |
Output is correct |
28 |
Correct |
54 ms |
5240 KB |
Output is correct |
29 |
Execution timed out |
4003 ms |
7292 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |