QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#488449#9155. 集合hos_lyric#100 ✓1145ms19840kbC++145.5kb2024-07-24 05:25:412024-07-24 05:25:42

Judging History

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

  • [2024-07-24 05:25:42]
  • 评测
  • 测评结果:100
  • 用时:1145ms
  • 内存:19840kb
  • [2024-07-24 05:25:41]
  • 提交

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")

////////////////////////////////////////////////////////////////////////////////
// 2^61 - 1 = 2'305'843'009'213'693'951
struct ModLong61 {
  static constexpr unsigned long long M = (1ULL << 61) - 1;
  unsigned long long x;
  constexpr ModLong61() : x(0ULL) {}
  constexpr ModLong61(unsigned x_) : x(x_) {}
  constexpr ModLong61(unsigned long long x_) : x(x_ % M) {}
  constexpr ModLong61(int x_) : x((x_ < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  constexpr ModLong61(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModLong61 &operator+=(const ModLong61 &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModLong61 &operator-=(const ModLong61 &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModLong61 &operator*=(const ModLong61 &a) {
    const unsigned __int128 y = static_cast<unsigned __int128>(x) * a.x;
    x = (y >> 61) + (y & M);
    x = (x >= M) ? (x - M) : x;
    return *this;
  }
  ModLong61 &operator/=(const ModLong61 &a) { return (*this *= a.inv()); }
  ModLong61 pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModLong61 a = *this, b = 1ULL; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModLong61 inv() const {
    unsigned long long a = M, b = x; long long y = 0, z = 1;
    for (; b; ) { const unsigned long long q = a / b; const unsigned long long c = a - q * b; a = b; b = c; const long long w = y - static_cast<long long>(q) * z; y = z; z = w; }
    assert(a == 1ULL); return ModLong61(y);
  }
  ModLong61 operator+() const { return *this; }
  ModLong61 operator-() const { ModLong61 a; a.x = x ? (M - x) : 0ULL; return a; }
  ModLong61 operator+(const ModLong61 &a) const { return (ModLong61(*this) += a); }
  ModLong61 operator-(const ModLong61 &a) const { return (ModLong61(*this) -= a); }
  ModLong61 operator*(const ModLong61 &a) const { return (ModLong61(*this) *= a); }
  ModLong61 operator/(const ModLong61 &a) const { return (ModLong61(*this) /= a); }
  template <class T> friend ModLong61 operator+(T a, const ModLong61 &b) { return (ModLong61(a) += b); }
  template <class T> friend ModLong61 operator-(T a, const ModLong61 &b) { return (ModLong61(a) -= b); }
  template <class T> friend ModLong61 operator*(T a, const ModLong61 &b) { return (ModLong61(a) *= b); }
  template <class T> friend ModLong61 operator/(T a, const ModLong61 &b) { return (ModLong61(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModLong61 &a) const { return (x == a.x); }
  bool operator!=(const ModLong61 &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModLong61 &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

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

////////////////////////////////////////////////////////////////////////////////


int N, M, Q;
vector<int> A[2];

ModLong61 X;
vector<ModLong61> wts;
ModLong61 msets[2];
vector<ModLong61> setss[2];

void init() {
  X = (unsigned long long)rng();
  wts.resize(N);
  for (int i = 0; i < N; ++i) {
    wts[i] = (unsigned long long)rng();
  }
  for (int h = 0; h < 2; ++h) {
    msets[h] = X.pow(M);
    setss[h].assign(M, X);
  }
}
void add(int i, int sig) {
  for (int h = 0; h < 2; ++h) {
    for (int j = 0; j < 3; ++j) {
      const int a = A[h][i * 3 + j];
      msets[h] /= setss[h][a];
      setss[h][a] += sig * wts[i];
      msets[h] *= setss[h][a];
    }
  }
}

int main() {
  for (; ~scanf("%d%d%d", &N, &M, &Q); ) {
    for (int h = 0; h < 2; ++h) {
      A[h].resize(N * 3);
      for (int i = 0; i < N * 3; ++i) {
        scanf("%d", &A[h][i]);
        --A[h][i];
      }
    }
    
    vector<int> rs(N);
    init();
    for (int l = 0, r = 0; l < N; ++l) {
      for (; r < N; ++r) {
        add(r, +1);
        if (msets[0] != msets[1]) {
          add(r, -1);
          break;
        }
      }
      rs[l] = r;
      add(l, -1);
    }
    
    for (; Q--; ) {
      int L, R;
      scanf("%d%d", &L, &R);
      --L;
      puts((R <= rs[L]) ? "Yes" : "No");
    }
  }
  return 0;
}

Details


Pretests

Pretest #1:

score: 5
Accepted
time: 1ms
memory: 3740kb

Pretest #2:

score: 5
Accepted
time: 1ms
memory: 3692kb

Pretest #3:

score: 5
Accepted
time: 1ms
memory: 3668kb

Pretest #4:

score: 5
Accepted
time: 1ms
memory: 3904kb

Pretest #5:

score: 5
Accepted
time: 1ms
memory: 3936kb

Pretest #6:

score: 5
Accepted
time: 1ms
memory: 3776kb

Pretest #7:

score: 5
Accepted
time: 1ms
memory: 3884kb

Pretest #8:

score: 5
Accepted
time: 1ms
memory: 3744kb

Pretest #9:

score: 5
Accepted
time: 22ms
memory: 3716kb

Pretest #10:

score: 5
Accepted
time: 19ms
memory: 3936kb

Pretest #11:

score: 5
Accepted
time: 1040ms
memory: 10268kb

Pretest #12:

score: 5
Accepted
time: 1018ms
memory: 10208kb

Pretest #13:

score: 5
Accepted
time: 11ms
memory: 3736kb

Pretest #14:

score: 5
Accepted
time: 10ms
memory: 4052kb

Pretest #15:

score: 5
Accepted
time: 118ms
memory: 3844kb

Pretest #16:

score: 5
Accepted
time: 122ms
memory: 4064kb

Pretest #17:

score: 5
Accepted
time: 100ms
memory: 3936kb

Pretest #18:

score: 5
Accepted
time: 93ms
memory: 4708kb

Pretest #19:

score: 5
Accepted
time: 1134ms
memory: 10220kb

Pretest #20:

score: 5
Accepted
time: 1122ms
memory: 19840kb

Final Tests

Test #1:

score: 5
Accepted
time: 1ms
memory: 3664kb

Test #2:

score: 5
Accepted
time: 1ms
memory: 3616kb

Test #3:

score: 5
Accepted
time: 1ms
memory: 3932kb

Test #4:

score: 5
Accepted
time: 1ms
memory: 3664kb

Test #5:

score: 5
Accepted
time: 1ms
memory: 3660kb

Test #6:

score: 5
Accepted
time: 1ms
memory: 3776kb

Test #7:

score: 5
Accepted
time: 1ms
memory: 3936kb

Test #8:

score: 5
Accepted
time: 1ms
memory: 3936kb

Test #9:

score: 5
Accepted
time: 19ms
memory: 3716kb

Test #10:

score: 5
Accepted
time: 22ms
memory: 3936kb

Test #11:

score: 5
Accepted
time: 998ms
memory: 10296kb

Test #12:

score: 5
Accepted
time: 1033ms
memory: 10268kb

Test #13:

score: 5
Accepted
time: 10ms
memory: 3732kb

Test #14:

score: 5
Accepted
time: 10ms
memory: 3880kb

Test #15:

score: 5
Accepted
time: 115ms
memory: 3840kb

Test #16:

score: 5
Accepted
time: 124ms
memory: 4096kb

Test #17:

score: 5
Accepted
time: 101ms
memory: 4200kb

Test #18:

score: 5
Accepted
time: 96ms
memory: 4792kb

Test #19:

score: 5
Accepted
time: 1115ms
memory: 10272kb

Test #20:

score: 5
Accepted
time: 1145ms
memory: 19604kb

Extra Test:

score: 0
Extra Test Passed