Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
24232 fyq & jbh's LCA 【BJ】T1 C++ 通过 100 94 MS 888 KB 2253 2023-12-20 09:28:41

Tests(10/10):


#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) using namespace std; typedef long long ll; const int maxn=5e5+10; inline ll read(){ ll x=0;short t=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; }int n,g,r; ll d[maxn],res[maxn]; struct node { int l,r; ll ans; }t[maxn]; bool operator<(node a,node b){if(a.r!=b.r)return a.r<b.r;return a.l<b.l;} ll qry(int x){ ll res=x; up(i,1,n){ res+=d[i]; if(res%(g+r)>=g)res=(res/(g+r)+1)*(g+r); }return res+d[n+1]; }void slv1(){ int q=read(); while(q--){ int x=read(); printf("%lld\n",qry(x)); } } void slv2(){ up(i,0,g+r-1)res[i]=qry(i); int q=read(); while(q--){ int x=read(); printf("%lld\n",res[x%(g+r)]+x-x%(g+r)); } } void slv3(){ res[0]=0; up(i,1,n){ res[i]=res[i-1]+d[1]; if(res[i]%(g+r)>=g)res[i]=(res[i]/(g+r)+1)*(g+r); }int q=read(); while(q--){ ll x=read(); up(j,1,n){ x+=d[j]; if(x%(g+r)>=g){ x=(x/(g+r)+1)*(g+r); x+=res[n-j];break; } }x+=d[n+1]; printf("%lld\n",x); } } void slv4(){ int now=0,tot=0; while(now<=g+r-1){ ll l=now,rr=g+r; t[++tot].ans=qry(l); while(l+1<rr){ ll mid=l+rr>>1; if(qry(mid)==t[tot].ans)l=mid; else rr=mid; }t[tot].l=now,t[tot].r=l; now=l+1; }//cout<<"test "<<tot<<'\n'; int q=read(); while(q--){ int x=read(); ll p=(*lower_bound(t+1,t+tot+1,(node){-1,x%(g+r),0})).ans; p+=x-x%(g+r); //assert(p==qry(x)); printf("%lld\n",p); } } void slv(){ n=read(),g=read(),r=read(); up(i,1,n+1)d[i]=read(); if(n<=100){ slv1();return; } if(g<=100&&r<=100){ slv2();return; }bool flg=1; up(i,2,n+1)if(d[i]!=d[1])flg=0; if(flg)slv3(); else slv4(); }int main(){ // freopen("light.in","r",stdin); // freopen("light.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }


测评信息: