[nowcoder5667H]Happy Triangle

1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 200005
4 #define oo 0x3f3f3f3f
5 #define mid (l+r>>1)
6 #define T r,1,1e9
7 int V,r,n,p,k,ls[N*30],rs[N*30],sum[N*30],f[N*30];
8 int add(int &k,int l,int r,int x,int y){
9 if (!k)k=++V;
10 sum[k]+=y;
11 if (l==r)return sum[k];
12 if (x<=mid)return add(ls[k],l,mid,x,y);
13 return add(rs[k],mid+1,r,x,y);
14 }
15 int find1(int k,int l,int r,int x){
16 if ((!x)||(!sum[k]))return -oo;
17 if (l==r)return l;
18 if (x<=mid)return find1(ls[k],l,mid,x);
19 int ans=find1(rs[k],mid+1,r,x);
20 if ((ans>0)||(!sum[ls[k]]))return ans;
21 return find1(ls[k],l,mid,x);
22 }
23 int find2(int k,int l,int r,int x){
24 if ((x>1e9)||(!sum[k]))return oo;
25 if (l==r)return l;
26 if (mid<x)return find2(rs[k],mid+1,r,x);
27 int ans=find2(ls[k],l,mid,x);
28 if ((ans!=oo)||(!sum[rs[k]]))return ans;
29 return find2(rs[k],mid+1,r,x);
30 }
31 void update(int k,int l,int r,int x,int y){
32 if (l==r){
33 f[k]=y;
34 return;
35 }
36 if (x<=mid)update(ls[k],l,mid,x,y);
37 else update(rs[k],mid+1,r,x,y);
38 f[k]=min(f[ls[k]],f[rs[k]]);
39 }
40 int query(int k,int l,int r,int x,int y){
41 if ((!k)||(l>y)||(x>r))return oo;
42 if ((x<=l)&&(r<=y))return f[k];
43 return min(query(ls[k],l,mid,x,y),query(rs[k],mid+1,r,x,y));
44 }
45 int main(){
46 scanf("%d",&n);
47 memset(f,oo,sizeof(f));
48 for(int i=1;i<=n;i++){
49 scanf("%d%d",&p,&k);
50 int x=find1(T,k-1),y=find2(T,k+1);
51 if (p<3){
52 int t=add(T,k,3-2*p);
53 if ((p==1)&&(t==2))update(T,k,0);
54 if ((p==2)&&(t==1))update(T,k,k-x);
55 if ((p==1)&&(t==1)){
56 update(T,k,k-x);
57 if ((y!=oo)&&(add(T,y,0)==1))update(T,y,y-k);
58 }
59 if ((p==2)&&(t==0)){
60 update(T,k,oo);
61 if ((y!=oo)&&(add(T,y,0)==1))update(T,y,y-x);
62 }
63 }
64 else{
65 int t=add(T,k,0);
66 if ((t>1)||((x>0)&&((t==1)||(2*x-query(T,x,x)>k)))){
67 printf("Yes\n");
68 continue;
69 }
70 if (query(T,y,1e9)<k)printf("Yes\n");
71 else printf("No\n");
72 }
73 }
74 }
[nowcoder5667H]Happy Triangle的更多相关文章
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [LeetCode] Pascal's Triangle II 杨辉三角之二
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Triangle - Delaunay Triangulator
Triangle - Delaunay Triangulator eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...
- LeetCode 118 Pascal's Triangle
Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
- LeetCode 119 Pascal's Triangle II
Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...
随机推荐
- caffe转换变量时的gflags问题
先解决错误7,解决方式来自于http://blog.csdn.net/wishchin/article/details/51888566这篇博文,感谢博主 只需要添加上 #pragma comment ...
- 前端必会的Javascript经典面试题
这是前端最基础的问题,也是在面试中难倒无数同学的经典问题 01. Javascript 数据类型 Javascript 数据类型 = 基本类型 + 引用类型 ES6 之前 5 + 1 = 6 种 ES ...
- CAD_DWG图Web可视化一站式解决方案-唯杰地图-vjmap
背景 DWG图是AutoCAD是私有格式,只能在CAD软件上编辑查看,如何发布至Web上做数据展示,GIS分析应用开发,一直是业内头疼的事情. 传统的办法采用的解析AutoCAD图形绘制,并封装成Ac ...
- opencv中的exp32f函数
exp32f opencv的exp函数和cmath的exp函数在精度上存在一定差异,通过查找源码,发现了这么一段实现.代码如下: 点击查看代码 #define EXPTAB_SCALE 6 #defi ...
- 2.3 Core Building Blocks 核心构件
Core Building Blocks 核心构件 DDD mostly focuses on the Domain & Application Layers and ignores the ...
- java定时任务调度框架
java定时任务目前主要有三种: Java自带的java.util.Timer类,这个类允许你调度一个java.util.TimerTask任务.使用这种方式可以让你的程序按照某一个频度执行,但不能在 ...
- Kafka消息(存储)格式及索引组织方式
要深入学习Kafka,理解Kafka的存储机制是非常重要的.本文介绍Kafka存储消息的格式以及数据文件和索引组织方式,以便更好的理解Kafka是如何工作的. Kafka消息存储格式 Kafka为了保 ...
- 【UE4 C++ 基础知识】<10>资源的引用
2种引用方式 硬引用(Hard Reference) 即对象 A 引用对象 B,并导致对象 B 在对象 A 加载时加载 硬引用过多会导致运行时很多暂时用不到的资源也被加载到内存中 大量资源会导致进程阻 ...
- 灵光一闪!帮你使用Vue,搞定无法解决的“动态挂载”
在一些特殊场景下,使用组件的时机无法确定,或者无法在Vue的template中确定要我们要使用的组件,这时就需要动态的挂载组件,或者使用运行时编译动态创建组件并挂载. 今天我们将带大家从实际项目出发, ...
- [对对子队]会议记录5.27(Scrum Meeting12)
今天已完成的工作 朱俊豪 工作内容:寻找电池模型和BGM,修改关卡选择场景 相关issue:优化初步导出版本 相关签入:perf:地图界面优化 feat:更新系列资源(星星,大电池) 何瑞 ...