(我不会告诉你我**考试时推了40分钟的错式子)
找规律。
发现这些数是\(9,279,4779,67779,877779,10777779,127777779\cdots\)
?
结果考完试都说是等差 \(\times\) 等比 \(\cdots\)
(mdzz我要学高中数学)
#include<bits/stdc++.h>
#define R register int
#define ll long long
using namespace std;
namespace Luitaryi {
inline int g() { R x=0,f=1;
register char ch; while(!isdigit(ch=getchar())) f=ch=='-'?-1:f;
do x=x*10+(ch^48); while(isdigit(ch=getchar())); return x*f;
} const int M=233333,Inv=25926;
inline int qpow(int a,int b) { R ret=1;
for(;b;b>>=1,a=1ll*a*a%M) if(b&1) ret=1ll*ret*a%M; return ret;
}
int T,n,ans;
inline void main() {
freopen("bug.in","r",stdin);
freopen("bug.out","w",stdout);
T=g(); while(T--) { ans=0;
n=g();
if(n%2==0) --n;
if(n<=2) {puts("9"); continue;}
ans=(1ll*(n-1)%M*qpow(10,(n+1)/2)+70*(1ll*(qpow(10,n/2)-1+M)*Inv%M)%M+9)%M;
//cout<<1ll*(n-1)%M*qpow(10,(n+1)/2)<<' '<<70*(1ll*(qpow(10,n/2)-1+M)*Inv%M)%M<<' '<<9<<endl;
printf("%d\n",ans);
}
}
} signed main() {Luitaryi::main(); return 0;}
考试时只拿了\(60pts\),原因竟是数组开小了。
我的AK又没了
我也不知道他为什么对,先放个骗到了满分的代码,正解明天学。
#include<bits/stdc++.h>
#define R register int
#define ll long long
using namespace std;
namespace Luitaryi {
inline int g() { R x=0,f=1;
register char ch; while(!isdigit(ch=getchar())) f=ch=='-'?-1:f;
do x=x*10+(ch^48); while(isdigit(ch=getchar())); return x*f;
} const int N=5010;
int n,m;
namespace solve2 {
struct node { int l,r;
}a[1000010];
int p[N],d[N],mx;
ll s[N],f[N];
bool v[N];
inline void solve2() {
for(R i=1;i<=n;++i) s[i]=g(),s[i]+=s[i-1];
memset(d,0x3f,sizeof d);
for(R i=1,l,r;i<=m;++i)
l=a[i].l=g(),r=a[i].r=g(),v[l-1]=v[r]=1,
--p[l-1],++p[r],d[r]=min(d[r],l),mx=max(mx,r);
for(R i=n;i;--i) {
p[i]+=p[i+1];
if(p[i]) d[i]=min(d[i+1],d[i]);
}
for(R i=1;i<=n;++i) if(v[i]) {
for(R j=d[i];j<=i;++j)
f[i]=max(f[i],f[j-1]+1ll*(s[i]-s[j-1])*(s[i]-s[j-1]));
f[i]=max(f[i],f[i-1]);
} else f[i]=max(f[i],f[i-1]);
printf("%lld\n",f[mx]);
}
}
//namespace solve1 {
//struct node{int l,r;}a[1000010];
//int mem[N],p[N],s[N],anss[N]; ll sum,ans;
//inline void solve1() {
// for(R i=1;i<=n;++i) mem[i]=g();
// for(R i=1;i<=m;++i) a[i].l=g(),a[i].r=g();
// for(R i=1;i<=m;++i) p[i]=i;
// do { register ll ret=0;
// memcpy(s,mem,sizeof s);
// for(R t=1;t<=m;++t) { R i=p[t]; sum=0;
// for(R j=a[i].l;j<=a[i].r;++j) sum+=s[j],s[j]=0;
// ret+=1ll*sum*sum;
// } if(ans<ret) memcpy(anss,p,sizeof anss),ans=ret;
// } while(next_permutation(p+1,p+m+1));
// printf("%lld\n",ans);
// //for(R i=1;i<=m;++i) cout<<anss[i]<<' ';
//}
//}
inline void main() {
freopen("shopping.in","r",stdin);
freopen("shopping.out","w",stdout);
//freopen("in.in","r",stdin);
//freopen("ans.out","w",stdout);
n=g(),m=g();
//if(n<=10&&m<=8) solve1::solve1();
//else
solve2::solve2();
}
} signed main() {Luitaryi::main(); return 0;}
哈希二分lcp竟然过了。。。(后来发现高一学长由于没有用自然溢出T掉了。。。)
#include<bits/stdc++.h>
#define R register int
using namespace std;
namespace Luitaryi {
inline int g() { R x=0,f=1;
register char ch; while(!isdigit(ch=getchar())) f=ch=='-'?-1:f;
do x=x*10+(ch^48); while(isdigit(ch=getchar())); return x*f;
} const int B=147,N=300010;
#define u32 unsigned
int n,m,K,ans;
char s[N],t[N>>1];
u32 f[N],h[N>>1],p[N];
inline u32 hsh(int pos,int len) {return f[len+pos-1]-f[pos-1]*p[len];}
inline u32 hsh1(int pos,int len) {return h[len+pos-1]-h[pos-1]*p[len];}
inline int ckpos(int p1,int p2) {
R l=0,r=min(n-p1+1,m-p2+1);
while(l<r) {
R md=l+r+1>>1;
if(hsh(p1,md)==hsh1(p2,md)) l=md;
else r=md-1;
} return l;
}
inline void main() {
freopen("mo.in","r",stdin);
freopen("mo.out","w",stdout);
scanf("%s",s+1),scanf("%s",t+1); K=g();
n=strlen(s+1),m=strlen(t+1);
p[0]=1; for(R i=1,lim=max(n,m)+1;i<=lim;++i) p[i]=p[i-1]*B;
for(R i=1;i<=n;++i) f[i]=f[i-1]*B+s[i];
for(R i=1;i<=m;++i) h[i]=h[i-1]*B+t[i];
for(R i=1;i<=n-m+1;++i) { R cnt=0,lst=1;
while(cnt<=K) {
if(lst==m+1) {
++ans; break;}
R len=ckpos(i+lst-1,lst);
if(lst+len-1==m) {
++ans; break;}
else lst+=len,++lst; ++cnt;
}
} printf("%d\n",ans);
}
} signed main() {Luitaryi::main(); return 0;}
原文:https://www.cnblogs.com/Jackpei/p/11695868.html