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 ...
随机推荐
- Bootstrap学习--基本格式
以下为Bootstrap的基本格式代码 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta ...
- 笨办法学Python - 习题1: A Good First Program
在windows上安装完Python环境后,开始按照<笨办法学Python>书上介绍的章节进行练习. 习题 1: 第一个程序 第一天主要是介绍了Python中输出函数print的使用方法, ...
- python os.walk详解
os模块大全详情 os.walkos.walk方法,主要用来遍历一个目录内各个子目录和子文件. os.walk(top, topdown=True, onerror=None, followlinks ...
- python常用模块目录
博客目录总纲首页 python其他知识目录 random hashlib os sys json __name__ shutil xlrd xlwt xlutils 核心模块:os s ...
- mybatis批量插入oracle
<insert id="batchInsert" parameterType="java.util.List"> INSERT INTO TEST( ...
- No.110_第三次团队会议
前端的易帜 前端在整个软件中有着举足轻重的地位.前端设计一般可以理解为视觉设计,前端开发则是前台代码的实现. 随着科技水平的提高和生产力的提高,人民对于审美的要求逐渐增高.在没有科技壁垒的情况下,是否 ...
- Task 6.2冲刺会议七 /2015-5-20
今天把主界面改善了一下,主要功能时摄像头的使用以及语音聊天的部分,两个部分的设计原理基本相同,但是可是好几个模块让有点不知道该怎么下手.这时候我感觉到了模块拼接是很困难的,只有十分清楚每个模块才能很好 ...
- ubuntu16.04+opencv3.0.0
基本步骤: http://blog.csdn.net/xuezhisdc/article/details/48691797 报错: http://www.jianshu.com/p/68ac83436 ...
- arcgis 10.3中文版安装教程、配置及常见问题(百度的有些错误)
参考的: 1.http://wenku.baidu.com/link?url=W-wo_lEMvzHxF19w91X7H0WDjyCQ16DjGu4ViaZ4-eVPr0NTU-LrZTPK1oyzT ...
- 团队作业7——第二次项目冲刺(Beta版本12.04——12.07)
1.当天站立式会议照片 本次会议在5号公寓3楼召开,本次会议内容:①:熟悉每个人想做的模块.②:根据项目要求还没做的完成. 2.每个人的工作 经过会议讨论后确定了每个人的分工 组员 任务 陈福鹏 实现 ...