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 ...
随机推荐
- go vendor 安装失败的原因分析
安装之前的配置 export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin 1 2 安装 通常,我们查到的安装方法一般是下面这种 go get -u gi ...
- XSS(Cross Site Script)
类型一:反射型XSS 简单地把用户输入的数据“反射”给浏览器.也就是说,黑客需要诱使用户“点击”一个恶意链接,才能攻击成功. 类型二:存储型XSS 把用户输入的数据“存储”在服务器端.这种XSS具有很 ...
- QT中的小细节
一 . QT4和QT5的区别(信号和槽):1. QT4: connect(button,SIGNAL(pressed()),this,SLOT(close())); /** * 优点 :写法简单 ...
- 图片人脸检测(OpenCV版)
图片人脸检测 人脸检测使用到的技术是OpenCV,上一节已经介绍了OpenCV的环境安装,点击查看. 功能展示 识别一种图上的所有人的脸,并且标出人脸的位置,画出人眼以及嘴的位置,展示效果图如下: 多 ...
- kerkee demo编译连接过程中遇到的问题及解决方法(iOS)
https://github.com/kercer/kerkee_ios 1.刚打开这个demo的时候是下图这个样子的,我们很自然的可以想到将kerkee.xcoderproj添加到项目里面 2.将k ...
- 必应词典手机版(IOS版)与有道词典(IOS版)之软件分析【功能篇】【用户体验篇】
1.序言: 随着手机功能的不断更新和推广,手机应用市场的竞争变得愈发激烈.这次我们选择必应词典和有道词典的苹果客户端作对比,进一步分析这两款词典的客户端在功能和用户体验方面的利弊.这次测评的主要评测人 ...
- vue.js常用指令
本文摘自:http://www.cnblogs.com/rik28/p/6024425.html Vue.js的常用指令 上面用到的v-model是Vue.js常用的一个指令,那么指令是什么呢? Vu ...
- 软工之404 Note Found队选题报告
目录 NABCD分析引用 N(Need,需求): A(Approach,做法): B(Benefit,好处): C(Competitors,竞争): D(Delivery,交付): 初期 中期 个人贡 ...
- Struts hibernate Spring 框架原理
转自:http://www.cnblogs.com/javaNewegg/archive/2011/08/28/2156521.html 原理:1.通过Configuration().configur ...
- [转帖]HTTPS的简单说明
HTTPS(全称:Hyper Text Transfer Protocol over SecureSocket Layer),是以安全为目标的 HTTP 通道,简单讲是 HTTP 的安全版,即 HTT ...