QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725628#6533. Traveling in CellsTheZoneCompile Error//C++203.2kb2024-11-08 19:08:402024-11-08 19:08:41

Judging History

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

  • [2024-11-08 19:08:41]
  • 评测
  • [2024-11-08 19:08:40]
  • 提交

answer

#include <bits/stdc++.h>
#define MAXN ((int) 3e5)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();struct chash { int operator()(int x) const { return x ^ RANDOM; }};typedef gp_hash_table<int, int, chash> hash_t;int n, q, C[MAXN + 10], V[MAXN + 10];hash_t colTree[MAXN + 10];long long smTree[MAXN + 10];int lb(int x) { return x & (-x); }void addCol(int pos, int c, int val) {for (; pos <= n; pos += lb(pos)) colTree[pos][c] += val;}int queryCol(int pos, vector<int> &vec) {
    int ret = 0;
    for (; pos; pos -= lb(pos)) for (int c : vec) {
        auto it = colTree[pos].find(c);
        if (it != colTree[pos].end()) ret += it->second;
    }
    return ret;
int gao1(int lim, vector<int> &vec) {
    int base = queryCol(lim, vec);
    if (base == lim) return 1;
    int b;
    for (b = 1; b <= n; b <<= 1);
    int now = 0, cnt = 0;
    for (b >>= 1; b; b >>= 1) {
        int nxt = now | b, tmp = 0;
        for (int c : vec) {
            auto it = colTree[nxt].find(c);
            if (it != colTree[nxt].end()) tmp += it->second;
        }
        if (nxt > lim || base - (cnt + tmp) == lim - nxt) {
        } else {
            now = nxt; cnt += tmp;
        }
    }
    return now + 2;
}
int gao2(int lim, vector<int> &vec) {
    int base = queryCol(lim, vec);
    int b;
    for (b = 1; b <= n; b <<= 1);
    int now = 0, cnt = 0;
    for (b >>= 1; b; b >>= 1) {
        int nxt = now | b, tmp = 0;
        for (int c : vec) {
            auto it = colTree[nxt].find(c);
            if (it != colTree[nxt].end()) tmp += it->second;
        }
        if (nxt < lim || (cnt + tmp) - base == nxt - lim) {
            now = nxt; cnt += tmp;
        } else {
        }
    }
    return now;
}
void addSm(int pos, long long val) {
    for (; pos <= n; pos += lb(pos)) smTree[pos] += val;
}
long long querySm(int pos) {
    long long ret = 0;
    for (; pos; pos -= lb(pos)) ret += smTree[pos];
    return ret;
}
void solve() {
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &C[i]);
        addCol(i, C[i], 1);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d", &V[i]);
        addSm(i, V[i]);
    }
    while (q--) {
        int op, x, y; scanf("%d%d%d", &op, &x, &y);
        if (op == 1) {
            addCol(x, C[x], -1);
            addCol(x, y, 1);
            C[x] = y;
        } else if (op == 2) {
            addSm(x, y - V[x]);
            V[x] = y;
        } else {
            bool ok = false;
            vector<int> vec;
            for (int i = 1; i <= y; i++) {
                int z; scanf("%d", &z);
                if (C[x] == z) ok = true;
                vec.push_back(z);
            }
            if (!ok) { printf("0\n"); continue; }
            int L = gao1(x, vec), R = gao2(x, vec);
            printf("%lld\n", querySm(R) - querySm(L - 1));
        }
    }
    for (int i = 1; i <= n; i++) colTree[i].clear();
    for (int i = 1; i <= n; i++) smTree[i] = 0;
}
int main() {
    int tcase; scanf("%d", &tcase);
    while (tcase--) solve();
    return 0;
}

Details

answer.code: In function ‘int queryCol(int, std::vector<int>&)’:
answer.code:12:37: error: a function-definition is not allowed here before ‘{’ token
   12 | int gao1(int lim, vector<int> &vec) {
      |                                     ^
answer.code:31:37: error: a function-definition is not allowed here before ‘{’ token
   31 | int gao2(int lim, vector<int> &vec) {
      |                                     ^
answer.code:49:36: error: a function-definition is not allowed here before ‘{’ token
   49 | void addSm(int pos, long long val) {
      |                                    ^
answer.code:52:28: error: a function-definition is not allowed here before ‘{’ token
   52 | long long querySm(int pos) {
      |                            ^
answer.code:57:14: error: a function-definition is not allowed here before ‘{’ token
   57 | void solve() {
      |              ^
answer.code:92:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   92 | int main() {
      |         ^~
answer.code:92:9: note: remove parentheses to default-initialize a variable
   92 | int main() {
      |         ^~
      |         --
answer.code:92:9: note: or replace parentheses with braces to value-initialize a variable
answer.code:92:12: error: a function-definition is not allowed here before ‘{’ token
   92 | int main() {
      |            ^
answer.code:96:2: error: expected ‘}’ at end of input
   96 | }
      |  ^
answer.code:5:484: note: to match this ‘{’
    5 | using namespace __gnu_pbds;const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();struct chash { int operator()(int x) const { return x ^ RANDOM; }};typedef gp_hash_table<int, int, chash> hash_t;int n, q, C[MAXN + 10], V[MAXN + 10];hash_t colTree[MAXN + 10];long long smTree[MAXN + 10];int lb(int x) { return x & (-x); }void addCol(int pos, int c, int val) {for (; pos <= n; pos += lb(pos)) colTree[pos][c] += val;}int queryCol(int pos, vector<int> &vec) {
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ^