Submission #72715251


Source Code Expand

#include <bits/stdc++.h>

//#include <atcoder/all>
using namespace std;

#define lli long long int
#define REP(i, s, n) for (lli i = s; i < n; i++)
#define INF (1LL << 62)
#define mp(a, b) make_pair(a, b)
#define SORT(V) sort(V.begin(), V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) #VariableName
#define LOG1(x)                                                                \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << endl;
#define LOG2(x, y)                                                             \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << TO_STRING(y) << "=" << y << endl;
#define LOG3(x, y, z)                                                          \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << TO_STRING(y) << "=" << y << " " \
         << TO_STRING(z) << "=" << z << endl;
#define LOG4(w, x, y, z)                                                       \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z        \
         << endl;
#define LOG5(w, x, y, z, a)                                                    \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z << " " \
         << TO_STRING(a) << "=" << a << endl;
#define LOG6(w, x, y, z, a, b)                                                 \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z << " " \
         << TO_STRING(a) << "=" << a << " " << TO_STRING(b) << "=" << b        \
         << endl;

#define overload6(a, b, c, d, e, f, g, ...) g
#define LOG(...)                                                               \
  overload6(__VA_ARGS__, LOG6, LOG5, LOG4, LOG3, LOG2, LOG1)(__VA_ARGS__)

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

mt19937 engine;
std::chrono::system_clock::time_point start, endTime;

#define DEBUG 0

lli gcd(lli a, lli b) {
  if (a == 0)
    return b;
  if (b == 0)
    return a;
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
lli lcm(lli a, lli b) { return a * b / gcd(a, b); }

void solve() {
  //  write your code here

  lli N, Q;
  cin >> N >> Q;

  vector<lli> X(N), Y(N);

  REP(i, 0, N) { cin >> X[i] >> Y[i]; }

  vector<pair<long double, int>> V(N);

  REP(i, 0, N) {
    lli nowGcd = gcd(abs(Y[i]), abs(X[i]));
    V[i] = {atan2l(Y[i] / nowGcd, X[i] / nowGcd), i};
  }

  //同じものはまとめ上げる、どうやってやるかは最大公約数で割ればよい

  map<pair<int, int>, set<int>> cnts;

  REP(i, 0, N) {
    lli nowGcd = gcd(abs(X[i]), abs(Y[i]));
    cnts[{X[i] / nowGcd, Y[i] / nowGcd}].insert(i);
  }

  SORT(V);

  vector<pair<int, int>> V2;

  int nowIndex = 0;

  set<int> visitedRealIndex;
  REP(i, 0, N) {
    int realIndex = V[i].second;
    int realX = X[realIndex];
    int realY = Y[realIndex];
    LOG(realIndex, realX, realY);
    if (visitedRealIndex.find(realIndex) != visitedRealIndex.end()) {
      break;
    }
    int nowGcd = gcd(abs(realX), abs(realY));
    for (auto realIndex2 : cnts[{realX / nowGcd, realY / nowGcd}]) {
      V2.push_back({nowIndex, realIndex2});
      visitedRealIndex.insert(realIndex2);
      i++;
    }
    nowIndex += cnts[{realX / nowGcd, realY / nowGcd}].size();
    i--;
  }

  map<lli, lli> backRealIndexToV2Index;
  REP(i, 0, N) { backRealIndexToV2Index[V2[i].second] = V2[i].first; }

  while (Q--) {
    lli a, b;
    cin >> a >> b;
    a--;
    b--;

    lli aV2Index = backRealIndexToV2Index[a];
    lli bV2Index = backRealIndexToV2Index[b];

    lli realAX = X[a];
    lli realAY = Y[a];
    lli aGcd = gcd(abs(realAX), abs(realAY));
    lli aCnts = cnts[{realAX / aGcd, realAY / aGcd}].size();

    lli realBX = X[b];
    lli realBY = Y[b];
    lli bGcd = gcd(abs(realBX), abs(realBY));
    lli bCnts = cnts[{realBX / bGcd, realBY / bGcd}].size();
    LOG(aV2Index, bV2Index);

    if (aV2Index < bV2Index) {
      aV2Index += N;
    }
    cout << aV2Index - bV2Index + aCnts << endl;
  }
}

// Generated by 2.13.0 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  // Failed to predict input format

  lli N = 1;
  // cin >> N;
  while (N--)
    solve();

  return 0;
}

Submission Info

Submission Time
Task E - Laser Takahashi
User ohuton_labo
Language C++23 (GCC 15.2.0)
Score 450
Code Size 5294 Byte
Status AC
Exec Time 1606 ms
Memory 64332 KiB

Compile Error

./Main.cpp: In function 'void solve()':
./Main.cpp:149:9: warning: unused variable 'bCnts' [-Wunused-variable]
  149 |     lli bCnts = cnts[{realBX / bGcd, realBY / bGcd}].size();
      |         ^~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 33
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 05_killer_00.txt, 05_killer_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3516 KiB
00_sample_01.txt AC 1 ms 3612 KiB
00_sample_02.txt AC 1 ms 3608 KiB
01_random_00.txt AC 484 ms 17532 KiB
01_random_01.txt AC 1152 ms 62844 KiB
01_random_02.txt AC 1245 ms 57084 KiB
01_random_03.txt AC 32 ms 5884 KiB
01_random_04.txt AC 1239 ms 64128 KiB
01_random_05.txt AC 1606 ms 64276 KiB
01_random_06.txt AC 1585 ms 64224 KiB
01_random_07.txt AC 1597 ms 64332 KiB
01_random_08.txt AC 1600 ms 64272 KiB
01_random_09.txt AC 1600 ms 64276 KiB
02_random2_00.txt AC 1566 ms 61800 KiB
02_random2_01.txt AC 1555 ms 61724 KiB
02_random2_02.txt AC 1539 ms 61808 KiB
02_random2_03.txt AC 1592 ms 61788 KiB
02_random2_04.txt AC 1579 ms 61724 KiB
02_random2_05.txt AC 1572 ms 61800 KiB
02_random2_06.txt AC 1545 ms 61840 KiB
02_random2_07.txt AC 1584 ms 61772 KiB
02_random2_08.txt AC 1549 ms 61732 KiB
02_random2_09.txt AC 1563 ms 61788 KiB
03_random3_00.txt AC 1433 ms 60596 KiB
03_random3_01.txt AC 1229 ms 56840 KiB
03_random3_02.txt AC 1023 ms 53032 KiB
03_random3_03.txt AC 823 ms 49248 KiB
03_random3_04.txt AC 636 ms 45572 KiB
04_handmade_00.txt AC 380 ms 45572 KiB
04_handmade_01.txt AC 353 ms 45608 KiB
04_handmade_02.txt AC 141 ms 3540 KiB
05_killer_00.txt AC 1381 ms 62400 KiB
05_killer_01.txt AC 1385 ms 62444 KiB