E. Mahmoud and Ehab and the function Codeforces Round #435 (Div. 2)
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+7;//998244353 24 const int maxn=1e5+10; 25 26 ll b[maxn],f[maxn]; 27 28 int main() 29 { 30 int n,m,q,g=0,i,l,r; 31 ll a,tot=0,sum=0,v; 32 scanf("%d%d%d",&n,&m,&q); 33 for (i=1;i<=n;i++) 34 { 35 scanf("%lld",&a); 36 if (i & 1) 37 sum+=a; 38 else 39 sum-=a; 40 } 41 for (i=1;i<=m;i++) 42 { 43 scanf("%lld",&b[i]); 44 if (i & 1) 45 tot+=b[i]; 46 else 47 tot-=b[i]; 48 if (i>=n) 49 { 50 g++; 51 if ((i-n) & 1) 52 f[g]=-tot; 53 else 54 f[g]=tot; 55 if ((i-n+1) & 1) 56 tot-=b[i-n+1]; 57 else 58 tot+=b[i-n+1]; 59 } 60 } 61 sort(f+1,f+g+1); 62 63 i=lower_bound(f+1,f+g+1,sum)-f; 64 v=inf; 65 if (i-1>=1 && i-1<=g) 66 v=min(v,abs(sum-f[i-1])); 67 if (i>=1 && i<=g) 68 v=min(v,abs(sum-f[i])); 69 if (i+1>=1 && i+1<=g) 70 v=min(v,abs(sum-f[i+1])); 71 printf("%lld\n",v); 72 73 while (q--) 74 { 75 scanf("%d%d%lld",&l,&r,&a); 76 if ((r-l)%2==0) 77 { 78 if (l & 1) 79 sum+=a; 80 else 81 sum-=a; 82 } 83 84 i=lower_bound(f+1,f+g+1,sum)-f; 85 v=inf; 86 if (i-1>=1 && i-1<=g) 87 v=min(v,abs(sum-f[i-1])); 88 if (i>=1 && i<=g) 89 v=min(v,abs(sum-f[i])); 90 if (i+1>=1 && i+1<=g) 91 v=min(v,abs(sum-f[i+1])); 92 printf("%lld\n",v); 93 } 94 return 0; 95 }
转载于:https://www.cnblogs.com/cmyg/p/9520945.html
E. Mahmoud and Ehab and the function Codeforces Round #435 (Div. 2)相关推荐
- D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)
http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 1 #include <cstd ...
- 寒假刷题13: Anu Has a Function Codeforces Round #618 (Div. 2) C
题目链接: Anu Has a Function 题目解析: 观察函数f(x,y)定义:(x|y)-y 即 取出来x里是1但是y里不是1的地方 也就是 x&(~y) (也可以列真值表) 因此题 ...
- Codeforces Round #628 (Div. 2) F. Ehab‘s Last Theorem dfs树
传送门 文章目录 题意: 思路: 题意: 给你个nnn个点mmm条边的图,可以选择完成以下两个任务中的一个: (1)(1)(1)找出大小恰好为n\sqrt nn的一个独立集. (2)(2)(2)找出 ...
- Codeforces Round #628 (Div. 2) E. Ehab‘s REAL Number Theory Problem 巧妙的质因子建图
传送门 文章目录 题意: 思路: 题意: 给你nnn个数,每个数的因子个数不超过777个,选出最少的数使其乘积为平方数. n≤1e5n\le 1e5n≤1e5 思路: 由于因子不超过777个,所以由约 ...
- Codeforces Round #618 (Div. 1)-----A. Anu Has a Function
提示: Codeforces Round #618 (Div. 1)-----A. Anu Has a Function 题意: 定义一个函数f(x , y) = f(x | y) - y 给定一个长 ...
- Codeforces Round #563 (Div. 2)/CF1174
Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...
- Codeforces Round #729 (Div. 2)
Codeforces Round #729 (Div. 2) 题号 题目 知识点 A Odd Set B Plus and Multiply C Strange Function D Priority ...
- Codeforces Round #717 (Div. 2)
Codeforces Round #717 (Div. 2) CodeForces 1516 题号 题目 知识点 A Tit for Tat 贪心 B AGAGA XOOORRR 思维题 C Baby ...
- Codeforces Round #716 (Div. 2)
Codeforces Round #716 (Div. 2) CodeForces 1514 题号 题目 知识点 难度 A Perfectly Imperfect Array B AND 0, Sum ...
最新文章
- linux 网络错误 TCP: too many orphaned sockets 解决方法
- JS一起学01:css复习、js基础知识、事件、参数、函数、网页换肤、if判断、className问题、浏览器执行顺序
- WINCE6.0+S3C2443的启动过程---eboot3
- Leetcode 58.最后一个单词的长度 (每日一题 20210705)
- SVM-支持向量机原理详解与实践之四
- python笔记视频_终于拿到!清华大佬Python视频+书+笔记汇总
- 后视摄像头_鸡肋还是“真香”?流媒体后视镜到底值不值冲?
- 火车头采集的数据库文件*.bd3是什么格式的数据库?
- 计算机更改开机密码快捷方法,win7怎么修改开机密码(最快) win7修改开机密码最便捷的方法...
- 工具类库系列(六)-TimeTool
- 高等数学知识点总结——导数定义及性质、微积分、泰勒展开、洛必达法则、函数单调性判断
- 计算标准差(c++)
- 清华物理系与计算机系哪个好,兰州大学现在还有物理系吗?
- 【Python】批量下载新浪微博某用户的头像相册
- 《扬帆优配》个人养老金投资最新成绩出炉 七成养老FOF跑输基准
- linux中强行执行root权限
- 【蓝桥杯 数独填数 DFS】
- 基于VHDL的层次化设计:异步清零和同步使能4位十六进制加法计数器和七段显示译码器的元件例化实现
- 删除的照片如何恢复?SD卡数据恢复妙招
- Matlab/Python nc格式小时数据转日期
热门文章
- 经典SQL[私家珍藏]
- 摘自缪雪峰的博客的JavaScript个人笔记(3)
- springboot配置文件application.properties参阅文章
- powershell自动化操作AD域、Exchange邮箱系列(9)—导出AD内所有计算机到数据库
- 搭建SVN服务器详细过程 及 使用方法 Windows端
- python进阶09并发之五生产者消费者
- Ubuntu 18.04/18.10快速开启Google BBR的方法
- 从数据仓库到大数据平台再到数据中台(内附13张架构图)
- 知乎高赞!python能做这么多自动化,可开发效率真的有Java高?
- c++如何输入数组_工作表数组计算之一:行列数相同的数组间运算