[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 ...
随机推荐
- Serverless 的初心、现状和未来
作者 | 不瞋 导读:Serverless 是如何产生的?当前有哪些落地场景?Serverless 的未来又将如何?本文分享了阿里云高级技术专家不瞋对于 Serverless 的看法,回顾其发展历程, ...
- ASP.NET Core Filter与IOC的羁绊
前言 我们在使用ASP.NET Core进行服务端应用开发的时候,或多或少都会涉及到使用Filter的场景.Filter简单来说是Action的拦截器,它可以在Action执行之前或者之后对请求信息进 ...
- 阿里云服务器上在docker部署jenkins
1.查询jenkins:docker search jenkins 2.拉取jenkins镜像 docker pull jenkins/jenkins:lts 3.新建jenkins的工作目录: mk ...
- 重庆邮电大学第十一届ACM程序设计竞赛-网络选拔赛 C题
1008: 偷袭 时间限制: 1.000 sec 内存限制: 128 MB 武林要以和为贵,张麻子不讲武德来偷袭马老师的亲传弟子. 马老师有n个亲传弟子,每个弟子有一个武力值a[i]. n个弟子中只有 ...
- js模板引擎laytpl的使用
在我们实际的开发过程中,可能会遇到使用ajax去后台获取一堆的数据,然后动态的渲染到页面上.比如:去后台获取一个list集合,然后将数据以表格的形式展示在页面上.另外一种可能发生的情况就是页面上需要批 ...
- 【BZOJ2070】列队春游———[组合数学+概率DP]
数学渣滓不可做の题OTZ Description (单身人士不可做 Input | Output 3 ...
- 按照工业标准1英寸=25.4mm,而在电子元件成像领域Sensor尺寸1英寸=16mm。
按照工业标准1英寸=25.4mm,而在电子元件成像领域Sensor尺寸1英寸=16mm. 我们平常所说的CCD/CMOS的尺寸,实际上是指Sensor对角线的长度,这一点跟我们平常所说的屏幕尺寸是一样 ...
- 重建二叉树 牛客网 剑指Offer
重建二叉树 牛客网 剑指Offer 题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3, ...
- hdu 5095 Linearization of the kernel functions in SVM(模拟,分类清楚就行)
题意: INPUT: The input of the first line is an integer T, which is the number of test data (T<120). ...
- Vue3学习(十)之 页面、菜单、路由的使用
一.前言 好几天没更文了,周末真的太冷了,在家躺了一天不爱动.今天给暖气了,相对不那么冷了,就可以继续更文了. 由文章标题不难看出,就是实现点击菜单跳转的意思,我写的很直白了,哈哈. 二.实现点击菜单 ...