一开始有很多答案
f0,f1,f2,f3,f4…,fm - n这个我们预处理出来这里是没有绝对值的
每次修改l,r 其实只修改了a的总和
假设修改了总值v
那么要求的最小的原式 = abs(v+fj)
记录一下改变的总和然后二分一下找最接近的fj
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define pb push_back
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define lans() printf("%lld",ans)
#define lanss() printf("%lld ",ans)
#define lansn() printf("%lld\n",ans)
#define fansn() printf("%.10f\n",ans)
#define r0(i,n) for(int i=0;i<(n);++i)
#define r1(i,e) for(int i=1;i<=e;++i)
#define rn(i,e) for(int i=e;i>=1;--i)
#define rsz(i,v) for(int i=0;i<(int)v.size();++i)
#define szz(x) ((int)x.size())
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define lowbit(a) (a&(-a))
#define all(a) a.begin(),a.end()
#define pii pair
#define pli pair
#define mp make_pair
#define lrt rt<<1
#define rrt rt<<1|1
#define X first
#define Y second
#define PI (acos(-1.0))
#define sqr(a) ((a)*(a))
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1000000000+7;
const double eps=1e-9;
const int inf=0x3f3f3f3f;
const ll infl = 10000000000000000;
const int maxn= 200000+10;
const int maxm = 1000+10;
//Pretests passed
int in(int &ret)
{
char c;
int sgn ;
if(c=getchar(),c==EOF)return -1;
while(c!='-'&&(c<'0'||c>'9'))c=getchar();
sgn = (c=='-')?-1:1;
ret = (c=='-')?0:(c-'0');
while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0');
ret *=sgn;
return 1;
}
int a[maxn];
int b[maxn];
int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif // LOCAL
int n,m,q
; sddd(n,m,q);
r1(i,n)in(a[i]);
r1(i,m)in(b[i]);
ll x = 0, y = 0;
int op = 1;
r1(i,n)x+=op*a[i],op=-op;
vectorv;
op = -1;
int idx = n&1?1:0;
ll del = 0;
int op2 = -1;
for(int i = 1;i<=m;++i)
{
if(i>n)
{
del+=op2*b[i-n];
op2 = -op2;
}
y+=op*b[i],op = -op;
if(i>=n)
{
ll tmp = y - del;
if((i-n+1)%2==0)tmp = -tmp;
v.pb(tmp+x);
}
}
ll tot = 0;
sort(all(v));
int sz = v.size();
r0(i,q+1)
{
ll l= 0 ,r=0,z=0;
if(i)slddd(l,r,z);
if((r-l+1)&1)
{
if(l&1)tot+=z;
else tot-=z;
}
int pos = lower_bound(all(v),-tot)-v.begin();
if(pos==sz)pos = sz-1;
ll ans = abs(v[pos]+tot);
if(pos)ans = min(ans,abs(v[pos-1]+tot));
lansn();
}
return 0;
}