洛谷10月月赛R2
A.浮游大陆的68号岛(模拟+前缀和)AC。注意开ll,分左右情况讨论即可。
B.Chtholly Nota Seniorious 完全不会。水了20分。
B的题解看这里:传送门
C.Nephren Ruq Insania 瞎搞了60分。欧拉定理我哪会啊。。
#include
using namespace std;
#define N 200010
#define inf 0x3f3f3f3f
#define ll long long
#define mod 19260817
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
int n,m,d[N],w[N];
ll sw[N],s[N];
int main(){
// freopen("sample5.in","r",stdin);
// freopen("a.out","w",stdout);
n=read();m=read();
for(int i=2;i<=n;++i) d[i]=read(),d[i]=(d[i]+d[i-1])%mod;
for(int i=1;i<=n;++i) w[i]=read(),sw[i]=(sw[i-1]+w[i])%mod;
for(int i=1;i<=n;++i) s[i]=(ll)w[i]*d[i]%mod,s[i]=(s[i]+s[i-1])%mod;
while(m--){
int x=read(),l=read(),r=read();ll res=0;
if(x<=l) res=s[r]-s[l-1]-(sw[r]-sw[l-1])*d[x];
else if(x>=r) res=(sw[r]-sw[l-1])*d[x]-(s[r]-s[l-1]);
else res=s[r]-s[x]-(sw[r]-sw[x])*d[x]-(s[x-1]-s[l-1]-(sw[x-1]-sw[l-1])*d[x]);
if(res<0) res=res+mod*10000000000LL;
printf("%lld\n",res%mod);
}return 0;
}
#include
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 2010
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
int n,m,a[4][N][N],tmp[N][N],mx=0,mn=inf,now=0;
void rotate(int x,int y){
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
a[y][j][n-i+1]=a[x][i][j];
}
bool check(int x){
int last=m;
for(int i=1;i<=n;++i){
for(int j=1;j<=last;++j)
if(a[now][i][j]1;break;}
for(int j=last+1;j<=m;++j)
if(a[now][i][j]>mn+x) return 0;
}return 1;
}
bool jud(int x){
if(check(x)) return 1;now++;now&=3;swap(n,m);
if(check(x)) return 1;now++;now&=3;swap(n,m);
if(check(x)) return 1;now++;now&=3;swap(n,m);
if(check(x)) return 1;return 0;
}
int main(){
// freopen("sample3.in","r",stdin);
n=read();m=read();
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j) a[now][i][j]=read(),mx=max(mx,a[now][i][j]),mn=min(mn,a[now][i][j]);
for(int i=1;i<=3;++i){
rotate(now,now+1);now++;swap(n,m);
}now=0;swap(n,m);
int l=0,r=mx-mn;
while(l<=r){
int mid=l+r>>1;
if(jud(mid)) r=mid-1;else l=mid+1;
}printf("%d\n",r+1);
return 0;
}
瞎搞60分版。
#include
using namespace std;
#define N 100010
#define inf 0x3f3f3f3f
#define ll long long
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
int n,m,mod;
ll a[N];
struct que{
int op,l,r,x;
}q[N];
struct node{
ll x;
}tree[N<<2];
void build(int p,int l,int r){
if(l==r){tree[p].x=a[l];return;}
int mid=l+r>>1;
build(p<<1,l,mid);build(p<<1|1,mid+1,r);
}
void add(int p,int l,int r,int x,int y,int val){
if(x<=l&&r<=y){tree[p].x+=val;return;}
int mid=l+r>>1;
if(x<=mid) add(p<<1,l,mid,x,y,val);
if(y>mid) add(p<<1|1,mid+1,r,x,y,val);
}
ll ask(int p,int l,int r,int x){
if(l==r) return tree[p].x;
int mid=l+r>>1;
if(x<=mid) return ask(p<<1,l,mid,x)+tree[p].x;
else return ask(p<<1|1,mid+1,r,x)+tree[p].x;
}
inline ll ksm(ll base,ll k){
ll res=1;
for(;k;k>>=1,base=base*base%mod)
if(k&1) res=res*base%mod;return res;
}
void solve0(){
while(m--){
int op=read(),l=read(),r=read(),x=read();
if(op==1) for(int i=l;i<=r;++i) a[i]+=x;
if(op==2){
int res=a[r]%x;mod=x;
for(int i=r-1;i>=l;--i) res=ksm(a[i]%x,res);
printf("%d\n",res);
}
}
}
void solve1(){
for(int i=1;i<=m;++i){
if(q[i].op==1) add(1,1,n,q[i].l,q[i].r,q[i].x);
if(q[i].op==2){
mod=q[i].x;
if(q[i].l==q[i].r) printf("%lld\n",ask(1,1,n,q[i].l)%mod);
else printf("%lld\n",ksm(ask(1,1,n,q[i].l)%mod,ask(1,1,n,q[i].r)));
}
}
}
void solve2(){
for(int i=1;i<=m;++i){
if(q[i].op==1) add(1,1,n,q[i].l,q[i].r,q[i].x);
if(q[i].op==2){
if(ask(1,1,n,q[i].l)%2) puts("1");
else puts("0");
}
}
}
int main(){
freopen("sample3.in","r",stdin);
freopen("a.out","w",stdout);
n=read();m=read();for(int i=1;i<=n;++i) a[i]=read();
if(n==5){solve0();return 0;}bool flag1=1,flag2=1;
for(int i=1;i<=m;++i){
q[i].op=read(),q[i].l=read(),q[i].r=read(),q[i].x=read();
if(q[i].op==2&&q[i].r-q[i].l+1>2) flag1=0;
if(q[i].op==2&&q[i].x!=2) flag2=0;
}build(1,1,n);
if(flag1){solve1();return 0;}
if(flag2){solve2();return 0;}
return 0;
}