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 ...
随机推荐
- webpack开发和生产两个环境的配置详解
一开始在接触webpack 的时候,简直痛不欲生,现在回头看,做个注释,当然参考了很多文章.这是一个关于vue 开发的webpack 架构会列举出来webpack 系列教程Webpack——令人困惑的 ...
- [mysql] 归档工具pt-archiver,binlog格式由mixed变成row
pt-archiver官方地址:https://www.percona.com/doc/percona-toolkit/3.0/pt-archiver.html 介绍:归档数据,比如将一年前的数据备份 ...
- Scrum Meeting 报告
Scrum Meeting 报告 ----团队项目所需时间估计以及任务分配 由于能力有限,我们还不能构架好一个大框架.但是初步可以完成任务的流程和分配.任务所需要的具体实现可以参看<学霸系统的N ...
- java第三次实验报告
北京电子科技学院(BESTI) 实验报告 课程: Java程序设计 班级: 1352 姓名: 池彬宁 学号: 20135212 成绩: 指导教师: 娄嘉鹏 实验日期: 2015.6.3 实验密级: 无 ...
- 20172319 《Java程序设计教程》 第10周学习总结
20172319 2018.05.09-05.21 <Java程序设计教程>第10周学习总结 目录 教材学习内容总结 教材学习中的问题和解决过程 代码调试中的问题和解决过程 代码托管 上周 ...
- Leetcode题库——16.最接近的三数之和
@author: ZZQ @software: PyCharm @file: threeSumClosest.py @time: 2018/10/14 20:28 说明:最接近的三数之和. 给定一个包 ...
- 第一个spring冲刺总结
讨论成员:罗凯旋.罗林杰.吴伟锋.黎文衷 第一阶段总体是做到了运算的功能,只是一些基本的功能实现,包括APP进入动画,以及界面的基本效果设计,还有核心算法已经实现(可以计算括号 乘除法等等)“: 燃尽 ...
- angularJS1笔记-(2)-$watch方法监听变量的变化
html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- HDU 2123 An easy problem
http://acm.hdu.edu.cn/showproblem.php?pid=2123 Problem Description In this problem you need to make ...
- pycharm安装jpype报错及解决方法
安装jpype时发生报错: 按照提示去装了Microsoft visual C++,结果重新安装还是报错,根据https://blog.csdn.net/qq_38934189/article/det ...