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. MyBatis思维导图

    1.初识框架技术 2.搭建MyBatis环境 3.掌握MyBatis的核心API 4.掌握MyBatis的核心配置文件:主要用于配置数据库连接和MyBatis运行时所需的各种特性 5.掌握SQL映射文 ...

  2. AJAX请求中出现OPTIONS请求

    背景 有一个前后端分离的VUE项目来发送ajax请求, 查看Nginx日志或使用Chrome Dev Tools查看请求发送情况时, 会看到每次调后台API的请求之前, 都会发送一个OPTIONS请求 ...

  3. [T-ARA/超新星][TTL (Time To Love)]

    歌词来源:http://music.163.com/#/song?id=5403002 作曲 : 金道勋 [作曲 : 金道勋] 作词 : Rhymer/Joosuc/황성진 [作词 : Rhymer/ ...

  4. Daily Scrum (2015/10/22)

    今天我们发现了源代码并不能直接在PC上运行.通过学长我们了解到我们需要在服务器上链接上数据库才能正常运行,所以找了老师要了地址后进入了正常工作.由此我们的PM增添了一些新的任务,团队的总工作时间有所增 ...

  5. Daily Scrumming* 2015.10.26(Day 7)

    一.总体情况总结 今天我们开会具体讨论了一下接下来的任务.还详细讨论了一下分数的分配,具体分数分配我们会在下一篇博客中详细说明. 我们下一周大致的工作安排如下: 1.UI:完成社团后台界面的设计,以及 ...

  6. Sprint会议2

    昨天:准备查找安卓APP开发的有关资料,安装有关软件 今天:自己制作一个安卓小程序,熟悉一下操作 遇到问题:安装遇到问题,环境配置出现问题

  7. Scapy 网段中ping扫描

    安装scapy pip3 install scapy-python3 交互式ip包构造 #scapy >>> ping = sr(IP(dst='202.100.1.1')/ICMP ...

  8. Java 反射 不定参数bug

    遇到的第一个关于反射的bug:java.lang.IllegalArgumentException: wrong number of arguments的问题解析如下: 1.错误bug wrong n ...

  9. java项目 相对路径(本项目的地址)

    File file=new File(""); String abspath=file.getAbsolutePath(); System.out.println(abspath) ...

  10. HDU 4405 Aeroplane chess 期望dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...