QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#403380 | #7782. Ursa Minor | qf96 | TL | 1321ms | 265496kb | C++14 | 3.8kb | 2024-05-02 10:04:05 | 2024-05-02 10:04:07 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INT __int128
#define UINT __uint128_t
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb emplace_back
#define pc __builtin_popcount
#define pcl __builtin_popcountll
#define lb(x) ((x)&-(x))
using namespace std;
void __file(string s){freopen((s+".in").c_str(),"r",stdin),freopen((s+".out").c_str(),"w",stdout);}
const INT P=(ll)(1e18)+3,base=20080523;
INT qpow(INT x,INT y=P-2){INT z=1;while(y){if(y&1)z=z*x%P;x=x*x%P,y>>=1;}return z;}
const ll N=2e5+5,B=150;
ll pw[N],pi[N],pws[N];
struct BIT{
vector<ll> v;
int n;
void init(int siz){n=siz,v.resize(siz+3);}
inline void upd(int x,ll d){
for(;x<=n;x+=lb(x)) v[x]+=d;
}
inline ll qr(int x){
ll ans=0;for(;x;x-=lb(x))ans+=v[x];
return ans;
}
inline ll qr(int l,int r){return qr(r)-qr(l-1);}
}s[B+5][B+5],tree;//间隔i,模i余数1~i
inline void add(INT& x,INT y){x+=y;if(x>=P)x-=P;}
inline INT sub(INT x,INT y){add(x,P-y);return x;}
struct BIT_MOD{
INT v[N];
int n;
inline void upd(int x,INT d){
for(;x<=n;x+=lb(x)) add(v[x],d);
}
inline INT qr(int x){
INT ans=0;for(;x;x-=lb(x)) add(ans,v[x]);
return ans;
}
inline INT qr(int l,int r){return sub(qr(r),qr(l-1));}
}tmod;
ll n,m,q;
ll a[N],b[N];
ll re[N];
namespace OP{
ll l1[N],r1[N],d[N];
ll gcd[N];
void work(int l,int r,vector<int>& v){
if(l==r){
for(int i:v) d[i]=b[l];
return;
}
vector<int> lv,rv;
int mid=(l+r)>>1;
int i;
gcd[mid]=b[mid];
for(i=mid-1;i>=l;i--) gcd[i]=__gcd(gcd[i+1],b[i]);
gcd[mid+1]=b[mid+1];
for(i=mid+2;i<=r;i++) gcd[i]=__gcd(gcd[i-1],b[i]);
for(int i:v){
if(r1[i]<=mid) lv.pb(i);
else if(l1[i]>mid) rv.pb(i);
else{
d[i]=__gcd(gcd[l1[i]],gcd[r1[i]]);
}
}
work(l,mid,lv),work(mid+1,r,rv);
}
ll op[N];
void init(){
vector<int> v;for(int i=1;i<=q;i++) if(op[i]==2) v.pb(i);
work(1,m,v);
// for(int i=1;i<=q;i++) cerr<<d[i]<<' ';;cerr<<endl;
}
ll x[N],y[N];
ll l[N],r[N];
void input(){
char ch;
for(int i=1;i<=q;i++){
cin>>ch,op[i]=(ch=='Q')+1;
if(op[i]==1) cin>>x[i]>>y[i];
else cin>>l[i]>>r[i]>>l1[i]>>r1[i];
}
}
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
ll i,j,x,y;
cin>>n>>m>>q;
for(i=1;i<=n;i++) cin>>a[i];
for(i=1;i<=m;i++) cin>>b[i];
OP::input(),OP::init();
INT ib=qpow(base);
pw[0]=pi[0]=1;for(i=1;i<=n;i++) pw[i]=(INT)pw[i-1]*base%P,pi[i]=(INT)pi[i-1]*ib%P;
pws[0]=1;for(i=1;i<=n;i++) pws[i]=(pws[i-1]+pw[i])%P;
tree.init(n);for(i=1;i<=n;i++) tree.upd(i,a[i]);
tmod.n=n;
for(i=1;i<=n;i++) tmod.upd(i,(INT)pw[i]*a[i]%P);
for(i=1;i<=B;i++) for(j=1;j<=i;j++) s[i][j].init(n/i+1);
for(i=1;i<=B;i++) for(j=1;j<=n;j++){
s[i][(j-1)%i+1].upd((j-1)/i+1,a[j]);
}
for(int Q=1;Q<=q;Q++){
int op=OP::op[Q];
if(op==1){
x=OP::x[Q],y=OP::y[Q];
INT d=y-a[x];a[x]=y;
for(i=1;i<=B;i++){
s[i][(x-1)%i+1].upd((x-1)/i+1,d);
}
tree.upd(x,d);
// cerr<<x<<' '<<(ll)d<<endl;
d=(d+P)%P*pw[x]%P;
// cerr<<x<<' '<<(ll)d<<endl;
tmod.upd(x,d);
}
else{
ll l=OP::l[Q],r=OP::r[Q],d=OP::d[Q];
d=__gcd(d,r-l+1);
if(d<=B){
// cout<<1;
unordered_set<ll> st;
ll len=(r-l+1)/d;
for(i=l;i<l+d;i++){
st.insert(s[d][(i-1)%d+1].qr((i-1)/d+1,(i-1)/d+len));
if(st.size()>=2) break;
}
cout<<(st.size()==1?"Yes":"No")<<'\n';
}
else{
// cout<<2;
// cerr<<tree.qr(l,r)<<endl;
INT u=(tree.qr(l,r)/d%P+P)%P;
// cerr<<(ll)u<<endl;
// cout<<l<<' '<<r<<' '<<(ll)d<<' '<<(ll)u<<' '<<endl;
INT cnt=0,ec=0;
ec=u*pws[d-1]%P;
for(i=l;i<=r;i+=d){
cnt+=tmod.qr(i,i+d-1)*pi[i]%P;
}
cnt%=P;
cout<<(cnt==ec?"Yes":"No")<<'\n';
}
}
}
cerr<<clock()*1.0/CLOCKS_PER_SEC<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5216kb
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: 5084kb
input:
1 1 1 0 1 Q 1 1 1 1
output:
Yes
result:
ok "Yes"
Test #3:
score: 0
Accepted
time: 234ms
memory: 21072kb
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:
ok 100554 tokens
Test #4:
score: 0
Accepted
time: 98ms
memory: 20720kb
input:
1 200000 200000 998244353 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100240 tokens
Test #5:
score: 0
Accepted
time: 97ms
memory: 19724kb
input:
6 131072 200000 0 0 0 0 1000000000 1000000000 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ...
output:
Yes Yes Yes No No No Yes No No No No No Yes Yes No Yes No Yes Yes Yes No No No No No No No Yes No No No Yes Yes Yes Yes Yes Yes Yes Yes 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 Yes No No No No No No No No No No No No No No No Yes No No No No No No Yes Yes No Yes N...
result:
ok 100021 tokens
Test #6:
score: 0
Accepted
time: 1140ms
memory: 265392kb
input:
200000 200000 200000 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877...
output:
No No No No No No No No No No No No No No Yes No No No Yes No No No No No No No No No No No No No No Yes No No No No No Yes Yes Yes No No No No No No No No Yes No No No No No No No No 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 Yes No Yes Yes No No No No No No No No N...
result:
ok 187340 tokens
Test #7:
score: 0
Accepted
time: 1272ms
memory: 262272kb
input:
200000 200000 200000 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 199985 tokens
Test #8:
score: 0
Accepted
time: 1172ms
memory: 262224kb
input:
200000 200000 200000 793134805 922104801 158394038 993313213 77527653 992889267 148461787 499165677 132176015 189185554 783374975 332147281 923925325 371040161 393285793 437388761 138662855 212488140 265392646 498903298 578518594 550390771 960084339 408548934 56106823 814997309 456913457 300689692 1...
output:
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 No No No No No No No No No No No No No No Yes No No No No No No 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 Yes No...
result:
ok 200000 tokens
Test #9:
score: 0
Accepted
time: 1164ms
memory: 262464kb
input:
200000 200000 200000 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037...
output:
No No No No Yes No Yes No No No No Yes No No No Yes No Yes No No No No No No No No No No No No No No Yes No No No No No No No Yes No No Yes No Yes No Yes No Yes No No No No Yes No No Yes No No No No No No No No Yes No Yes No No No No Yes No Yes No No Yes No Yes No No No Yes No No No No No No No No N...
result:
ok 199977 tokens
Test #10:
score: 0
Accepted
time: 1321ms
memory: 265496kb
input:
200000 200000 200000 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606...
output:
No No No Yes No No No No No No No No No No No No Yes No No Yes No No No No No No No No No No Yes No No No No Yes No No No No No No No No Yes No No No No No No No No No No No No Yes No No No Yes No No No No No No No Yes No No No No No No No No No Yes No No No No No No No No No Yes No No No No No No N...
result:
ok 100329 tokens
Test #11:
score: -100
Time Limit Exceeded
input:
200000 199999 200000 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886...
output:
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 No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No...