题解:AT_abc425_c [ABC425C] Rotate and Sum Query
weiwei1000 · · 题解
题目简述
长度为
有两个操作:
1 c:将A 数组往左移c 位,第一位变为第N 位。2 l r:输出A 数组中的第l 位到第r 位的和。
思路
所以可以预处理长度为
因为左移
而统计区间和则使用方便快捷的前缀和,统计
别忘记 long long 本题数据范围是
::::success[AC 代码]
#include<bits/stdc++.h>
#define int long long //重要
using namespace std;
using ll=long long;
const int N=2e5+10;
int a[N*2],s[N*2]; //不要忘记开二倍数组
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//输入:
int n,q,b=0; //b是当前循环的数组的前一位
cin>>n>>q;
for(int i=1;i<=n;i++) cin>>a[i],a[i+n]=a[i]; //复制二倍
for(int i=1;i<=2*n;i++) s[i]=s[i-1]+a[i]; //前缀和
for(int i=1;i<=q;i++)
{
int op;
cin>>op;
if(op==1)
{
int c;
cin>>c;
b+=c;
b%=n; //左移n次等于没有左移
}
if(op==2)
{
int l,r;
cin>>l>>r;
cout<<s[b+r]-s[b+l-1]<<'\n'; //计算前缀和
}
}
return 0;
}
::::