E. Mahmoud and Ehab and the function Codeforces Round #435 (Div. 2)
http://codeforces.com/contest/862/problem/E
二分答案
一个数与数组中的哪个数最接近:
先对数组中的数排序,然后lower_bound
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <string>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <ext/rope>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e18
#define pi 3.1415926536
#define E 2.7182818284
const ll mod=1e9+;//
const int maxn=1e5+; ll b[maxn],f[maxn]; int main()
{
int n,m,q,g=,i,l,r;
ll a,tot=,sum=,v;
scanf("%d%d%d",&n,&m,&q);
for (i=;i<=n;i++)
{
scanf("%lld",&a);
if (i & )
sum+=a;
else
sum-=a;
}
for (i=;i<=m;i++)
{
scanf("%lld",&b[i]);
if (i & )
tot+=b[i];
else
tot-=b[i];
if (i>=n)
{
g++;
if ((i-n) & )
f[g]=-tot;
else
f[g]=tot;
if ((i-n+) & )
tot-=b[i-n+];
else
tot+=b[i-n+];
}
}
sort(f+,f+g+); i=lower_bound(f+,f+g+,sum)-f;
v=inf;
if (i->= && i-<=g)
v=min(v,abs(sum-f[i-]));
if (i>= && i<=g)
v=min(v,abs(sum-f[i]));
if (i+>= && i+<=g)
v=min(v,abs(sum-f[i+]));
printf("%lld\n",v); while (q--)
{
scanf("%d%d%lld",&l,&r,&a);
if ((r-l)%==)
{
if (l & )
sum+=a;
else
sum-=a;
} i=lower_bound(f+,f+g+,sum)-f;
v=inf;
if (i->= && i-<=g)
v=min(v,abs(sum-f[i-]));
if (i>= && i<=g)
v=min(v,abs(sum-f[i]));
if (i+>= && i+<=g)
v=min(v,abs(sum-f[i+]));
printf("%lld\n",v);
}
return ;
}
E. Mahmoud and Ehab and the function Codeforces Round #435 (Div. 2)的更多相关文章
- Codeforces Round #435 (Div. 2)【A、B、C、D】
//在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...
- CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)
/* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #includ ...
- 【Codeforces Round #435 (Div. 2) A B C D】
CF比赛题目地址:http://codeforces.com/contest/862 A. Mahmoud and Ehab and the MEX ·英文题,述大意: 输入n,x(n,x& ...
- Codeforces Round #435 (Div. 2)
A. Mahmoud and Ehab and the MEX 题目链接:http://codeforces.com/contest/862/problem/A 题目意思:现在一个数列中有n个数,每个 ...
- Codeforces Round #435 (Div. 2) B (二分图) C(构造)
B. Mahmoud and Ehab and the bipartiteness time limit per test 2 seconds memory limit per test 256 me ...
- D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)
http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio ...
- 【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string
题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置 ...
- 【构造】【分类讨论】Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor
题意:给你n,x,均不超过10^5,让你构造一个无重复元素的n个元素的非负整数集合(每个元素不超过10^6),使得它们的Xor和恰好为x. 如果x不为0: 随便在x里面找一个非零位,然后固定该位为0, ...
- 【Codeforces Round #435 (Div. 2) A】Mahmoud and Ehab and the MEX
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 让x没有出现,以及0..x-1都出现就可以了. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/std ...
随机推荐
- TensorFlow --- 01初识
由于博客园对Markdown支持不够友好,阅读此文请前往云栖社区:TensorFlow --- 01初识
- 君学,佳一tvodp文件破解
tvodp文件破解的意思就是,越过加密部分直接提取内部原始文件,难度较大,方法用U盘刻老毛桃pe,然后电脑启动pe,在pe中打开文件,做提取工作, 本人淘宝破解:https://item.taobao ...
- Python 命令行解析工具 Argparse介绍
最近在研究pathon的命令行解析工具,argparse,它是Python标准库中推荐使用的编写命令行程序的工具. 以前老是做UI程序,今天试了下命令行程序,感觉相当好,不用再花大把时间去研究界面问题 ...
- url的param与dict转换
urllib.parse.urlencode urlencode from urllib import parse from urllib.request import urlopen from ur ...
- 课堂实践ASL博客
实践博客 二分法查找元素 1.首先定义三个位置min,mid,max 2.每次从所有元素所处位置的中间开始查找(所有元素必须以由小及大顺序排列完毕) 3.当中间元素大于所查找元素时,从中间元素(mid ...
- 20172325 2016-2017-2 《Java程序设计》第四周学习总结
20172325 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 1.对类.对象.声明变量的定义和属性有了进一步的了解 2.学会如何编写一个类并运用到需要的程 ...
- raise PDFEncryptionError('Unknown algorithm: param=%r' % param) pdfminer.pdfdocument.PDFEncryptionError: Unknown algorithm
使用pdfminer遇到的pdf文件加密问题: raise PDFEncryptionError('Unknown algorithm: param=%r' % param) pdfminer.pdf ...
- .NET WinForm下StatusStrip控件如何设置分隔线及部分子控件右对齐
ssInfo.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;//StatusStrip 控件 tsslUpdate.Alignment = ...
- Java基本程序设计结构
一.要求: 1.设平面上有一个m×n 的网格,将左下角的网格点标记为(0,0)而右上角的网格点标记为(m,n).某人想从(0,0)出发沿网格线行进到达(m,n),但是在网格点(i,j)处他只能向上行进 ...
- 第九周(11.11-11.17)----Beta版本视频发布
beta阶段视频发布地址: http://v.youku.com/v_show/id_XMTgxNjE2NzY3Mg==.html