Codeforces862 E. Mahmoud and Ehab and the function
来源:互联网 发布:循环更新数据库 编辑:程序博客网 时间:2024/06/03 02:02
传送门
显然
对每次更新
而
#include<stdio.h>#include<bits/stdc++.h>#define ll long long#define pii pair<int,int>#define pll pair<ll,ll>#define MEM(a,x) memset(a,x,sizeof(a))#define lowbit(x) ((x)&-(x))using namespace std;const int INF = 1e9+7;const int inf=INF;const int N = 1e5+50;ll sumA;int b[N];ll sumB[N];void getSumB(int m,int n){ sumB[0]=0; for(int i=1,flag=-1;i<=m;++i,flag*=-1){ scanf("%d",&b[i]); if(i<=n){ sumB[0]+=b[i]*flag; } } for(int i=1;n+i<=m;++i){ sumB[i]=-(sumB[i-1]+b[i])+b[n+i]*((n&1)?-1:1); }}void getSumA(int n){ sumA=0; for(int i=1,flag=1;i<=n;++i,flag*=-1){ int x; scanf("%d",&x); sumA+=flag*x; }}void add(int l,int r,int x){ if((r-l)%2==0){ if(l%2==1){ sumA+=x; } else{ sumA-=x; } }}ll __abs(ll x){ return x>0?x:-x;}ll query(int l,int r,int x,int bSz){ add(l,r,x); ll*it=lower_bound(sumB,sumB+bSz,-sumA); ll ans=1e18+5; if(it!=sumB+bSz){ ans=min(ans,__abs(sumA+*it)); } if(it!=sumB){ --it; ans=min(ans,__abs(sumA+*it)); } //add(l,r,-x); return ans;}int main(){ //freopen("/home/lu/code/r.txt","r",stdin); //freopen("/home/lu/code/w.txt","w",stdout); int n,m,q; while(~scanf("%d%d%d",&n,&m,&q)){ getSumA(n); getSumB(m,n); int bSz=m-n+1; sort(sumB,sumB+bSz); printf("%lld\n",query(1,1,0,bSz)); while(q--){ int l,r,x; scanf("%d%d%d",&l,&r,&x); printf("%lld\n",query(l,r,x,bSz)); } } return 0;}
阅读全文
0 0
- Codeforces862 E. Mahmoud and Ehab and the function
- Codeforces Round #435 (Div. 2) E. Mahmoud and Ehab and the function
- Codeforces Round #435 (Div. 2) E. Mahmoud and Ehab and the function
- codeforces 862E Mahmoud and Ehab and the function 二分+思维
- Mahmoud and Ehab and the xor CodeForces
- Mahmoud and Ehab and the bipartiteness CodeForces
- Mahmoud and Ehab and the xor CodeForces
- Mahmoud and Ehab and the MEX
- A. Mahmoud and Ehab and the MEX
- codeforces Mahmoud and Ehab and the bipartiteness
- Codeforces --- Mahmoud and Ehab and the MEX
- Codeforces Round #435 A. Mahmoud and Ehab and the MEX
- CF C. Mahmoud and Ehab and the xor
- CF 862C Mahmoud and Ehab and the xor 构造
- Codeforces Round #435 A. Mahmoud and Ehab and the MEX
- codeforces 862A Mahmoud and Ehab and the MEX
- Codeforces 862C. Mahmoud and Ehab and the xor
- codeforces 862B B. Mahmoud and Ehab and the bipartiteness
- 75. Sort Colors
- java web 项目中可能出现乱码的原因
- 利用Java输出九九乘法表(从四个方向排列)
- C语言的const和指针
- D_D系统构建-篇外话
- Codeforces862 E. Mahmoud and Ehab and the function
- translate和ktranslate用法详解
- Hbuilder增加vuejs、angularjs代码提示
- eclipse的一些设置
- 带头结点循环链表
- bzoj1854 [Scoi2010]游戏 并查集/二分图最大匹配
- transtrn用法详解
- 基于cropper.js封装vue在线图片裁剪组件
- 反射机制