QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578687#8338. Quad Kingdoms ChessOkuchiriWA 92ms9964kbC++202.7kb2024-09-20 20:49:032024-09-20 20:49:04

Judging History

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

  • [2024-09-20 20:49:04]
  • 评测
  • 测评结果:WA
  • 用时:92ms
  • 内存:9964kb
  • [2024-09-20 20:49:03]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll ksm(ll x,ll y)
{
    ll res=1;
    while(y)
    {
        if(y&1)res=res*x%mod;
        x=x*x%mod;
        y=y/2;
    }
    return res;
}
ll n,m,bas1,bas2;
ll mx[400010][2];
ll cnt[400010][2];
ll hsh1[400010][2];
ll hsh2[400010][2];
ll count(ll now,ll l,ll r,ll k,ll t)
{
    if(l==r)
    {
        return mx[now][t]>=k;
    }
    ll mid=(l+r)/2;
    if(mx[now*2][t]<k)return count(now*2+1,mid+1,r,k,t);
    return cnt[now][t]-cnt[now*2][t]+count(now*2,l,mid,k,t);
}
ll geths1(ll now,ll l,ll r,ll k,ll t)
{
    if(l==r)
    {
        if(mx[now][t]>=k)return mx[now][t];
        return 0;
    }
    ll mid=(l+r)/2;
    if(mx[now*2][t]<k)return geths1(now*2+1,mid+1,r,k,t);
    ll h=count(now*2,l,mid,k,t);
    return ((hsh1[now][t]-hsh1[now*2][t]+mod)%mod*ksm(ksm(bas1,cnt[now*2][t]),mod-2)%mod*ksm(bas1,h)%mod+geths1(now*2,l,mid,k,t))%mod;
}
ll geths2(ll now,ll l,ll r,ll k,ll t)
{
    if(l==r)
    {
        if(mx[now][t]>=k)return mx[now][t];
        return 0;
    }
    ll mid=(l+r)/2;
    if(mx[now*2][t]<k)return geths1(now*2+1,mid+1,r,k,t);
    ll h=count(now*2,l,mid,k,t);
    return ((hsh2[now][t]-hsh2[now*2][t]+mod)%mod*ksm(ksm(bas2,cnt[now*2][t]),mod-2)%mod*ksm(bas2,h)%mod+geths2(now*2,l,mid,k,t))%mod;
}
void change(ll now,ll l,ll r,ll k,ll x,ll t)
{
    if(l==r)
    {
        mx[now][t]=x;
        cnt[now][t]=1;
        hsh1[now][t]=x;
        hsh2[now][t]=x;
        return;
    }
    ll mid=(l+r)/2;
    if(k<=mid)change(now*2,l,mid,k,x,t);
    else change(now*2+1,mid+1,r,k,x,t);
    mx[now][t]=max(mx[now*2][t],mx[now*2+1][t]);
    cnt[now][t]=cnt[now*2][t]+count(now*2+1,mid+1,r,mx[now*2][t],t);
    hsh1[now][t]=(hsh1[now*2][t]+ksm(bas1,cnt[now*2][t])*geths1(now*2+1,mid+1,r,mx[now*2][t],t)%mod)%mod;
    hsh2[now][t]=(hsh2[now*2][t]+ksm(bas2,cnt[now*2][t])*geths2(now*2+1,mid+1,r,mx[now*2][t],t)%mod)%mod;
}

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    srand(time(0));
    cin>>n;
    bas1=rand();
    bas2=rand();
    bas1=bas1*1145141ll%mod;
    bas2=bas2*1145141ll%mod;
    for(int i=1;i<=n;i++)
    {
        ll x;
        cin>>x;
        change(1,1,n,n-i+1,x,0);
    }
    cin>>m;
    for(int i=1;i<=m;i++)
    {
        ll x;
        cin>>x;
        change(1,1,m,m-i+1,x,1);
    }
    ll q;
    cin>>q;
    while(q--)
    {
        ll opt,x,y;
        cin>>opt>>x>>y;
        if(opt==1)
        {
            change(1,1,n,n-x+1,y,0);
        }
        else change(1,1,m,m-x+1,y,1);
        if(hsh1[1][0]==hsh1[1][1]&&hsh2[1][0]==hsh2[1][1])cout<<"YES\n";
        else cout<<"NO\n";
    }
}

詳細信息

Test #1:

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

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: 64ms
memory: 9800kb

input:

1
2
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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
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: 0
Accepted
time: 92ms
memory: 9768kb

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:

ok 200000 tokens

Test #5:

score: 0
Accepted
time: 40ms
memory: 9804kb

input:

4
1 1 2 2
1
1
200000
2 1 2
1 1 3
1 2 1
2 1 2
2 1 2
2 1 3
2 1 1
2 1 1
1 4 2
2 1 3
1 3 1
1 2 1
1 3 2
2 1 1
1 4 2
2 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
N...

result:

ok 200000 tokens

Test #7:

score: 0
Accepted
time: 72ms
memory: 9788kb

input:

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

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
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO...

result:

ok 200000 tokens

Test #8:

score: 0
Accepted
time: 50ms
memory: 9800kb

input:

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

result:

wrong answer 19732nd words differ - expected: 'YES', found: 'NO'