#include <cstdio>
#include <cstring>
#include <tuple>
#include <vector>
#include <algorithm>
typedef long long i64;
const int N = 100000 + 10;
int n, m;
struct Point {
i64 x, y;
Point() {}
Point(i64 _x, i64 _y): x(_x), y(_y) {}
};
inline Point operator- (const Point &a, const Point &b) {
return Point(a.x - b.x, a.y - b.y);
}
inline i64 cross(const Point &a, const Point &b) {
return a.x * b.y - a.y * b.x;
}
inline i64 cross(const Point &o, const Point &a, const Point &b) {
return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
}
inline bool operator< (const Point &a, const Point &b) {
return cross(a, b) > 0;
}
int c[N];
bool flag[N];
Point r[N];
std::pair<int, Point> a[N];
std::pair<Point, int> b[N];
int pos[N], l[N];
Point st, ed;
std::vector<std::pair<int, int>> q, u[N], v[N];
int ans[N];
void init() {
scanf("%d%d", &n, &m);
static Point p[N];
for (int i = 0; i < n; ++i) scanf("%lld%lld%d", &p[i].x, &p[i].y, &c[i]), --c[i];
scanf("%lld%lld%lld%lld", &st.x, &st.y, &ed.x, &ed.y);
for (int i = 0; i < n; ++i) flag[i] = cross(st, ed, p[i]) > 0;
for (int i = 0; i < n; ++i) a[i] = {c[i], r[i] = flag[i] ? p[i] - ed : ed - p[i]};
std::sort(a, a + n);
for (int i = 0; i < n; ++i) pos[i] = std::lower_bound(a, a + n, std::make_pair(c[i], r[i])) - a;
for (int i = 0; i <= m; ++i) l[i] = std::lower_bound(a, a + n, std::make_pair(i, ed - st)) - a;
for (int i = 0; i < n; ++i) b[i] = {flag[i] ? p[i] - st : st - p[i], i};
std::sort(b, b + n);
int k;
scanf("%d", &k);
for (int i = 0; i < k; ++i) {
int x, y;
scanf("%d%d", &x, &y);
q.emplace_back(--x, --y);
u[x].emplace_back(y, i);
}
for (int i = 0; i < m; ++i) {
if (u[i].size() <= 300) continue;
for (auto j : u[i]) v[j.first].emplace_back(i, j.second);
u[i].clear();
}
}
class BIT {
int data[N];
int query(int p) {
int res = 0;
for (++p; p; p ^= p & -p) res += data[p];
return res;
}
public:
inline void clear() {
memset(data, 0, sizeof data);
}
void add(int p, int v) {
for (++p; p < N; p += p & -p) data[p] += v;
}
inline int query(int l, int r) {
return query(r - 1) - query(l - 1);
}
} bit[2];
int main() {
init();
for (int i = 0; i < n; ++i) if (!flag[i]) bit[0].add(pos[i], 1);
for (int i = 0; i < n; ++i) {
int x = b[i].second, y = c[x], z = flag[x];
for (auto it : u[y]) {
int k, id;
std::tie(k, id) = it;
int p = std::lower_bound(a, a + n, std::make_pair(k, r[x])) - a;
ans[id] += bit[0].query(l[k], p) + bit[1].query(p, l[k + 1]);
}
if (z) bit[1].add(pos[x], 1); else bit[0].add(pos[x], -1);
}
bit[0].clear(), bit[1].clear();
for (int i = 0; i < n; ++i) bit[1].add(pos[i], 1);
for (int i = 0; i < n; ++i) {
int x = b[i].second, y = c[x], z = flag[x];
for (auto it : v[y]) {
int k, id;
std::tie(k, id) = it;
int p = std::lower_bound(a, a + n, std::make_pair(k, r[x])) - a;
ans[id] += z ? bit[1].query(l[k], p) : bit[0].query(p, l[k + 1]);
}
bit[0].add(pos[x], 1);
bit[1].add(pos[x], -1);
}
for (int i = 0; i < q.size(); ++i) printf("%d\n", ans[i]);
return 0;
}
Compilation message
dragon2.cpp: In function 'int main()':
dragon2.cpp:123:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < q.size(); ++i) printf("%d\n", ans[i]);
^
dragon2.cpp: In function 'void init()':
dragon2.cpp:52:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
dragon2.cpp:54:83: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i = 0; i < n; ++i) scanf("%lld%lld%d", &p[i].x, &p[i].y, &c[i]), --c[i];
^
dragon2.cpp:55:56: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld%lld", &st.x, &st.y, &ed.x, &ed.y);
^
dragon2.cpp:64:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &k);
^
dragon2.cpp:67:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &x, &y);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
16128 KB |
Output is correct |
2 |
Correct |
3 ms |
16128 KB |
Output is correct |
3 |
Correct |
19 ms |
16284 KB |
Output is correct |
4 |
Correct |
96 ms |
18624 KB |
Output is correct |
5 |
Correct |
46 ms |
18608 KB |
Output is correct |
6 |
Correct |
0 ms |
16260 KB |
Output is correct |
7 |
Correct |
3 ms |
16260 KB |
Output is correct |
8 |
Correct |
0 ms |
16128 KB |
Output is correct |
9 |
Correct |
0 ms |
16128 KB |
Output is correct |
10 |
Correct |
0 ms |
16128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
16128 KB |
Output is correct |
2 |
Correct |
69 ms |
16128 KB |
Output is correct |
3 |
Correct |
36 ms |
16128 KB |
Output is correct |
4 |
Correct |
26 ms |
16128 KB |
Output is correct |
5 |
Correct |
33 ms |
16128 KB |
Output is correct |
6 |
Correct |
29 ms |
16128 KB |
Output is correct |
7 |
Correct |
39 ms |
16128 KB |
Output is correct |
8 |
Correct |
39 ms |
16128 KB |
Output is correct |
9 |
Correct |
26 ms |
16128 KB |
Output is correct |
10 |
Correct |
26 ms |
16128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
16128 KB |
Output is correct |
2 |
Correct |
3 ms |
16128 KB |
Output is correct |
3 |
Correct |
19 ms |
16284 KB |
Output is correct |
4 |
Correct |
96 ms |
18624 KB |
Output is correct |
5 |
Correct |
46 ms |
18608 KB |
Output is correct |
6 |
Correct |
0 ms |
16260 KB |
Output is correct |
7 |
Correct |
3 ms |
16260 KB |
Output is correct |
8 |
Correct |
0 ms |
16128 KB |
Output is correct |
9 |
Correct |
0 ms |
16128 KB |
Output is correct |
10 |
Correct |
0 ms |
16128 KB |
Output is correct |
11 |
Correct |
39 ms |
16128 KB |
Output is correct |
12 |
Correct |
69 ms |
16128 KB |
Output is correct |
13 |
Correct |
36 ms |
16128 KB |
Output is correct |
14 |
Correct |
26 ms |
16128 KB |
Output is correct |
15 |
Correct |
33 ms |
16128 KB |
Output is correct |
16 |
Correct |
29 ms |
16128 KB |
Output is correct |
17 |
Correct |
39 ms |
16128 KB |
Output is correct |
18 |
Correct |
39 ms |
16128 KB |
Output is correct |
19 |
Correct |
26 ms |
16128 KB |
Output is correct |
20 |
Correct |
26 ms |
16128 KB |
Output is correct |
21 |
Correct |
43 ms |
16128 KB |
Output is correct |
22 |
Correct |
69 ms |
16128 KB |
Output is correct |
23 |
Correct |
373 ms |
16284 KB |
Output is correct |
24 |
Correct |
886 ms |
18624 KB |
Output is correct |
25 |
Correct |
186 ms |
18624 KB |
Output is correct |
26 |
Correct |
159 ms |
18768 KB |
Output is correct |
27 |
Correct |
59 ms |
16692 KB |
Output is correct |
28 |
Correct |
66 ms |
16692 KB |
Output is correct |
29 |
Correct |
103 ms |
19344 KB |
Output is correct |
30 |
Correct |
453 ms |
18732 KB |
Output is correct |
31 |
Correct |
103 ms |
18888 KB |
Output is correct |
32 |
Correct |
99 ms |
19352 KB |
Output is correct |
33 |
Correct |
1016 ms |
18732 KB |
Output is correct |
34 |
Correct |
129 ms |
18888 KB |
Output is correct |
35 |
Correct |
143 ms |
19352 KB |
Output is correct |
36 |
Correct |
123 ms |
18732 KB |
Output is correct |
37 |
Correct |
176 ms |
18888 KB |
Output is correct |
38 |
Correct |
339 ms |
19268 KB |
Output is correct |
39 |
Correct |
889 ms |
19140 KB |
Output is correct |
40 |
Correct |
1049 ms |
18728 KB |
Output is correct |
41 |
Correct |
129 ms |
19272 KB |
Output is correct |
42 |
Correct |
109 ms |
19236 KB |
Output is correct |
43 |
Correct |
156 ms |
19316 KB |
Output is correct |
44 |
Correct |
46 ms |
16816 KB |
Output is correct |
45 |
Correct |
53 ms |
16856 KB |
Output is correct |
46 |
Correct |
49 ms |
16888 KB |
Output is correct |
47 |
Correct |
49 ms |
16692 KB |
Output is correct |
48 |
Correct |
46 ms |
16692 KB |
Output is correct |
49 |
Correct |
53 ms |
16692 KB |
Output is correct |