QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133560 | #4940. Token Distance | SolitaryDream# | WA | 14ms | 17316kb | C++20 | 3.2kb | 2023-08-02 11:09:06 | 2023-08-02 11:09:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+1e3+7,K=4,P=998244353,iv2=(P+1)/2,iv3=(P+1)/3,iv6=iv2*iv3%P;
int C[K][K];
int n,q;
int cnt,a[N];
struct T{
int l,r,ls,rs;
int mx,mn;
int s[K];
}t[N*2+1];
void update(int x)
{
t[x].mx=max(t[t[x].ls].mx,t[t[x].rs].mx);
t[x].mn=min(t[t[x].ls].mn,t[t[x].rs].mn);
for(int i=0;i<K;i++)
t[x].s[i]=(t[t[x].ls].s[i]+t[t[x].rs].s[i])%P;
}
int build(int l,int r)
{
int x=++cnt;
t[x].l=l,t[x].r=r;
if(l==r)
{
t[x].mx=t[x].mn=a[l];
int j=1;
for(int i=0;i<K;i++)
t[x].s[i]=j,j=j*a[l]%P;
return x;
}
int mid=(l+r)>>1;
t[x].ls=build(l,mid);
t[x].rs=build(mid+1,r);
update(x);
return x;
}
void change(int x,int p)
{
if(t[x].l==t[x].r)
{
t[x].mx=t[x].mn=a[p];
int j=1;
for(int i=0;i<K;i++)
t[x].s[i]=j,j=j*a[p];
return;
}
int mid=(t[x].l+t[x].r)>>1;
if(p<=mid)
change(t[x].ls,p);
else
change(t[x].rs,p);
update(x);
}
int qmx,qmn,S[K];
void qry(int x,int l,int r)
{
if(l<=t[x].l&&t[x].r<=r)
{
qmx=max(qmx,t[x].mx);
qmn=min(qmn,t[x].mn);
for(int i=0;i<K;i++)
S[i]=(S[i]+t[x].s[i])%P;
return;
}
int mid=(t[x].l+t[x].r)>>1;
if(l<=mid)
qry(t[x].ls,l,r);
if(r>mid)
qry(t[x].rs,l,r);
}
int cs(int x,int k)
{
if(k==0)
return x+1;
if(k==1)
return x*(x+1)%P*iv2%P;
if(k==2)
return x*(x+1)%P*(2*x+1)%P*iv6%P;
if(k==3)
return x*(x+1)%P*iv2%P*x%P*(x+1)%P*iv2%P;
assert(0);
}
int eS[K];
int qpow(int a,int b)
{
int ret=1;
while(b)
{
if(b&1)
ret=1ll*ret*a%P;
b>>=1;
a=1ll*a*a%P;
}
return ret;
}
void calc(int n,int a,int b)
{
for(int k=0;k<K;k++)
{
eS[k]=0;
for(int j=0;j<=k;j++)
{
int coe=qpow(a,k-j)*qpow(b,j)%P*C[k][j]%P;
eS[k]=(eS[k]+coe*cs(n,j))%P;
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
C[0][0]=1;
for(int i=1;i<K;i++)
{
C[i][0]=1;
for(int j=1;j<=i;j++)
C[i][j]=(C[i-1][j-1]+C[i-1][j])%P;
}
cin>>n>>q;
for(int i=1;i<=n;i++)
cin>>a[i];
build(1,n);
while(q--)
{
int op,x,y;
cin>>op>>x>>y;
if(op==1)
{
a[x]=y;
change(1,x);
}
else
{
if(x==y)
{
cout<<"YES\n";
continue;
}
qmx=-1e18,qmn=1e18;
for(int j=0;j<K;j++)
S[j]=0;
qry(1,x,y);
int d=qmx-qmn;
if(d%(y-x))
{
cout<<"NO\n";
continue;
}
d/=(y-x);
calc(y-x,qmn,d);
int ok=1;
for(int i=0;i<K;i++)
if(eS[i]!=S[i])
ok=0;
cout<<(ok?"YES":"NO")<<"\n";
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3480kb
input:
5 7 1 1 1 10 1 2 1 3 2 1 5 1 5 4 1 3 7 2 2 4 2 2 5 2 4 5
output:
YES NO NO YES YES
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 5520kb
input:
2 1 0 1000000000 2 1 2
output:
YES
result:
ok single line: 'YES'
Test #3:
score: -100
Wrong Answer
time: 14ms
memory: 17316kb
input:
81473 13549 972586683 972586964 972587245 972587526 972587807 972588088 972588369 972588650 972588931 972589212 972589493 972589774 972590055 972590336 972590617 972590898 972591179 972591460 972591741 972592022 972592303 972592584 972592865 972593146 972593427 972593708 972593989 972594270 97259455...
output:
YES YES YES NO NO YES NO 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 YES 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 N...
result:
wrong answer 4th lines differ - expected: 'YES', found: 'NO'