题目传送门

题意:现在有n个人,现在可以把这n个人分成若干组,只有连续的人才能被分为一组,并且一个组内最多2个人,现在问你 所有组内的最大值-最小值 这个差值最小是多少。

题解:

将每个人的情况3种情况都拿出来,把这些所有的情况从小到大排序,然后我们枚举起点,然后一直不停的添加线段,然后直到当前的区间内的所有线段,我们可以选择其中的一部分,使得这些线段能够不重合的前提下巧好覆盖1-n的区间内。

tree[x] 假设管理的区间为 [l, r]  tree[x][i][j] i代表的是左端点 j 代表的是右端点, 当i == 1 的时候,j == 1的时候,我们管理的是 [l+1,r+1]这个区间的状态 i == 0,j == 0 管理的是 [l, r]这个区间的状态。

所以我们pushup的时候不重合的搞就好了。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int a[N][];
pll p[N<<];
bool cmp(pll & x, pll & y){
return a[x.fi][x.se] < a[y.fi][y.se];
}
int tree[N<<][][];
void Build(int l, int r, int rt){
tree[rt][][] = tree[rt][][] = tree[rt][][] = tree[rt][][] = ;
if(l == r) {
tree[rt][][] = ;
return ;
}
int m = l+r >> ;
Build(lson); Build(rson);
}
void PushUp(int rt){
tree[rt][][] = (tree[rt<<][][] && tree[rt<<|][][]) || (tree[rt<<][][] && tree[rt<<|][][]);
tree[rt][][] = (tree[rt<<][][] && tree[rt<<|][][]) || (tree[rt<<][][] && tree[rt<<|][][]);
tree[rt][][] = (tree[rt<<][][] && tree[rt<<|][][]) || (tree[rt<<][][] && tree[rt<<|][][]);
tree[rt][][] = (tree[rt<<][][] && tree[rt<<|][][]) || (tree[rt<<][][] && tree[rt<<|][][]);
}
void Update(int L, int op,int l, int r, int rt){
if(l == r){
tree[rt][][op] ^= ;
return ;
}
int m = l+r >> ;
if(L <= m) Update(L, op, lson);
else Update(L, op, rson);
PushUp(rt);
}
int main(){
int T, n;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
int m = ;
for(int i = ; i <= n; ++i){
scanf("%d", &a[i][]);
p[++m] = pll(i,);
if(i-) {
a[i-][] = a[i-][] + a[i][];
p[++m] = pll(i-,);
}
}
sort(p+, p++m, cmp);
Build(,n,);
LL ans = INF;
for(int i = , j=; i <= m; ++i){
while(j <= m && !tree[][][]){
Update(p[j].fi, p[j].se, , n, );
j++;
}
if(tree[][][]) ans = min(ans, 1ll*a[p[j-].fi][p[j-].se] - a[p[i].fi][p[i].se]);
Update(p[i].fi, p[i].se, , n, );
}
printf("%lld\n", ans);
}
return ;
}

zoj 5823 Soldier Game 2018 青岛 I的更多相关文章

  1. 2018 青岛ICPC区域赛E ZOJ 4062 Plants vs. Zombie(二分答案)

    Plants vs. Zombies Time Limit: 2 Seconds      Memory Limit: 65536 KB BaoBao and DreamGrid are playin ...

  2. ACM-ICPC 2018 青岛赛区现场赛 K. Airdrop && ZOJ 4068 (暴力)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4068 题意:吃鸡游戏简化为二维平面上有 n 个人 (xi,yi) ...

  3. ACM-ICPC 2018 青岛赛区现场赛 D. Magic Multiplication && ZOJ 4061 (思维+构造)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4061 题意:定义一个长度为 n 的序列 a1,a2,..,an ...

  4. ACM ICPC 2018 青岛赛区 部分金牌题题解(K,L,I,G)

     目录: K Airdrop I Soldier Game L Sub-cycle Graph G Repair the Artwork ———————————————————— ps:楼主脑残有点严 ...

  5. ACM-ICPC 2018青岛网络赛-H题 Traveling on the Axis

    题目:略(不知道怎么从ZOJ搬题) 地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4054 把这题的每个点分成两种情况 ...

  6. ZOJ 4063 - Tournament - [递归][2018 ACM-ICPC Asia Qingdao Regional Problem F]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4063 Input Output Sample Input 2 3 ...

  7. ZOJ 4067 - Books - [贪心][2018 ACM-ICPC Asia Qingdao Regional Problem J]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4067 题意: 给出 $n$ 本书(编号 $1 \sim n$), ...

  8. 2018青岛网络赛G - Couleur 区间上的启发式合并

    题意:给出\(a[1...n]\),共\(n\)次操作,每次删除一个位置\(p_i\)(强制在线),此时区间会变为两个分离的区间,求每次操作的最大区间逆序对 首先要知道必要的工具,按权值建立的主席树可 ...

  9. ACM-ICPC 2018 青岛赛区网络预赛 J. Press the Button(数学)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4056 题意:有一个按钮,时间倒计器和计数器,在时间[0,t]内, ...

随机推荐

  1. 在Java大环境下.NET程序员如何夺得一线生机

    先来看一组数据,从某招聘网站直接检索3-4w的岗位,会看到Java与.NET社会需求量的巨大差异,这里就不再对比高薪的岗位了,.NET的高薪岗位更是少的可怜:   笔者从业十余年,一直是在.NET圈子 ...

  2. 2、JAVA相关基础的学习和工具

    个人感觉,各种语言的基础知识,例如标识符,运算符等在宏观上几乎是一样的,只是在某些方面上会有一点点差异,因为本人已经有了语言基础,所以对于标识符,关键字,运算符等方面的只是便不作赘述,敬请谅解,如果你 ...

  3. Java——类型信息

    1.Class对象 Class对象是一个特殊的对象,它包含了与类有关的信息.Class对象就是用来创建类的所有常规对象的. 类是程序的一部分,每个类都有一个Class对象,每当编写并且编译一个新类,就 ...

  4. java中File IO流的笔记

    1.File文件的属性和操作 boolean exists( )  判断文件或目录是否存在boolean isFile( )  判断是否是文件boolean isDirectory( ) 判断是否是目 ...

  5. AOSP 预置 APP

    Android 系统预置 APP 是做 Framework 应用开发经常经常会遇到的工作,预置 APP 分为两种,一种是直接预置 APK,一种是预置带有源码的 APP. 预置 apk 示例说明 以 . ...

  6. Spring入门(八):自动装配的歧义性

    1. 什么是自动装配的歧义性? 在Spring中,装配bean有以下3种方式: 自动装配 Java配置 xml配置 在这3种方式中,自动装配为我们带来了很大的便利,大大的降低了我们需要手动装配bean ...

  7. Mac 安装 homebrew 流程 以及 停在 Updating Homebrew等 常见错误解决方法

    懒人操作顺序:S_01>>>S_02>>>S_03 首先这是homebrew的官网 https://brew.sh/index_zh-cn 安装方法是在终端中输入 ...

  8. Go调度器介绍和容易忽视的问题

    本文记录了本人对Golang调度器的理解和跟踪调度器的方法,特别是一个容易忽略的goroutine执行顺序问题,看了很多篇Golang调度器的文章都没提到这个点,分享出来一起学习,欢迎交流指正. 什么 ...

  9. vscode 配置 nodejs 开发环境

    1.配置 cnpm 镜像 (国内淘宝镜像网速更快) npm install -g cnpm --registry=https://registry.npm.taobao.org 2.配置智能提示 安装 ...

  10. Go---go-cache包学习

    github.com/patrickmn/go-cachego-cache是一款类似于memached 的key/value 缓存软件.它比较适用于单机执行的应用程序.go-cache实质上就是拥有过 ...