QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#386642 | #7782. Ursa Minor | xlwang | WA | 471ms | 23284kb | C++14 | 4.9kb | 2024-04-11 18:58:00 | 2024-04-11 18:58:00 |
Judging History
answer
#include<bits/stdc++.h>
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
using namespace std;
inline int read(){
int x=0;
bool f=0;
char c=getchar();
while(!isdigit(c)) f|=(c=='-'),c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
return f?-x:x;
}
inline void write(int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
//inline void init(){
// int t=read();
// while(t--) work();
//}
const int Maxn=2e5+10,B=450,mod=1e9+7,base=1331,Maxb=460;
inline int ksm(int x,int y=mod-2){
int sum=1;
while(y){
if(y&1) sum=1ll*sum*x%mod;
y=y/2;x=1ll*x*x%mod;
}
return sum;
}
int n,q;
namespace GCD{
int lg[Maxn];
inline int gcd(int x,int y){
if(y==0) return x;
return gcd(y,x%y);
}
int ln;
int a[Maxn],f[Maxn][21];
inline void init(){
lg[0]=-1;
fr(i,1,ln) lg[i]=lg[i/2]+1;
fr(i,1,ln) f[i][0]=a[i];
fr(j,1,lg[ln]) fr(i,1,ln){
if(i+(1<<j)-1>ln) break;
f[i][j]=gcd(f[i][j-1],f[i+(1<<(j-1))][j-1]);
}
}
inline int getgcd(int l,int r){
int ln=lg[r-l+1];
return gcd(f[l][ln],f[r-(1<<ln)+1][ln]);
}
}
namespace bit{
int s[Maxn];
inline int lowbit(int x){return x&(-x);}
inline void update(int x,int k){
while(x<=n) s[x]+=k,x+=lowbit(x);
}
inline int query(int x){
int ans=0;
while(x) ans+=s[x],x-=lowbit(x);
return ans;
}
inline int getans(int l,int r){
return (query(r)-query(l-1)+mod)%mod;
}
}
inline void add(int &x,int y){
x+=y;if(x>=mod) x-=mod;
}
int a[Maxn];
int id[Maxn];
int bl[Maxn],br[Maxn];
int nod;
namespace ALL{
int pre[Maxn],s[Maxb];
int a[Maxn];
inline void update(int x,int k){
int now=1ll*(k-a[x]+mod)%mod;
fr(i,id[x],nod) add(s[i],now);
fr(i,x,br[id[x]]) add(pre[i],now);
a[x]=k;
}
inline int query(int x){
if(x<=0) return 0;
return (s[id[x]-1]+pre[x])%mod;
}
}
struct BLOCK{
int s[Maxn];
int S[Maxb];
int a[Maxn];
inline void update(int x,int k){
// cout<<x<<' '<<a[x]<<' '<<k<<endl;
S[id[x]]=1ll*(S[id[x]]-a[x]+k+mod)%mod;
s[x]=k;
}
inline int query(int x){
int ans=0;
fr(i,1,id[x]-1) add(ans,S[i]);
fr(i,bl[id[x]],x) add(ans,s[i]);
return ans;
}
}block[Maxb];
int ipw[Maxn];
int s[Maxn];
int pw[Maxn];
inline void init(){
n=read();GCD::ln=read();q=read();
fr(i,1,n) a[i]=read();
fr(i,1,GCD::ln) GCD::a[i]=read();
GCD::init();
fr(i,1,n){
id[i]=(i-1)/B+1;
if(!bl[id[i]]) bl[id[i]]=i;
br[id[i]]=i;
}
pw[0]=ipw[0]=1;s[0]=1;
fr(i,1,n) pw[i]=1ll*pw[i-1]*base%mod,ipw[i]=ksm(pw[i]);
fr(i,1,n) s[i]=pw[i],add(s[i],s[i-1]);
nod=id[n];
fr(i,1,B) fr(j,1,n) block[i].update(j,1ll*pw[j%i]*a[j]%mod);
fr(i,1,n) bit::update(i,a[i]);
fr(i,1,n) ALL::update(i,1ll*pw[i]*a[i]%mod);
}
inline void work(){
char ch[2];
while(q--){
scanf("%s",ch+1);
if(ch[1]=='U'){
int x,k;
x=read();k=read();
bit::update(x,(k-a[x]+mod)%mod);
fr(i,1,B) block[i].update(x,1ll*pw[x%i]*k%mod);
ALL::update(x,1ll*pw[x]*k%mod);a[x]=k;
}
else {
int l,r,ll,rr;
l=read();r=read();ll=read();rr=read();
int k=GCD::getgcd(ll,rr);k=GCD::gcd(k,(r-l+1));
// cout<<l<<' '<<r<<' '<<k<<endl;
int s1;s1=1ll*bit::getans(l,r)*ksm(k)%mod*s[k-1]%mod;
int s2=0;
// cout<<s1<<endl;
if(k<=B) s2=(block[k].query(r)-block[k].query(l-1)+mod)%mod;
else {
fr(i,0,n/k){
int nowl,nowr;
nowl=i*k,nowr=(i+1)*k-1;
nowl=max(nowl,l);nowr=min(nowr,r);
if(nowl>nowr) continue;
int now;now=(ALL::query(nowr)-ALL::query(nowl-1)+mod)%mod;
add(s2,1ll*now*ipw[i*k]%mod);
}
}
// cout<<k<<' '<<s1<<' '<<s2<<endl;
if(s1==s2) puts("Yes");
else puts("No");
}
}
}
signed main(){
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
init();work();
// printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 17708kb
input:
6 4 5 1 1 4 5 1 4 3 3 2 4 Q 1 5 1 2 Q 2 5 3 4 U 5 2 Q 1 6 1 2 Q 2 5 3 4
output:
Yes No No Yes
result:
ok 4 tokens
Test #2:
score: 0
Accepted
time: 2ms
memory: 17712kb
input:
1 1 1 0 1 Q 1 1 1 1
output:
Yes
result:
ok "Yes"
Test #3:
score: -100
Wrong Answer
time: 471ms
memory: 23284kb
input:
2000 2000 200000 1 1 2 0 0 2 0 2 0 0 0 0 0 2 2 1 2 0 0 2 2 2 1 0 1 2 1 2 0 0 1 1 1 2 0 0 2 2 2 2 0 2 0 0 2 1 2 0 0 1 2 2 1 0 2 0 0 0 1 2 2 1 2 2 0 0 1 1 1 0 0 2 0 0 1 1 0 2 2 2 1 0 0 1 0 1 2 2 2 1 1 2 2 1 2 1 0 2 2 3 1 3 2 3 1 0 1 2 0 1 1 1 0 2 2 3 2 0 3 2 3 3 1 2 3 1 2 0 1 0 3 1 0 0 2 0 1 2 1 3 2 2...
output:
Yes Yes No Yes Yes No No No Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes No Yes Yes No No No No No Yes No No No Yes Yes No Yes No Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes No Yes Yes Yes No No Yes No Yes No No No Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes No...
result:
wrong answer 135th words differ - expected: 'Yes', found: 'No'