[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 ...
随机推荐
- enum 试图表达64位数
enum AttributeType: unsigned long long{ aa = 1, bb = 2, cc = 0x842AC1040000}; int main() { DWORD64 b ...
- 易华录 X ShardingSphere|葫芦 App 后台数据处理的逻辑捷径
"ShardingSphere 大大简化了分库分表的开发和维护工作,对于业务的快速上线起到了非常大的支撑作用,保守估计 ShardingSphere 至少为我们节省了 4 个月的研发成本.& ...
- golang []byte和string的高性能转换
golang []byte和string的高性能转换 在fasthttp的最佳实践中有这么一句话: Avoid conversion between []byte and string, since ...
- CF123E Maze(期望dp,树形dp,式子)
题目大意: 给你一棵树,边权都是1,每一个点有一个是起点的概率和一个是终点的概率,你将以起点为根,开始在树上随机dfs,每到一个点,就会将他的所有儿子随机打乱成序列,然后按照那个随机顺序走完,直到走到 ...
- 如何在前端通过JavaScript创建修改CAD图形
背景 在之前的博文CAD图DWG解析WebGIS可视化技术分析总结.CAD_DWG图Web可视化一站式解决方案-唯杰地图-vjmap中讲解了如何把CAD的DWG格式的图纸Web可视化的方案,那在Web ...
- C++ 与 Visual Studio 2019 和 WSL(三)
头文件 如果不小心修改了 Linux C/C++ 标准头文件,可以下面这样操作进行恢复: 项目 → 重新扫描解决方案
- webRTC中语音降噪模块ANS细节详解(二)
上篇(webRTC中语音降噪模块ANS细节详解(一))讲了维纳滤波的基本原理.本篇先给出webRTC中ANS的基本处理过程,然后讲其中两步(即时域转频域和频域转时域)中的一些处理细节. ANS的基本处 ...
- 异常大讨论-抛出异常还是返回false
iteye精华帖之异常大讨论 原帖链接http://www.iteye.com/topic/2038 Robbin的观点 观点1:Exception实际上代表了一个UseCase中的异常流的处理. 绝 ...
- [敏捷软工团队博客]Beta设计和计划
项目 内容 2020春季计算机学院软件工程(罗杰 任健) 博客园班级博客 作业要求 Beta设计和计划 我们在这个课程的目标是 在团队合作中锻炼自己 这个作业在哪个具体方面帮助我们实现目标 对Beta ...
- Spring Authorization Server的使用
Spring Authorization Server的使用 一.背景 二.前置知识 三.需求 四.核心代码编写 1.引入授权服务器依赖 2.创建授权服务器用户 3.创建授权服务器和客户端 五.测试 ...