Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- using ld = long double;
- using ull = unsigned long long;
- template <class T>
- void read(T &x)
- {
- x = 0;
- register int c;
- while ((c = getchar()) && (c > '9' || c < '0'))
- ;
- for (; c >= '0' && c <= '9'; c = getchar())
- x = x * 10 + c - '0';
- }
- constexpr bool typetest = 0;
- constexpr int N = 2e5 + 5;
- constexpr ll mod = 1e9 + 7;
- struct Vector
- {
- ll x, y;
- Vector(ll x = 0, ll y = 0) : x(x), y(y) {}
- Vector operator-(const Vector &a) const
- {
- return Vector(x - a.x, y - a.y);
- }
- ll operator*(const Vector &a) const
- {
- return x * a.y - y * a.x;
- }
- } d[N];
- using Point = Vector;
- int n;
- ll a, b, c;
- void Read()
- {
- cin >> n >> a >> b >> c;
- for (int i = 1; i <= n; ++i)
- cin >> d[i].x >> d[i].y;
- }
- // ax + by = c
- // a * x1 + b * y1 = a
- // a * x2 + b * y2 = b
- pair<ll, ll> Dio(ll a, ll b, ll c)
- {
- ll xa = 1, ya = 0, xb = 0, yb = 1, xr, yr, r;
- while (b != 0)
- {
- ll q = a / b;
- r = a - b * q;
- xr = xa - xb * q;
- yr = ya - yb * q;
- a = b;
- xa = xb;
- ya = yb;
- b = r;
- xb = xr;
- yb = yr;
- }
- // d -> gcd(a, b)
- // a * xd + b * yd = gcd(a, b)
- // a * (xd * c/gcd(a, b)) + b * (yd * c/gcd(a, b)) = c;
- ll v = c / a;
- return make_pair(xa * v, ya * v);
- }
- void Solve()
- {
- pair<ll, ll> point = Dio(a, b, -c);
- Point u = Point(point.first, point.second);
- Point v = Point(u.x + b, u.y - a);
- ll cnt[2] = {0, 0};
- for (int i = 1; i <= n; ++i)
- if ((d[i] - u) * (v - d[i]) > 0)
- ++cnt[0];
- else if ((d[i] - u) * (v - d[i]) < 0)
- ++cnt[1];
- cout << cnt[0] * cnt[1];
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen("tests.inp", "r"))
- {
- freopen("test.inp", "r", stdin);
- freopen("test.out", "w", stdout);
- }
- int t(1);
- if (typetest)
- cin >> t;
- for (int _ = 1; _ <= t; ++_)
- {
- // cout << "Case #" << _ << endl;
- Read();
- Solve();
- }
- // cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
- }
- /*
- */
- /*
- Input:
- 4 5 4
- 2 3
- 2 5
- 3 1
- 4 4
- Output:
- 9
- */
Advertisement
Add Comment
Please, Sign In to add comment