QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578630#8338. Quad Kingdoms ChessOkuchiriWA 85ms9944kbC++202.7kb2024-09-20 20:31:122024-09-20 20:31:13

Judging History

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

  • [2024-09-20 20:31:13]
  • 评测
  • 测评结果:WA
  • 用时:85ms
  • 内存:9944kb
  • [2024-09-20 20:31:12]
  • 提交

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])*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])*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: 9844kb

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: 61ms
memory: 9868kb

input:

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

result:

ok 200000 tokens

Test #4:

score: -100
Wrong Answer
time: 85ms
memory: 9944kb

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 2135th words differ - expected: 'NO', found: 'YES'