QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#673733#8338. Quad Kingdoms ChessMiniLongWA 8ms32136kbC++204.8kb2024-10-25 09:27:022024-10-25 09:27:02

Judging History

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

  • [2024-10-25 09:27:02]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:32136kb
  • [2024-10-25 09:27:02]
  • 提交

answer

#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
    #ifdef ONLINE_JUDGE
    char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
    #define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
    #else
    #define get() getchar()
    #endif
    template<typename T> inline void read(T &t){
        T x = 0, f = 1;
        char c = getchar();
        while(!isdigit(c)){
            if(c == '-') f = -f;
            c = getchar();
        }
        while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
        t = x * f;
    }
    template<typename T, typename ... Args> inline void read(T &t, Args&... args){
        read(t);
        read(args...);
    }
    template<typename T> void write(T t){
        if(t < 0) putchar('-'), t = -t;
        if(t >= 10) write(t / 10);
        putchar(t % 10 + '0');
    }
    template<typename T, typename ... Args> void write(T t, Args... args){
        write(t), putchar(' '), write(args...);
    }
    template<typename T> void writeln(T t){
        write(t);
        puts("");
    }
    template<typename T> void writes(T t){
        write(t), putchar(' ');
    }
    #undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
    const ll mod = 998244853, mod2 = 2;
    ll ksm(ll p, ll h, ll mod){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
    void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
    void add(ll &x, ll y){x = (x + y) % mod;}
    void mul(ll &x, ll y){x = x * y % mod;}
    ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
    ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
    ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 1e5 + 5, _ = 1e5;
const ll base = 2e5 + 3;
ll pw[N], pw2[N], ipw[N], ipw2[N];
struct sgt{
    struct node{
        ll hsh, hsh2, maxn, cnt;
        node(int _x = 0){hsh = hsh2 = maxn = _x, cnt = _x > 0;}
        node operator+(const node b)const{
            node c;
            c.hsh = (hsh * pw[b.cnt] % mod + b.hsh) % mod;
            c.hsh2 = (hsh2 * pw2[b.cnt] % mod2 + b.hsh2) % mod2;
            c.maxn = max(maxn, b.maxn), c.cnt = cnt + b.cnt;
            return c;
        }
        node operator-(const node b)const{
            node c;
            c.hsh = (hsh - b.hsh + mod) % mod * ipw[b.cnt] % mod;
            c.hsh2 = (hsh2 - b.hsh2 + mod2) % mod2 * ipw2[b.cnt] % mod2;
            c.cnt = cnt - b.cnt;
            c.maxn = c.cnt ? maxn : 0;
            return c;
        }
    }tr[N << 2];
    #define ls x << 1
    #define rs x << 1 | 1
    node ask(int x, int l, int r, int cur){
        if(tr[x].maxn < cur) return node();
        if(l == r) return tr[x];
        int mid = l + r >> 1;
        if(tr[rs].maxn >= cur) return (tr[x] - tr[rs]) + ask(rs, mid + 1, r, cur);
        return ask(ls, l, mid, cur);
    }
    void update(int x, int l, int r){
        int mid = l + r >> 1;
        tr[x] = ask(ls, l, mid, tr[rs].maxn) + tr[rs];
    }
    void build(int x, int l, int r, int *a){
        if(l == r) return tr[x] = node(a[l]), void();
        int mid = l + r >> 1;
        build(ls, l, mid, a), build(rs, mid + 1, r, a);
        update(x, l, r);
    }
    void modify(int x, int l, int r, int p, int val){
        if(l == r) return tr[x] = node(val), void();
        int mid = l + r >> 1;
        if(p <= mid) modify(ls, l, mid, p, val);
        else modify(rs, mid + 1, r, p, val);
        update(x, l, r);
    }
};
struct Seq{
    int n, a[N];
    sgt tr;
    void init(){
        read(n); _rep(i, 1, n) read(a[i]);
        tr.build(1, 1, n, a);
    }
    void modify(int x, int val){
        tr.modify(1, 1, n, x, val);
    }
    PII ask(){
        return make_pair(tr.tr[1].hsh, tr.tr[1].hsh2);
    }
}p[2];
int main(){
    pw[0] = pw2[0] = ipw[0] = ipw2[0] = 1, pw[1] = pw2[1] = base, ipw[1] = ksm(base, mod - 2, mod), ipw2[1] = ksm(base, mod2 - 2, mod2); 
    _rep(i, 1, _){
        pw[i] = pw[i - 1] * base % mod, pw2[i] = pw2[i - 1] * base % mod2;
        ipw[i] = ipw[i - 1] * ipw[1] % mod, ipw2[i] = ipw2[i - 1] * ipw2[1] % mod2;
    }
    p[0].init(), p[1].init();
    multitest(){
        int op, x, y; read(op, x, y);
        p[op - 1].modify(x, y);
        puts(p[0].ask() == p[1].ask() ? "YES" : "NO");
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 32136kb

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: -100
Wrong Answer
time: 8ms
memory: 32076kb

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

result:

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