QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#353078#8338. Quad Kingdoms Chessucup-team093Compile Error//C++142.3kb2024-03-13 20:45:342024-03-13 20:45:35

Judging History

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

  • [2024-03-13 20:45:35]
  • 评测
  • [2024-03-13 20:45:34]
  • 提交

answer

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

using i64 = long long;
using big = __int128;

const int N = 1e5 + 10;

mt19937 rnd;

i64 b[N];

struct segTree {
    int n, tN;
    vector<int> a, maxp;
    vector<i64> h;

    void merge(int i) {
        maxp[i] = max(maxp[i * 2], maxp[i * 2 + 1]);
        h[i * 2 + 1] = (i * 2 + 1 >= tN ? b[a[i * 2 + 1 - tN]] : 0);
        if(maxp[i * 2] >= maxp[i * 2 + 1]) {
            for(int j = i * 2 * 2; j < tN * 2; ) {
                if(maxp[j + 1] >= maxp[i * 2 + 1]) j ++;
                h[i * 2 + 1] += h[j];
                j *= 2;
            }
        }
    }

    segTree(vector<int> &v) {
        n = v.size();
        a = v;
        a.insert(a.begin(), 0);
        tN = n + 2;
        while(tN != (tN & -tN)) tN += (tN & -tN);

        maxp = vector<int>(tN * 2);
        h = vector<i64>(tN * 2);
        for(int i = 1; i <= n; i ++) {
            maxp[tN + i] = a[i];
            h[tN + i] = b[a[i]];
        }
        
        for(int i = tN - 1; i; i --)
            merge(i);
    }

    void modify(int p, int x) {
        a[p] = x;
        maxp[tN + p] = x;
        h[tN + p] = b[x];

        for(int j = (tN + p) / 2; j; j /= 2)
            merge(j);
    }

    i64 query() {
        i64 ret = 0;
        for(int i = tN + n; i; i /= 2)
            ret += h[i];
        return ret;
    }

    i64 debug() {
        for(int i = 1; i < tN * 2; i ++)
            cout << i << ": " << maxp[i] << " " << h[i] << "\n";
        i64 ret = 0;
        for(int i = tN + n; i; i /= 2)
            ret += h[i];
        return ret;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    rnd = mt19937(time(0));

    for(int i = 0; i < N; i ++)
        b[i] = rnd();
    
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i ++)
        cin >> v[i];
    
    int m;
    cin >> m;
    vector<int> z(m);
    for(int i = 0; i < m; i ++)
        cin >> z[i];
    
    vector tr{segTree(v), segTree(z)};

    int q;
    cin >> q;
    for(int i = 0, op, p, x; i < q; i ++) {
        cin >> op >> p >> x;
        tr[op - 1].modify(p, x);
        if(tr[0].query() == tr[1].query()) cout << "YES\n";
        else cout << "NO\n";
    }
}

Details

answer.code: In function ‘int main()’:
answer.code:95:12: error: missing template arguments before ‘tr’
   95 |     vector tr{segTree(v), segTree(z)};
      |            ^~
answer.code:101:9: error: ‘tr’ was not declared in this scope; did you mean ‘tm’?
  101 |         tr[op - 1].modify(p, x);
      |         ^~
      |         tm