[nowcoder5669E]Eliminate++

1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 1000005
4 #define L (k<<1)
5 #define R (L+1)
6 #define mid (l+r>>1)
7 struct sta{
8 int x,y;
9 };
10 struct ji{
11 int k;
12 sta a[2];
13 }o,o0,o1;
14 struct type{
15 ji p0,p1;
16 }f[N<<2];
17 int t,n,a[N],id[N],ans[N];
18 sta merge(sta x,sta y){
19 sta z;
20 z.x=x.x+max(y.x-x.y,0);
21 z.y=(y.y+max(x.y-y.x,0)-1)%2+1;
22 return z;
23 }
24 type merge(type x,type y){
25 type z;
26 z.p0.k=x.p0.k+y.p0.k;
27 z.p1.k=x.p1.k+y.p1.k;
28 z.p0.a[0]=merge(x.p0.a[0],y.p0.a[0]);
29 z.p0.a[1]=merge(y.p0.a[1],x.p0.a[1]);
30 z.p1.a[0]=merge(x.p1.a[0],y.p1.a[0]);
31 z.p1.a[1]=merge(y.p1.a[1],x.p1.a[1]);
32 return z;
33 }
34
35 void build(int k,int l,int r){
36 if (l==r){
37 f[k]=type{o0,o1};
38 return;
39 }
40 build(L,l,mid);
41 build(R,mid+1,r);
42 f[k]=merge(f[L],f[R]);
43 }
44 void update(int k,int l,int r,int x){
45 if (l==r){
46 f[k]=type{o1,o0};
47 return;
48 }
49 if (x<=mid)update(L,l,mid,x);
50 else update(R,mid+1,r,x);
51 f[k]=merge(f[L],f[R]);
52 }
53 type query(int k,int l,int r,int x,int y){
54 if ((l>y)||(x>r))return type{o,o};
55 if ((x<=l)&&(r<=y))return f[k];
56 return merge(query(L,l,mid,x,y),query(R,mid+1,r,x,y));
57 }
58 bool pd(type k,int p,int x){
59 if (!x)return k.p0.a[p].x>k.p0.a[p].y;
60 if (x==1)return k.p1.a[p].x>k.p1.a[p].y;
61 if (x==2){
62 if (k.p0.k==k.p1.k)return 1;
63 if (k.p0.k<k.p1.k)return k.p0.a[p].x>=k.p0.a[p].y;
64 return k.p1.a[p].x>=k.p1.a[p].y;
65 }
66 }
67 int main(){
68 o0.a[0].y=o0.a[1].y=1;
69 o1.k=o1.a[0].x=o1.a[1].x=1;
70 scanf("%d",&t);
71 while (t--){
72 scanf("%d",&n);
73 for(int i=1;i<=n;i++){
74 scanf("%d",&a[i]);
75 ans[i]=0;
76 id[a[i]]=i;
77 }
78 build(1,1,n);
79 for(int i=1;i<=n;i++){
80 update(1,1,n,id[i]);
81 type x=query(1,1,n,1,id[i]-1),y=query(1,1,n,id[i]+1,n);
82 if ((pd(x,0,0))&&(pd(y,1,1))||(pd(x,0,1))&&(pd(y,1,0))||(pd(x,0,2))&&(pd(y,1,2)))ans[id[i]]=1;
83 }
84 for(int i=1;i<=n;i++)printf("%d",ans[i]);
85 printf("\n");
86 }
87 }
[nowcoder5669E]Eliminate++的更多相关文章
- Effective Java 06 Eliminate obsolete object references
NOTE Nulling out object references should be the exception rather than the norm. Another common sour ...
- Effective Java 24 Eliminate unchecked warnings
Note Eliminate every unchecked warning that you can. Set<Lark> exaltation = new HashSet(); The ...
- hdu 4115 Eliminate the Conflict ( 2-sat )
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- hdu4115 Eliminate the Conflict
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Once you eliminate all the other factors,the only thing remaining must be the truth.
Once you eliminate all the other factors,the only thing remaining must be the truth. 一旦你排除了杂因,剩下的一定是 ...
- HDU 4115 Eliminate the Conflict(2-SAT)(2011 Asia ChengDu Regional Contest)
Problem Description Conflicts are everywhere in the world, from the young to the elderly, from famil ...
- 把配置和环境解耦 eliminate “works on my machine” problems when collaborating on code with co-workers docker架构与解决的问题
Docker实践 - 懒人的技术笔记 - 博客频道 - CSDN.NET http://blog.csdn.net/lincyang/article/details/43055061 Docker直 ...
- HDU 4115 Eliminate the Conflict(2-sat)
HDU 4115 Eliminate the Conflict pid=4115">题目链接 题意:Alice和Bob这对狗男女在玩剪刀石头布.已知Bob每轮要出什么,然后Bob给Al ...
随机推荐
- 洛谷4400 BlueMary的旅行(分层图+最大流)
qwq 首先,我们观察到题目中提到的每天只能乘坐一次航班的限制,很容易想到建分层图,也就是通过枚举天数,然后每天加入一层新的点. (然而我一开始想的却是erf) 考虑从小到大枚举天数,然后每次新建一层 ...
- Linux常用命令,查看树形结构、删除目录(文件夹)、创建文件、删除文件或目录、复制文件或目录(文件夹)、移动、查看文件内容、权限操作
5.查看树结构(tree) 通常情况下系统未安装该命令,需要yum install -y tree安装 直接使⽤tree显示深度太多,⼀般会使⽤ -L选项⼿⼯设定⽬录深度 格式:tree -L n [ ...
- kivy布局(一)
# import kivy from kivy.app import App # 导入应用 from kivy.uix.label import Label # 导入标签 from kivy.uix. ...
- [软工顶级理解组] Beta阶段测试报告
在测试过程中发现了多少Bug? 测试阶段发现并已修复的bug: 尚且存在,但是难以解决或者不影响使用的bug: 计算重修课程的时候,如果重修课程的课程号和原课程号不同,则GPA计算会出现误差.但我们无 ...
- Spring源码分析-BeanFactoryPostProcessor
Spring源码分析-BeanFactoryPostProcessor 博主技术有限,本文难免有错误的地方,如果您发现了欢迎评论私信指出,谢谢 BeanFactoryPostProcessor接口是S ...
- xmake v2.5.9 发布,改进 C++20 模块,并支持 Nim, Keil MDK 和 Unity Build
xmake 是一个基于 Lua 的轻量级跨平台构建工具,使用 xmake.lua 维护项目构建,相比 makefile/CMakeLists.txt,配置语法更加简洁直观,对新手非常友好,短时间内就能 ...
- Django(72)Django认证系统库--djoser
djoser是什么? 作用:Django认证系统的REST实现.djoser库提供了一组Django Rest Framework视图,用于处理注册.登录.注销.密码重置和帐户激活等基本操作.它适 ...
- Spring Cache 带你飞(一)
Spring 3.1 版本引入基于 annotation 的 cache 技术,提供了一套抽象的缓存实现方案,通过注解方式使用缓存,基于配置的方式灵活使用不同缓存组件.代码具有相当的灵活性和扩展性,本 ...
- Myod 选做
一.题目要求 1.复习c文件处理内容 2.编写myod.c 用myod XXX实现Linux下od -tc -tx XXX的功能 3.main与其他分开,制作静态库和动态库 4.编写Makefile ...
- Android编译执行envsetup.sh,产生工具命令m、mm、mmm、mmma、tapas 、croot、cgrep、jgrep、 resgrep、godir
一般来说编译一个sdk或者一个比较大的工程项目,第一步都是执行 envsetup.sh这个脚本,比如编译android,qt源码以及其他一些嵌入式的sdk. 而且执行的时候需要特别注意使用 sourc ...