QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358723#8338. Quad Kingdoms ChessKirill22#WA 59ms4340kbC++233.3kb2024-03-19 23:08:432024-03-19 23:08:44

Judging History

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

  • [2024-03-19 23:08:44]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:4340kb
  • [2024-03-19 23:08:43]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;

const int N = (int) 2e5;
const int mod = (int) 1e9 + 7, p = 1010101;
int pw[N];

int binpow(int x, int n) {
    int res = 1;
    while (n) {
        if (n & 1) {
            res = res * 1ll * x % mod;
        }
        x = x * 1ll * x % mod;
        n >>= 1;
    }
    return res;
}

struct tree {
    struct node {
        int mx, res, cnt;
    };

    vector<node> t;

    void update(int v, int l, int r, int& res, int& cnt, int& mx) {
        if (t[v].mx < mx) {
            return;
        }
        if (l + 1 == r) {
            res = (res + pw[cnt] * 1ll * t[v].mx) % mod;
            cnt++;
            mx = max(mx, t[v].mx);
            return;
        }
        if (t[v * 2 + 2].mx < mx) {
            update(v * 2 + 1, l, (l + r) / 2, res, cnt, mx);
        } else {
            update(v * 2 + 2, (l + r) / 2, r, res, cnt, mx);
            int h = (t[v].res - t[v * 2 + 2].res + mod) % mod;
            h = h * 1ll * binpow(t[v * 2 + 2].cnt, mod - 2) % mod;
            res = (res + pw[cnt] * 1ll * h) % mod;
            cnt += t[v].cnt - t[v * 2 + 2].cnt;
            mx = max(mx, t[v].mx);
        }
    }

    void upd(int v, int l, int r) {
        int res = t[v * 2 + 2].res;
        int cnt = t[v * 2 + 2].cnt;
        int mx = t[v * 2 + 2].mx;
        update(v * 2 + 1, l, (l + r) / 2, res, cnt, mx);
        t[v].mx = mx;
        t[v].res = res;
        t[v].cnt = cnt;
    }

    void build(int v, int l, int r, const vector<int>& a) {
        if (l + 1 == r) {
            t[v].mx = t[v].res = a[l];
            t[v].cnt = 1;
            return;
        }
        int m = (l + r) / 2;
        build(v * 2 + 1, l, m, a);
        build(v * 2 + 2, m, r, a);
        upd(v, l, r);
    }

    tree(int n, const vector<int>& a) {
        t.resize(4 * n);
        build(0, 0, n, a);
    }

    void set(int v, int l, int r, int i, int x) {
        if (l + 1 == r) {
            t[v].mx = t[v].res = x;
            t[v].cnt = 1;
            return;
        }
        int m = (l + r) / 2;
        if (i < m) {
            set(v * 2 + 1, l, m, i, x);
        } else {
            set(v * 2 + 2, m, r, i, x);
        }
        upd(v, l, r);
    }
};

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    tree A(n, a);
    int m;
    cin >> m;
    vector<int> b(m);
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    tree B(m, b);
    int q;
    cin >> q;
//    cout << A.t[0] << " " << B.t[0] << endl;
    while (q--) {
        int k, i, x;
        cin >> k >> i >> x;
        k--, i--;
        if (k == 0) {
            A.set(0, 0, n, i, x);
        } else {
            B.set(0, 0, m, i, x);
        }
//        cout << A.t[0] << " " << B.t[0] << endl;
//        cout << A.c[0] << " " << B.c[0] << endl;
        if (A.t[0].res == B.t[0].res) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    pw[0] = 1;
    for (int i = 1; i < N; i++) {
        pw[i] = pw[i - 1] * 1ll * p % mod;
    }
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 4340kb

input:

5
1 2 3 4 5
5
5 4 3 2 1
8
1 1 5
1 4 2
1 2 4
1 5 1
1 5 5
2 1 4
2 3 5
2 5 5

output:

NO
NO
NO
YES
NO
NO
NO
YES

result:

ok 8 tokens

Test #2:

score: 0
Accepted
time: 44ms
memory: 4332kb

input:

1
2
6
2 1 1 1 1 1
200000
2 6 2
1 1 1
1 1 1
1 1 2
2 1 1
1 1 2
1 1 1
2 4 1
2 1 2
1 1 1
1 1 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NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 200000 tokens

Test #4:

score: -100
Wrong Answer
time: 59ms
memory: 4284kb

input:

6
1 3 1 2 1 2
6
2 1 3 3 3 1
200000
2 4 2
1 2 1
1 6 2
2 3 2
1 1 1
1 6 2
1 6 2
1 3 2
2 6 1
2 4 3
1 1 2
2 5 2
2 6 2
2 3 1
1 4 3
1 3 1
2 5 2
2 4 2
2 1 3
1 1 1
2 2 2
2 4 2
1 5 3
1 6 3
2 6 3
1 5 3
2 5 3
2 4 1
2 4 2
1 1 2
1 6 1
2 6 1
1 2 3
1 1 3
1 1 1
2 6 3
2 4 1
1 4 2
2 2 1
1 3 1
1 1 3
1 1 3
1 4 3
1 3 3
2...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

wrong answer 195th words differ - expected: 'YES', found: 'NO'