题目链接: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. 【Mac】nsurlsessiond 后台下载问题的解决方法

    最近在使用 Mac 系统的时候,经常发现 nsurlsessiond 这个进程,一直在后台下载,非常占用网速.解决方案如下: 通过终端执行下面的语句可以停止后台的自动更新: #!/bin/sh lau ...

  2. Spring的依赖注入和管理Bean

    采用Spring管理Bean和依赖注入 1.实例化spring容器 和 从容器获取Bean对象 实例化Spring容器常用的两种方式: 方法一: 在类路径下寻找配置文件来实例化容器 [推荐使用] Ap ...

  3. Socket编程:UDP和TCP概论及案例

    网络编程的三要素: 1.IP地址  2.端口 3.协议 什么是Socket? Socket就是通信链路的端点称"套接词". 基于TCP协议的Socket网络通信: 用来实现双向安全 ...

  4. 自定义itemCheckView

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

  5. 【Java例题】6.1 进制转换

    1.进制转换.输入一个某种进制的整数,将其转换为其它进制的整数.说明:仅考虑十.二.八和十六进制. package chapter6; import java.util.*; public class ...

  6. vscode中配置git

    vscode中配置git vscode 报错 未找到Git.请安装Git,或在"git.path" 设置中配置 第一步安装git git安装方法自行解决,提供git下载连接! gi ...

  7. java后端开发面经 数据库相关

    小姐姐:怎么理解感情中的付出和回报? 你答:有这样一个故事,讲的是一个小男孩和一个小女孩,这个小男孩呢,用很多好玩石头,而这个小女孩呢,有好多好吃的糖果,有一天,他们相互约定:小男孩用所有的石头交互小 ...

  8. 配置Oracle透明网关用以连接 SQLServer经验总结

    一.情景介绍   业务中设计两个不同的系统,系统1和系统2,两个系统分别使用的是Oracle和SQLServer数据库.现需要在系统1的数据库中直接查询系统2数据库的数据.即在Oracle中执行SQL ...

  9. 【记忆化搜索】掷骰子 hpuoj

    B. 掷骰子 单点时限: 2.0 sec 内存限制: 512 MB 骰子,中国传统民间娱乐用来投掷的博具,早在战国时期就已经被发明. 现在给你 n 个骰子,求 n 个骰子掷出点数之和为 a 的概率是多 ...

  10. Elasticsearch 7.x 最详细安装及配置

    Elasticsearch 7.x 最详细安装及配置 一.Elasticsearch 7.x 小马哥说过,学习技术栈得看版本,那么 Elasticsearch 7.x 有什么好的特性呢? ES 7.0 ...