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)的更多相关文章

  1. Codeforces Round #435 (Div. 2)【A、B、C、D】

    //在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...

  2. CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)

    /* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #includ ...

  3. 【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& ...

  4. Codeforces Round #435 (Div. 2)

    A. Mahmoud and Ehab and the MEX 题目链接:http://codeforces.com/contest/862/problem/A 题目意思:现在一个数列中有n个数,每个 ...

  5. 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 ...

  6. D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)

    http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio ...

  7. 【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string

    题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置 ...

  8. 【构造】【分类讨论】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, ...

  9. 【Codeforces Round #435 (Div. 2) A】Mahmoud and Ehab and the MEX

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 让x没有出现,以及0..x-1都出现就可以了. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/std ...

随机推荐

  1. Hadoop错误码速查

    经常遇到的exception是:PipeMapRed.waitOutputThreads(): subprocess failed with code N "OS error code 1: ...

  2. VS code MacOS 环境搭建

    环境:MacBook Pro 参考博客 为了动手开发AI代码,我需要安装一个VS code. 开始我以为是安装visual studio呢.我装过visual studio2017. VS code是 ...

  3. fcn模型训练及测试

    1.模型下载 1)下载新版caffe: https://github.com/BVLC/caffe 2)下载fcn代码: https://github.com/shelhamer/fcn.berkel ...

  4. 利用python进行简单的图像处理:包括打开,显示以及保存图像

    利用python进行简单的图像处理:包括打开,显示以及保存图像 利用PIL处理 PIL(python image library) 是python用于图片处理的package.但目前这个package ...

  5. 第三章 深入Servlet技术

    3.1 配置Servlet <servlet-name>,<servlet-class>是必须配置的,以便于web容器知道浏览器具体访问的是哪个servlet. <ini ...

  6. Head First Java & final

  7. angularJS1笔记-(9)-自定义指令(restrict/template/replace)

    index.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  8. 1014 C语言文法定义与C程序的推导过程

    <程序> -> <外部声明> | <程序> <外部声明> <外部声明> -> <函数定义> | <声明> ...

  9. pxe前期接入H3C交换机网络准备

    环境:一个装机vlan3010,一个业务vlan,将接入交换机的下联,上联设置好vlan 如果服务器一直出于dhcp状态,有可能是交换机到服务器的光纤线路有问题,建议在交换机查看端口是否是down的. ...

  10. win32.gui.api.con(前置,鼠标点击,发送数据的Dome)

    # -*- coding: UTF-8 -*- import win32gui, win32con import os import time import win32gui import win32 ...