题目链接: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. 让techempower帮你通讯服务框架的性能

    在编写服务应用框架的时候一般都需要进行性能测试,但自己测试毕竟资源受限所以很难做更高性能上的测试.其实GitHub上有一个项目可以让开发人员提交自己的框架服务代码然后进行一个标准测试:现在已经有上百个 ...

  2. 通过jmeter发送webservice接口请求

    1.webservice接口地址:http://ip:port/...?wsdl 2.接口数据类型:<cuxGmiChukuRmaTrxV><salesrepId xmlns:xsi ...

  3. Spring文档学习

    Spring文档学习 参考Spring Framework Documentation学习 1. IoC 容器 1.1 容器实例化 <beans> <import resource= ...

  4. Eclipse+CXF框架开发Web服务实战

    一. 说明 采用CXF框架开发webservice. 所用软件及版本如下.  操作系统:Window XP SP3.  JDK:JDK1.6.0_07,http://www.oracle.com/ ...

  5. 中间件增强框架之InterceptFramework

    本文讲解MOF中的InterceptFramework框架.该框架可以在应用启动过程中获取画像信息,实现应用画像数据采集和存储. 一.前言 在智能运维中,应用服务所使用的组件及JAR包等相关信息非常重 ...

  6. Gradle-日志

    日志就像是构建工具的 UI,如果输出太混乱,真正的警告和错误很容易就被忽略了.Gradle 定义了 6 种日志级别,以便于我们识别有用的信息. 日志级别 Gradle 的日志 和Android 一样也 ...

  7. 线程学习oneday

    进程:执行中的程序叫做进程(Process),是一个动态的概念. 线程:一个进程可以产生多个线程.同多个进程可以共享操作系统的某些资源一样,同一进程的多个线程也可以共享此进程的某些资源(比如:代码.数 ...

  8. shiro@RequiresPermission的设置

    public class MyShiroRealm extends AuthorizingRealm { //slf4j记录日志,可以不使用 private Logger logger = Logge ...

  9. 解决mysql乱码

    总结的几个乱码问题 希望我们全体学员也能够学会总结 java web 很是希望大家能够学好.并且也希望大家能够在学习过程中不段的积累相关的知识点 1.在response中写<meta  http ...

  10. Kafka的消息会丢失和重复吗?——如何实现Kafka精确传递一次语义

    我们都知道Kafka的吞吐量很大,但是Kafka究竟会不会丢失消息呢?又会不会重复消费消息呢? 图 无人机实时监控 ​ 有很多公司因为业务要求必须保证消息不丢失.不重复的到达,比如无人机实时监控系统, ...