QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#382330#7782. Ursa MinornguyentunglamCompile Error//C++173.6kb2024-04-08 12:31:402024-04-08 12:31:41

Judging History

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

  • [2024-04-08 12:31:41]
  • 评测
  • [2024-04-08 12:31:40]
  • 提交

answer

#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define endl "\n"
//#define int long long
using namespace std;

const int N = 2e5 + 10, T1 = 500, T2 = 300;
const long long base = 177013, mod = rnd(1e9, 1e9 + 100);

long long pw[N], f[N], a[N], sum[T1 + 10][N / T2 + 10];

long long sum_block[N / T2 + 10], pref_block[N / T2 + 10], pref[N];

int lg[N], rmq[20][N];

int b[N];

int n, m, q;

void handle (int p) {
  long long old = f[p];
  f[p] = p > 1 ? a[p] - a[p - 1] : a[p] - a[n];
  f[p] %= mod;
  for(int c = 1; c <= T1; c++) {
    sum[c][p / T2] += (f[p] - old) * pw[p % c] % mod;
  }
  sum_block[p / T2] += (f[p] - old) * pw[p] % mod;
  sum_block[p / T2] %= mod;
  pref_block[0] = sum_block[0];
  for(int i = 1; i <= n / T2; i++) pref_block[i] = pref_block[i - 1] + sum_block[i];
  for(int i = max(1, p / T2 * T2); i <= min(n, p / T2 * T2 + T2 - 1); i++) {
    pref[i] = (f[i] * pw[i] % mod);
    if (i != p / T2 * T2) pref[i] += pref[i - 1];
  }
}

long long get_block (int l, int r) {
  if (l != l / T2 * T2) return pref[r] - pref[l - 1];
  return pref[r];
}

long long get (int l, int r) {
  if (l / T2 == r / T2) return get_block(l, r);
  return get_block(r / T2 * T2, r) + get_block(l, l / T2 * T2 + T2 - 1) + pref_block[r / T2 - 1] - pref_block[l / T2];
}

void update(int p, int v) {
  a[p] = v;
  handle(p);
  if (p + 1 <= n) handle(p + 1);
  else handle(1);
}

tuple<int, int, int, int> query[N];

int get_gcd (int l, int r) {
  int k = lg[r - l + 1];
  return __gcd(rmq[k][l], rmq[k][r - (1 << k) + 1]);
}

int32_t main() {
  #define task ""

  cin.tie(0) -> sync_with_stdio(0);

  if (fopen("task.inp", "r")) {
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
  }

  if (fopen(task".inp", "r")) {
    freopen (task".inp", "r", stdin);
    freopen (task".out", "w", stdout);
  }

  cin >> n >> m >> q;

  pw[0] = 1;
  for(int i = 1; i <= n; i++) {
    pw[i] = pw[i - 1] * base % mod;
  }

  for(int i = 1; i <= n; i++) {
    cin >> a[i];
    update(i, a[i]);
  }

  for(int i = 2; i <= m; i++) lg[i] = lg[i / 2] + 1;

  for(int i = 1; i <= m; i++) cin >> rmq[0][i];

  for(int j = 1; j <= lg[m]; j++) for(int i = 1; i + (1 << j) - 1 <= m; i++) {
    rmq[j][i] = __gcd(rmq[j - 1][i], rmq[j - 1][i + (1 << j - 1)]);
  }

//  cout << get(4, 5);
//  return 0;

  while (q--) {
    char type; cin >> type;
    if (type == 'U') {
      int p, v; cin >> p >> v;
      update(p, v);
    }
    else {
      int x, y, u, v; cin >> x >> y >> u >> v;
      int c = __gcd(y - x + 1, get_gcd(u, v));
      long long hs = 0;
//      cout << c << endl;
      if (c <= T1) {
        int st = x / T2;
        int ed = y / T2;
        for(int i = st + 1; i < ed; i++) hs += sum[c][i];
        if (st == ed) {
          for(int i = x; i <= y; i++) hs += f[i] * pw[i % c] % mod;
        }
        else {
          for(int i = x; i <= st * T2 + T2 - 1; i++) hs += f[i] * pw[i % c] % mod;
          for(int i = y; i >= ed * T2; i--) hs += f[i] * pw[i % c] % mod;
        }
        hs -= f[x] * pw[x % c] % mod;
        hs += (a[x] - a[y]) * pw[x % c] % mod;
        hs %= mod;
//        cout << hs << endl;
        cout << (hs == 0 ? "Yes\n" : "No\n");
      }
      else {
        for(int i = x; i <= y; i += c) {
          hs += get(i, i + c - 1) % mod * pw[n - i] % mod;
////          cout << get(i, i + c - 1) << " " << i << " " << get(4, 5) << endl;
        }
        hs -= f[x] * pw[n] % mod;
        hs += (a[x] - a[y]) * pw[n] % mod;
        hs %= mod;
//        cout << hs << endl;
        cout << (hs == 0 ? "Yes\n" : "No\n");
      }
    }
  }
}

详细

answer.code:8:38: error: ‘rnd’ was not declared in this scope; did you mean ‘rand’?
    8 | const long long base = 177013, mod = rnd(1e9, 1e9 + 100);
      |                                      ^~~
      |                                      rand
answer.code: In function ‘int32_t main()’:
answer.code:67:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   67 |     freopen("task.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
answer.code:68:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |     freopen("task.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:72:13: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   72 |     freopen (task".inp", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
answer.code:73:13: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   73 |     freopen (task".out", "w", stdout);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~