QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#280813#7782. Ursa Minorucup-team1198#Compile Error//C++206.3kb2023-12-09 17:58:212023-12-09 17:58:21

Judging History

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

  • [2023-12-09 17:58:21]
  • 评测
  • [2023-12-09 17:58:21]
  • 提交

answer

#pragma GCC optimize("Ofast,unroll-loops")

#define int long long

#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 = 163;
const int MAXN = 400400;

int n;

long long fenw[MAXN];

void add(int i, long long x) {
  for (; i < 2 * n; 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));
}


constexpr int MOD = 1050000011;

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) {
  id /= K;
  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;
  }
}

// bool prime(int x) {
//   for (int i = 2; i * i <= x; ++i) {
//     if (x%i == 0) return 0;
//   }
//   return 1;
// }

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

  // for (int x = 1e9 + 5e7; ; ++x) {
  //   if (prime(x)) {
  //     cout << x << '\n';
  //     return 0;
  //   }
  // }

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

  int 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 = [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] + MOD) % MOD;
      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

answer.code:3:18: error: ‘long long long’ is too long for GCC
    3 | #define int long long
      |                  ^~~~
answer.code:3:18: error: ‘long long long’ is too long for GCC
    3 | #define int long long
      |                  ^~~~
In file included from /usr/include/c++/11/bits/stl_algobase.h:61,
                 from /usr/include/c++/11/bits/stl_tree.h:63,
                 from /usr/include/c++/11/map:60,
                 from answer.code:5:
/usr/include/c++/11/bits/cpp_type_traits.h:242:12: error: redefinition of ‘struct std::__is_integer<long long int>’
  242 |     struct __is_integer<long long>
      |            ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/bits/cpp_type_traits.h:214:12: note: previous definition of ‘struct std::__is_integer<long long int>’
  214 |     struct __is_integer<int>
      |            ^~~~~~~~~~~~~~~~~
/usr/include/c++/11/bits/cpp_type_traits.h:249:12: error: redefinition of ‘struct std::__is_integer<long long unsigned int>’
  249 |     struct __is_integer<unsigned long long>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/bits/cpp_type_traits.h:221:12: note: previous definition of ‘struct std::__is_integer<long long unsigned int>’
  221 |     struct __is_integer<unsigned int>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/stl_algobase.h:62,
                 from /usr/include/c++/11/bits/stl_tree.h:63,
                 from /usr/include/c++/11/map:60,
                 from answer.code:5:
/usr/include/c++/11/ext/type_traits.h:95:12: error: redefinition of ‘struct __gnu_cxx::__add_unsigned<long long int>’
   95 |     struct __add_unsigned<long long>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/ext/type_traits.h:87:12: note: previous definition of ‘struct __gnu_cxx::__add_unsigned<long long int>’
   87 |     struct __add_unsigned<int>
      |            ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/ext/type_traits.h:138:12: error: redefinition of ‘struct __gnu_cxx::__remove_unsigned<long long unsigned int>’
  138 |     struct __remove_unsigned<unsigned long long>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/ext/type_traits.h:130:12: note: previous definition of ‘struct __gnu_cxx::__remove_unsigned<long long unsigned int>’
  130 |     struct __remove_unsigned<unsigned int>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/move.h:57,
                 from /usr/include/c++/11/bits/stl_pair.h:59,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/stl_tree.h:63,
                 from /usr/include/c++/11/map:60,
                 from answer.code:5:
/usr/include/c++/11/type_traits:320:12: error: redefinition of ‘struct std::__is_integral_helper<long long int>’
  320 |     struct __is_integral_helper<long long>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/type_traits:304:12: note: previous definition of ‘struct std::__is_integral_helper<long long int>’
  304 |     struct __is_integral_helper<int>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/type_traits:324:12: error: redefinition of ‘struct std::__is_integral_helper<long long unsigned int>’
  324 |     struct __is_integral_helper<unsigned long long>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/type_traits:308:12: note: previous definition of ‘struct std::__is_integral_helper<long long unsigned int>’
  308 |     struct __is_integral_helper<unsigned int>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/type_traits:1665:12: error: redefinition of ‘struct std::__make_unsigned<long long int>’
 1665 |     struct __make_unsigned<long long>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/type_traits:1657:12: note: previous definition of ‘struct std::__make_unsigned<long long int>’
 1657 |     struct __make_unsigned<int>
      |            ^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/type_traits:1819:12: error: redefinition of ‘struct std::__make_signed<long long unsigned int>’
 1819 |     struct __make_signed<unsigned long long>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/type_traits:1811:12: note: previous definition of ‘struct std::__make_signed<long long unsigned int>’
 1811 |     struct __make_signed<unsigned int>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/compare:39,
                 from /usr/include/c++/11/bits/stl_pair.h:65,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/stl_tree.h:63,
                 from /usr/include/c++/11/map:60,
                 from answer.code:5:
/usr/include/c++/11/concepts:219:55: error: no matching function for call to ‘declval<const std::ranges::__cust_swap::_Swap&>()’
  219 |           noexcept(noexcept(std::declval<co...