QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#280586#7782. Ursa Minorucup-team1198#RE 447ms19632kbC++146.2kb2023-12-09 17:08:332023-12-09 17:08:34

Judging History

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

  • [2023-12-09 17:08:34]
  • 评测
  • 测评结果:RE
  • 用时:447ms
  • 内存:19632kb
  • [2023-12-09 17:08:33]
  • 提交

answer

#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;

const int K = 393;
const int MAXN = 400400;

long long fenw[MAXN];

void add(int i, long long x) {
  for (; i < MAXN; i = (i | (i + 1)))
    fenw[i] += x;
}

long long get(int i) {
  long long ans = 0;
  for (; i >= 0; i = (i & (i + 1)) - 1)
    ans += fenw[i];
  return ans;
}

long long get(int l, int r) {
  return get(r - 1) - get(l - 1);
}


int gcd(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}

int tree_gcd[(1 << 19) + 228];

void build(int v, int left, int right, vector<int>& A) {
  if (left + 1 == right) {
    tree_gcd[v] = A[left];
    return;
  }
  int mid = (left + right) / 2;
  build(2 * v + 1, left, mid, A);
  build(2 * v + 2, mid, right, A);
  tree_gcd[v] = gcd(tree_gcd[2 * v + 1], tree_gcd[2 * v + 2]);
}

int get_gcd(int v, int left, int right, int x, int y) {
  if (y <= left || right <= x)
    return 0;
  if (x <= left && right <= y)
    return tree_gcd[v];
  int mid = (left + right) / 2;
  return gcd(get_gcd(2 * v + 1, left, mid, x, y), get_gcd(2 * v + 2, mid, right, x, y));
}


const int MOD = 1e9 + 7;

int add(int a, int b) {
  return a + b >= MOD ? a + b - MOD : a + b;
}

int sub(int a, int b) {
  return a >= b ? a - b : a + MOD - b;
}

int mul(int a, int b) {
  return (1ll * a * b) % MOD;
}

const int BASE = 547;
int BASEPOW[MAXN];

pair<int, int> combine(const pair<int, int>& A, const pair<int, int>& B) {
  return make_pair(add(mul(A.first, BASEPOW[B.second]), B.first), A.second + B.second);
}

const pair<int, int> NONE(0, 0);

int cur_vals[MAXN];
pair<int, int> suff_hashes[MAXN];
pair<int, int> pref_hashes[MAXN];

pair<int, int> get_segm_hash(int left, int right) {
  int l = left / K + 1;
  int r = right / K;
  pair<int, int> ans = suff_hashes[left];
  for (int i = l; i < r; ++i)
    ans = combine(ans, suff_hashes[i * K]);
  ans = combine(ans, pref_hashes[right]);
  return ans;
}

void recalc_block(int id) {
  pair<int, int> cur_pref = NONE;
  for (int i = id * K; i < id * K + K; ++i) {
    cur_pref = combine(cur_pref, make_pair((cur_vals[i] + MOD) % MOD, 1));
    pref_hashes[i] = cur_pref;
  }
  pair<int, int> cur_suff = NONE;
  for (int i = id * K + K - 1; i >= id * K; --i) {
    cur_suff = combine(make_pair((cur_vals[i] + MOD) % MOD, 1), cur_suff);
    suff_hashes[i] = cur_suff;
  }
}

int main() {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#else
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#endif

  BASEPOW[0] = 1;
  for (int i = 1; i < MAXN; ++i)
    BASEPOW[i] = mul(BASEPOW[i - 1], BASE);

  int n, m, q;
  cin >> n >> m >> q;
  vector<long long> A(n);
  for (int i = 0; i < n; ++i)
    cin >> A[i];
  vector<int> B(m);
  for (int i = 0; i < m; ++i)
    cin >> B[i];
  build(0, 0, m, B);
  vector<pair<pair<int, int>, int>> queries(q);
  vector<int> interesting;
  for (int i = 0; i < q; ++i) {
    char c;
    cin >> c;
    if (c == 'U') {
      int p, v;
      cin >> p >> v;
      --p;
      queries[i] = make_pair(make_pair(p, v), -1);
    } else {
      int l, r, s, t;
      cin >> l >> r >> s >> t;
      --l;
      --r;
      --s;
      --t;
      int k = gcd(r - l + 1, get_gcd(0, 0, m, s, t + 1));
      if (k <= K)
        interesting.emplace_back(k);
      queries[i] = make_pair(make_pair(l, r), k);
    }
  }
  vector<bool> ans(q);
  sort(interesting.begin(), interesting.end());
  interesting.resize(unique(interesting.begin(), interesting.end()) - interesting.begin());
  vector<long long> cur_a;
  for (int k : interesting) {
    cur_a = A;
    fill(fenw, fenw + 2 * n, 0);
    auto get_real_id = [n, k](int i) {
      return (i % k) * (n / k + 1) + i / k;
    };
    for (int i = 0; i < n; ++i) {
      add(get_real_id(i), cur_a[i] - (i == 0 ? 0 : cur_a[i - 1]));
    }
    for (int j = 0; j < q; ++j) {
      if (queries[j].second == -1) {
        // upd
        int i = queries[j].first.first;
        int x = queries[j].first.second;
        add(get_real_id(i), x - cur_a[i]);
        if (i + 1 < n)
          add(get_real_id(i + 1), cur_a[i] - x);
        cur_a[i] = x;
      } else if (queries[j].second == k) {
        // query
        int l = queries[j].first.first;
        int r = queries[j].first.second;
        ans[j] = true;
        for (int i = 1; i < k; ++i) {
          // l + i
          long long cur_sum = get(get_real_id(l + i), get_real_id(r + 1 - k + i) + 1);
          if (cur_sum != 0)
            ans[j] = false;
        }
        long long cur_sum = get(get_real_id(l), get_real_id(r + 1 - k) + 1) + (l == 0 ? 0 : cur_a[l - 1]) - cur_a[r];
        if (cur_sum != 0)
          ans[j] = false;
      }
    }
  }
  for (int i = 0; i < n; ++i)
    cur_vals[i] = A[i] - (i == 0 ? 0 : A[i - 1]);
  for (int i = 0; i < n; i += K)
    recalc_block(i);
  cur_a = A;
  for (int j = 0; j < q; ++j) {
    if (queries[j].second == -1) {
      // upd
      int i = queries[j].first.first;
      int x = queries[j].first.second;
      cur_vals[i] += x - cur_a[i];
      if (i + 1 < n)
        cur_vals[i + 1] += cur_a[i] - x;
      cur_a[i] = x;
      recalc_block(i);
      if ((i + 1) / K != i / K)
        recalc_block(i + 1);
    } else if (queries[j].second > K) {
      // query
      int l = queries[j].first.first;
      int r = queries[j].first.second;
      int k = queries[j].second;
      int total_hash = 0;
      for (int i = l; i < r; i += k) {
        total_hash = add(total_hash, get_segm_hash(i, i + k - 1).first);
      }
      int delta = (l == 0 ? 0 : cur_a[l - 1]) - cur_a[r];
      total_hash = add(total_hash, mul(delta, BASEPOW[k - 1]));
      ans[j] = total_hash == 0;
    }
  }

  for (int i = 0; i < q; ++i) {
    if (queries[i].second != -1) {
      if (ans[i])
        cout << "Yes\n";
      else
        cout << "No\n";
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 13732kb

input:

6 4 5
1 1 4 5 1 4
3 3 2 4
Q 1 5 1 2
Q 2 5 3 4
U 5 2
Q 1 6 1 2
Q 2 5 3 4

output:

Yes
No
No
Yes

result:

ok 4 tokens

Test #2:

score: 0
Accepted
time: 4ms
memory: 13740kb

input:

1 1 1
0
1
Q 1 1 1 1

output:

Yes

result:

ok "Yes"

Test #3:

score: 0
Accepted
time: 447ms
memory: 19632kb

input:

2000 2000 200000
1 1 2 0 0 2 0 2 0 0 0 0 0 2 2 1 2 0 0 2 2 2 1 0 1 2 1 2 0 0 1 1 1 2 0 0 2 2 2 2 0 2 0 0 2 1 2 0 0 1 2 2 1 0 2 0 0 0 1 2 2 1 2 2 0 0 1 1 1 0 0 2 0 0 1 1 0 2 2 2 1 0 0 1 0 1 2 2 2 1 1 2 2 1 2 1 0 2 2 3 1 3 2 3 1 0 1 2 0 1 1 1 0 2 2 3 2 0 3 2 3 3 1 2 3 1 2 0 1 0 3 1 0 0 2 0 1 2 1 3 2 2...

output:

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

result:

ok 100554 tokens

Test #4:

score: 0
Accepted
time: 405ms
memory: 16972kb

input:

1 200000 200000
998244353
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

ok 100240 tokens

Test #5:

score: 0
Accepted
time: 377ms
memory: 16672kb

input:

6 131072 200000
0 0 0 0 1000000000 1000000000
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ...

output:

Yes
Yes
Yes
No
No
No
Yes
No
No
No
No
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
No
No
No
No
No
No
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
No
Yes
Yes
No
No
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
No
No
No
Yes
No
No
No
No
No
No
Yes
Yes
No
Yes
N...

result:

ok 100021 tokens

Test #6:

score: -100
Runtime Error

input:

200000 200000 200000
490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877...

output:


result: