题目链接:http://codeforces.com/contest/862/problem/E

题解:水题显然利用前缀和考虑一下然后就是二分b的和与-ans_a最近的数(ans_a表示a的前缀和(奇加偶减))

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int M = 1e5 + ;
ll a[M] , b[M] , sum[M] , ans_b[M];
int main() {
int n , m , q;
scanf("%d%d%d" , &n , &m , &q);
for(int i = ; i <= n ; i++) scanf("%lld" , &a[i]);
for(int i = ; i <= m ; i++) scanf("%lld" , &b[i]);
sum[] = ;
for(int i = ; i <= m ; i++) {
if(i % ) {
sum[i] = sum[i - ] + b[i];
}
else {
sum[i] = sum[i - ] - b[i];
}
}
for(int i = ; i <= m - n + ; i++) {
if(!(i % )) {
ans_b[i - ] = sum[i + n - ] - sum[i - ];
}
else {
ans_b[i - ] = sum[i - ] - sum[i + n - ];
}
}
sort(ans_b , ans_b + m - n + );
ll ans_a = ;
for(int i = ; i <= n ; i++) {
if(i % ) {
ans_a += a[i];
}
else {
ans_a -= a[i];
}
}
int pos = ;
pos = lower_bound(ans_b , ans_b + m - n + , -ans_a) - ans_b;
pos = min(m - n , pos);
printf("%lld\n" , min(abs(ans_a + ans_b[max( , pos - )]) , min(abs(ans_a + ans_b[pos]) , abs(ans_a + ans_b[min(m - n , pos + )]))));
while(q--) {
int l , r;
ll x;
scanf("%d%d%lld" , &l , &r , &x);
if(l % ) {
if((r - l + ) % ) {
ans_a += x;
}
}
else {
if((r - l + ) % ) {
ans_a -= x;
}
}
pos = lower_bound(ans_b , ans_b + m - n + , -ans_a) - ans_b;
pos = min(m - n , pos);
printf("%lld\n" , min(abs(ans_a + ans_b[max( , pos - )]) , min(abs(ans_a + ans_b[pos]) , abs(ans_a + ans_b[min(m - n , pos + )]))));
}
return ;
}

codeforces E. Mahmoud and Ehab and the function(二分+思维)的更多相关文章

  1. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  2. Codeforces 862A Mahmoud and Ehab and the MEX

    传送门:CF-862A A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 ...

  3. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

  4. Codeforces 862B - Mahmoud and Ehab and the bipartiteness

    862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc+ ...

  5. Codeforces 862C - Mahmoud and Ehab and the xor

    862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...

  6. Codeforces 862D. Mahmoud and Ehab and the binary string (二分)

    题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...

  7. E. Mahmoud and Ehab and the function Codeforces Round #435 (Div. 2)

    http://codeforces.com/contest/862/problem/E 二分答案 一个数与数组中的哪个数最接近: 先对数组中的数排序,然后lower_bound #include &l ...

  8. codeforces D. Mahmoud and Ehab and the binary string(二分)

    题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...

  9. [Codeforces]862F - Mahmoud and Ehab and the final stage

    题目大意:n个字符串,支持修改一个位置上的字符串和查询一个区间的子区间中长度乘LCP的最大值,输入字符数和询问数不超过10^5. 做法:求出相邻的LCP长度,区间LCP等于区间最小值,查询分几种情况考 ...

随机推荐

  1. 初次见面C#排坑记录

    排一次开发C#遇到的坑,同时说一下自己对C#中文件夹构建方式的体会. 一个开发Java的人留下了痛苦的泪水,变量命名规则不一样,连括号打的都不一样,

  2. golang-http 请求---设置header与直接发

    背景 现在各种软件到处都是,写代码难免有时候需要http 调用其他的接口. 其实这个东西还挺常用,虽然很简单,但是写的时候 又忘,就像是提笔忘字,索性总结一下吧. 不需要设置header属性的http ...

  3. Dubbo里面线程池的拒绝策略

    Dubbo里面线程池的拒绝策略 public class AbortPolicyWithReport extends ThreadPoolExecutor.AbortPolicy { protecte ...

  4. CentOS 7.3下使用YUM 安装MySQL5.6

    1.检查Linux系统中是否已安装 MySQL rpm -qa | grep mysql 返回空值的话,就说明没有安装 MySQL 注意:在新版本的CentOS7中,默认的数据库已更新为了Mariad ...

  5. Java性能调优的11个实用技巧

    译文出处: ITeye    原文出处:dzone 大多数开发人员认为性能优化是个比较复杂的问题,需要大量的经验和知识.是的,这并不没有错.诚然,优化应用程序以获得最好的性能并不是一件容易的事情,但这 ...

  6. Java线程池的增长过程

    通过ThreadPoolExecutor的方式创建线程池 ThreadPoolExecutor 构造方法: public ThreadPoolExecutor(int corePoolSize, in ...

  7. 自定义 Button 选择器

    极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...

  8. 洛谷P3572题解

    这道题实在是一道 毒瘤 题,太坑爹了.那个写 \(deque\) 的题解亲测只有80分,原因 不言而明 ,这道题居然 丧心病狂 到 卡STL . 好了,不吐槽了,进入正题 题目分析: 这是一道十分 简 ...

  9. jdk安装及环境配置

    1.下载对应的安装包(我们公司用的是jdk 1.8) 2.选择对应版本,点击安装,在选择安装位置的时候,选择自己对应存放的位置,其他都点击下一步就行了,先安装jdk,后安装jre 3.环境变量,选择 ...

  10. [科研民工笔记1]安装Ubuntu到U盘

    主要是台式机只有一块固态,暂时没有加固态的打算,所以就买了一个64g的闪迪cz73,装了Ubuntu.以后可能考虑加一块硬盘. 前期准备:VMware.官网下载安装包(这里以16.04为例) 第一部分 ...