http://codeforces.com/contest/862/problem/E

二分答案

一个数与数组中的哪个数最接近:

先对数组中的数排序,然后lower_bound

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <time.h>
  6. #include <string>
  7. #include <set>
  8. #include <map>
  9. #include <list>
  10. #include <stack>
  11. #include <queue>
  12. #include <vector>
  13. #include <bitset>
  14. #include <ext/rope>
  15. #include <algorithm>
  16. #include <iostream>
  17. using namespace std;
  18. #define ll long long
  19. #define minv 1e-6
  20. #define inf 1e18
  21. #define pi 3.1415926536
  22. #define E 2.7182818284
  23. const ll mod=1e9+;//
  24. const int maxn=1e5+;
  25.  
  26. ll b[maxn],f[maxn];
  27.  
  28. int main()
  29. {
  30. int n,m,q,g=,i,l,r;
  31. ll a,tot=,sum=,v;
  32. scanf("%d%d%d",&n,&m,&q);
  33. for (i=;i<=n;i++)
  34. {
  35. scanf("%lld",&a);
  36. if (i & )
  37. sum+=a;
  38. else
  39. sum-=a;
  40. }
  41. for (i=;i<=m;i++)
  42. {
  43. scanf("%lld",&b[i]);
  44. if (i & )
  45. tot+=b[i];
  46. else
  47. tot-=b[i];
  48. if (i>=n)
  49. {
  50. g++;
  51. if ((i-n) & )
  52. f[g]=-tot;
  53. else
  54. f[g]=tot;
  55. if ((i-n+) & )
  56. tot-=b[i-n+];
  57. else
  58. tot+=b[i-n+];
  59. }
  60. }
  61. sort(f+,f+g+);
  62.  
  63. i=lower_bound(f+,f+g+,sum)-f;
  64. v=inf;
  65. if (i->= && i-<=g)
  66. v=min(v,abs(sum-f[i-]));
  67. if (i>= && i<=g)
  68. v=min(v,abs(sum-f[i]));
  69. if (i+>= && i+<=g)
  70. v=min(v,abs(sum-f[i+]));
  71. printf("%lld\n",v);
  72.  
  73. while (q--)
  74. {
  75. scanf("%d%d%lld",&l,&r,&a);
  76. if ((r-l)%==)
  77. {
  78. if (l & )
  79. sum+=a;
  80. else
  81. sum-=a;
  82. }
  83.  
  84. i=lower_bound(f+,f+g+,sum)-f;
  85. v=inf;
  86. if (i->= && i-<=g)
  87. v=min(v,abs(sum-f[i-]));
  88. if (i>= && i<=g)
  89. v=min(v,abs(sum-f[i]));
  90. if (i+>= && i+<=g)
  91. v=min(v,abs(sum-f[i+]));
  92. printf("%lld\n",v);
  93. }
  94. return ;
  95. }

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. go vendor 安装失败的原因分析

    安装之前的配置 export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin 1 2 安装 通常,我们查到的安装方法一般是下面这种 go get -u gi ...

  2. XSS(Cross Site Script)

    类型一:反射型XSS 简单地把用户输入的数据“反射”给浏览器.也就是说,黑客需要诱使用户“点击”一个恶意链接,才能攻击成功. 类型二:存储型XSS 把用户输入的数据“存储”在服务器端.这种XSS具有很 ...

  3. QT中的小细节

    一 .  QT4和QT5的区别(信号和槽):1.  QT4: connect(button,SIGNAL(pressed()),this,SLOT(close())); /** * 优点 :写法简单 ...

  4. 图片人脸检测(OpenCV版)

    图片人脸检测 人脸检测使用到的技术是OpenCV,上一节已经介绍了OpenCV的环境安装,点击查看. 功能展示 识别一种图上的所有人的脸,并且标出人脸的位置,画出人眼以及嘴的位置,展示效果图如下: 多 ...

  5. kerkee demo编译连接过程中遇到的问题及解决方法(iOS)

    https://github.com/kercer/kerkee_ios 1.刚打开这个demo的时候是下图这个样子的,我们很自然的可以想到将kerkee.xcoderproj添加到项目里面 2.将k ...

  6. 必应词典手机版(IOS版)与有道词典(IOS版)之软件分析【功能篇】【用户体验篇】

    1.序言: 随着手机功能的不断更新和推广,手机应用市场的竞争变得愈发激烈.这次我们选择必应词典和有道词典的苹果客户端作对比,进一步分析这两款词典的客户端在功能和用户体验方面的利弊.这次测评的主要评测人 ...

  7. vue.js常用指令

    本文摘自:http://www.cnblogs.com/rik28/p/6024425.html Vue.js的常用指令 上面用到的v-model是Vue.js常用的一个指令,那么指令是什么呢? Vu ...

  8. 软工之404 Note Found队选题报告

    目录 NABCD分析引用 N(Need,需求): A(Approach,做法): B(Benefit,好处): C(Competitors,竞争): D(Delivery,交付): 初期 中期 个人贡 ...

  9. Struts hibernate Spring 框架原理

    转自:http://www.cnblogs.com/javaNewegg/archive/2011/08/28/2156521.html 原理:1.通过Configuration().configur ...

  10. [转帖]HTTPS的简单说明

    HTTPS(全称:Hyper Text Transfer Protocol over SecureSocket Layer),是以安全为目标的 HTTP 通道,简单讲是 HTTP 的安全版,即 HTT ...