QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#438755#8782. Schoolgirlshos_lyricWA 99ms4036kbC++148.1kb2024-06-11 04:27:202024-06-11 04:27:21

Judging History

你现在查看的是最新测评结果

  • [2024-06-14 13:48:47]
  • hack成功,自动添加数据
  • (/hack/679)
  • [2024-06-14 13:05:18]
  • hack成功,自动添加数据
  • (/hack/678)
  • [2024-06-14 12:22:35]
  • hack成功,自动添加数据
  • (/hack/676)
  • [2024-06-11 04:27:21]
  • 评测
  • 测评结果:WA
  • 用时:99ms
  • 内存:4036kb
  • [2024-06-11 04:27:20]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


template <class T> T power(T a, long long e, T m) {
  for (T b = 1; ; (a *= a) %= m) {
    if (e & 1) (b *= a) %= m;
    if (!(e >>= 1)) return b;
  }
}

long long gcd(long long a, long long b) {
  if (a < 0) a = -a;
  if (b < 0) b = -b;
  if (a == 0) return b;
  if (b == 0) return a;
  const int s = __builtin_ctzll(a | b);
  a >>= __builtin_ctzll(a);
  do {
    b >>= __builtin_ctzll(b);
    if (a > b) swap(a, b);
    b -= a;
  } while (b);
  return a << s;
}

bool isPrime(long long n) {
  if (n <= 1 || n % 2 == 0) return (n == 2);
  const int s = __builtin_ctzll(n - 1);
  const long long d = (n - 1) >> s;
  // http://miller-rabin.appspot.com/
  for (const long long base : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) {
    __int128 a = base % n;
    if (a == 0) continue;
    a = power<__int128>(a, d, n);
    if (a == 1 || a == n - 1) continue;
    bool ok = false;
    for (int i = 0; i < s - 1; ++i) {
      (a *= a) %= n;
      if (a == n - 1) {
        ok = true;
        break;
      }
    }
    if (!ok) return false;
  }
  return true;
}


////////////////////////////////////////////////////////////////////////////////
// Barrett
struct ModInt {
  static unsigned M;
  static unsigned long long NEG_INV_M;
  static void setM(unsigned m) { M = m; NEG_INV_M = -1ULL / M; }
  unsigned x;
  ModInt() : x(0U) {}
  ModInt(unsigned x_) : x(x_ % M) {}
  ModInt(unsigned long long x_) : x(x_ % M) {}
  ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) {
    const unsigned long long y = static_cast<unsigned long long>(x) * a.x;
    const unsigned long long q = static_cast<unsigned long long>((static_cast<unsigned __int128>(NEG_INV_M) * y) >> 64);
    const unsigned long long r = y - M * q;
    x = r - M * (r >= M);
    return *this;
  }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  bool operator<(const ModInt &a) const { return (x < a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
unsigned ModInt::M;
unsigned long long ModInt::NEG_INV_M;
// !!!Use ModInt::setM!!!
////////////////////////////////////////////////////////////////////////////////

using Mint = ModInt;

// M: prime
Mint primitiveRoot() {
  const unsigned M = Mint::M;
  vector<unsigned> es;
  {
    unsigned m = M - 1;
    for (unsigned q = 2; q * q <= m; ++q) if (m % q == 0) {
      do { m /= q; } while (m % q == 0);
      es.push_back((M - 1) / q);
    }
    if (m > 1) es.push_back((M - 1) / m);
  }
  for (unsigned a = 1; a < M; ++a) {
    const Mint g = a;
    if ([&]() -> bool {
      for (const unsigned e : es) if (g.pow(e).x == 1) return false;
      return true;
    }()) {
      return g;
    }
  }
  assert(false);
}


#include <chrono>
#ifdef LOCAL
mt19937_64 rng(58);
#else
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#endif


constexpr int ITER = 100;

int N, M, Q;
vector<int> A, B, C;
vector<int> R;
vector<vector<int>> U;

int main() {
  for (; ~scanf("%d%d%d", &N, &M, &Q); ) {
    A.resize(M);
    B.resize(M);
    C.resize(M);
    for (int i = 0; i < M; ++i) {
      scanf("%d%d%d", &A[i], &B[i], &C[i]);
      --A[i];
      --B[i];
      --C[i];
    }
    R.resize(Q);
    U.resize(Q);
    for (int q = 0; q < Q; ++q) {
      scanf("%d", &R[q]);
      U[q].resize(R[q]);
      for (int r = 0; r < R[q]; ++r) {
        scanf("%d", &U[q][r]);
        --U[q][r];
      }
    }
    
    vector<int> ans(Q, 1);
    for (int iter = 0; iter < ITER; ++iter) {
      int p;
      for (; ; ) {
        /*
          N | p - 1
          p = N k + 1
          3 <= p < 2^31
        */
        p = N * (rng() % ((1LL<<31) / N)) + 1;
        if (3 <= p && p < 1LL<<31 && (p - 1) % N == 0 && isPrime(p)) {
          break;
        }
      }
      Mint::setM(p);
      const Mint g = primitiveRoot();
// cerr<<"p = "<<p<<", g = "<<g<<endl;
      const Mint rot = g.pow((p - 1) / N);
      vector<Mint> zs(N + M);
      zs[0] = 1;
      for (int u = 1; u < N; ++u) {
        zs[u] = zs[u - 1] * rot;
      }
      for (int i = 0; i < M; ++i) {
        // B - A = C - ?
        zs[N + i] = zs[A[i]] + zs[C[i]] - zs[B[i]];
      }
      for (int q = 0; q < Q; ++q) {
        if ([&]() -> bool {
          const int n = R[q];
          Mint o = 0;
          vector<Mint> ws(n);
          for (int r = 0; r < n; ++r) o += ws[r] = zs[U[q][r]];
          o /= n;
          for (int r = 0; r < n; ++r) ws[r] -= o;
          o = 0;
          sort(ws.begin(), ws.end());
          if (ws[0] == ws[N - 1]) return true;
          if ((p - 1) % n != 0) return false;
          const Mint ro = g.pow((p - 1) / n);
          vector<Mint> tar(n);
          tar[0] = ws[0];
          for (int r = 1; r < n; ++r) tar[r] = tar[r - 1] * ro;
          sort(tar.begin(), tar.end());
          return (tar == ws);
        }()) {
          // Yes
        } else {
          ans[q] = 0;
        }
      }
    }
    
    for (int q = 0; q < Q; ++q) {
      puts(ans[q] ? "Yes" : "No");
    }
  }
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3676kb

input:

3 6 8
1 2 3
3 1 4
5 4 3
3 1 2
4 5 3
4 5 2
6 4 7 6 5 1 2
3 1 3 2
3 1 1 8
4 2 5 6 7
3 2 1 4
3 6 5 9
3 4 7 9
4 1 3 2 8

output:

Yes
Yes
Yes
No
No
No
Yes
No

result:

ok 8 token(s): yes count is 4, no count is 4

Test #2:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

12 0 1
12 12 11 10 9 8 7 6 5 4 3 2 1

output:

Yes

result:

ok YES

Test #3:

score: -100
Wrong Answer
time: 99ms
memory: 4036kb

input:

3 0 6685
5 1 3 1 2 2
3 1 2 3
5 3 1 3 3 1
4 1 1 1 3
3 3 2 1
5 2 3 2 1 3
6 2 2 3 2 3 1
5 3 1 2 3 2
3 3 3 2
5 3 2 2 2 3
5 2 2 3 3 1
6 3 3 1 3 1 3
6 2 3 3 2 2 1
5 2 2 3 2 2
6 2 3 3 2 1 3
6 2 2 2 2 1 3
3 3 1 2
4 3 2 1 1
5 3 1 3 2 3
4 3 1 1 2
4 2 2 2 3
3 1 2 2
4 2 3 3 1
3 2 2 2
4 1 2 2 3
3 3 3 3
4 1 3 1 3...

output:

No
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
Yes
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
Yes
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
...

result:

wrong answer expected NO, found YES [60th token]