QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#589685#8338. Quad Kingdoms ChessDBsoleilCompile Error//C++204.0kb2024-09-25 19:39:352024-09-25 19:39:35

Judging History

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

  • [2024-09-25 19:39:35]
  • 评测
  • [2024-09-25 19:39:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

static constexpr int Maxn = 1e5 + 5, SqrN = 405, MaxB = 1205;

static constexpr uint64_t MOD1 = 1e9 + 9, MOD2 = 1e9 + 7;
static constexpr uint64_t BASE1 = 1e5 + 3, BASE2 = 1e5 + 19;
using hash_t = pair<uint64_t, uint64_t>;
hash_t operator + (hash_t lhs, int v)
{ return hash_t((lhs.first * BASE1 + v) % MOD1, (lhs.second * BASE2 + v) % MOD2); }
hash_t operator + (hash_t lhs, hash_t rhs)
{ return hash_t((lhs.first + rhs.first) % MOD1, (lhs.second + rhs.second) % MOD2); }
hash_t operator * (hash_t lhs, hash_t rhs)
{ return hash_t(lhs.first * rhs.first % MOD1, lhs.second * rhs.second % MOD2); }
const hash_t BASE = hash_t(BASE1, BASE2);
hash_t pw[Maxn];
using data_t = pair<int, hash_t>;
data_t operator + (data_t lhs, data_t rhs) {
  if (lhs.first == 0) return rhs;
  return data_t(lhs.first + rhs.first, hash_t(lhs.second * pw[rhs.first] + rhs.second));
} data_t New(uint64_t v) { return data_t(1, hash_t(v, v)); }

struct Array {
  int n, bn, bs, a[Maxn];
  int bel[Maxn], bL[Maxn], bR[Maxn];
  data_t h[Maxn];
  bool upd[Maxn];
  vector<pair<int, data_t>> hv[MaxB];
  unordered_map<int, data_t> mp[MaxB];
  void rebuild(int b) {
    int l = bL[b], r = bR[b];
    for (int i = l; i <= r; ++i) upd[i] = false;
    h[l] = New(a[l]); upd[l] = true;
    for (int i = l + 1, p = l; i <= r; ++i)
      if (a[i] >= a[p])
        h[i] = h[p] + New(a[i]), p = i, upd[i] = true;
      else h[i] = h[i - 1];
    hv[b].clear();
    mp[b].clear();
    hash_t cur = {0, 0};
    int len = 0;
    for (int i = r; i >= l; --i)
      if (upd[i]) {
        (cur.first += pw[len].first * a[i]) %= MOD1;
        (cur.second += pw[len].second * a[i]) %= MOD2;
        ++len;
        hv[b].emplace_back(a[i], data_t(len, cur));
      }
    reverse(hv[b].begin(), hv[b].end());
  } // Array::rebuild
  data_t qblock(int b, data_t res, int &pre) {
    if (pre > hv[b].back().first) return res;
    if (mp[b].find(pre) != mp[b].end()) {
      pre = hv[b].back().first;
      return res + mp[b][pre];
    }
    int l = bL[b], r = bR[b];
    auto it = lower_bound(hv[b].begin(), hv[b].end(), pair(pre, data_t()));
    if (it == hb[v].end()) return res;
    // fprintf(stderr, "l = %d, r = %d, it = %d\n", l, r, it - hv[b].begin());
    // fprintf(stderr, "|hv[%d]| = %d\n", b, (int)hv[b].size()); fflush(stderr);
    pre = hv[b].back().first;
    // fprintf(stderr, "pre = %d\n", pre);
    res = res + it->second;
    return mp[b][pre] = res;
  } // qblock
  data_t query(void) {
    data_t res = h[bR[1]];
    int cur = hv[1].back().first;
    // fprintf(stderr, "cur = %d\n", cur);
    for (int i = 2; i <= bn; ++i)
      res = qblock(i, res, cur);
    return res;
  } // Array::query
  void input(void) {
    scanf("%d", &n); bs = min(700, n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    reverse(a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i) bel[i] = (i - 1) / bs + 1;
    bn = bel[n];
    for (int i = 1; i <= bn; ++i) {
      bL[i] = (i - 1) * bs + 1;
      bR[i] = min(i * bs, n);
    }
    for (int i = 1; i <= bn; ++i) rebuild(i);
  } // Array::input
  void update(int x, int y) {
    x = n - x + 1, a[x] = y;
    rebuild(bel[x]);
  } // update
} a[2];

int main(void) {
  pw[0] = {1, 1};
  for (int i = 1; i < Maxn; ++i)
    pw[i] = pw[i - 1] * hash_t(BASE1, BASE2);
  a[1].input(); a[0].input();
  int qn; scanf("%d", &qn);
  while (qn--) {
    int op, x, y;
    scanf("%d%d%d", &op, &x, &y);
    // fprintf(stderr, "------------------------- %d, %d, %d\n", op, x, y); fflush(stderr);
    a[op % 2].update(x, y);
    // fprintf(stderr, "update success!\n");
    auto a1 = a[1].query(), a2 = a[0].query();
    // fprintf(stderr, "a1 = (%d, (%lu, %lu))\n", a1.first, a1.second.first, a1.second.second);
    // fprintf(stderr, "a2 = (%d, (%lu, %lu))\n", a2.first, a2.second.first, a2.second.second);
    if (a1 != a2) printf("NO\n");
    else printf("YES\n");
  }
  return 0;
} // main

详细

answer.code: In member function ‘data_t Array::qblock(int, data_t, int&)’:
answer.code:59:15: error: ‘hb’ was not declared in this scope; did you mean ‘h’?
   59 |     if (it == hb[v].end()) return res;
      |               ^~
      |               h
answer.code:59:18: error: ‘v’ was not declared in this scope
   59 |     if (it == hb[v].end()) return res;
      |                  ^
answer.code: In function ‘int main()’:
answer.code:98:16: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   98 |   int qn; scanf("%d", &qn);
      |           ~~~~~^~~~~~~~~~~
answer.code:101:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  101 |     scanf("%d%d%d", &op, &x, &y);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
answer.code: In member function ‘void Array::input()’:
answer.code:76:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   76 |     scanf("%d", &n); bs = min(700, n);
      |     ~~~~~^~~~~~~~~~
answer.code:77:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   77 |     for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
      |                                  ~~~~~^~~~~~~~~~~~~