[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 ...
随机推荐
- t-SNE 从入门到放弃
t-SNE 算法 1 前言 t-SNE 即 t-distributed stochastic neighbor embedding 是一种用于降维的机器学习算法,在 2008 年由 Laurens v ...
- opencv中的exp32f函数
exp32f opencv的exp函数和cmath的exp函数在精度上存在一定差异,通过查找源码,发现了这么一段实现.代码如下: 点击查看代码 #define EXPTAB_SCALE 6 #defi ...
- 2021.3.3--vj补题
题目 C - C CodeForces - 1166C The legend of the foundation of Vectorland talks of two integers xx and ...
- yum源安装nginx
nginx使用yum源安装 安装步骤 使用yum源安装依赖 yum install yum-utils 配置nginx.repo的yum文件 vim /etc/yum.repos.d/nginx.re ...
- Upload-labs通关指南(下) 11-20
承接上篇,这次我们继续做下半部分. 有些题目有其他做法是针对于windows系统特性的,并不能在linux上奏效,因此不在考虑范围之内. Pass-11 制作图片马直接上传 copy a.jpg /a ...
- 第3次 Beta Scrum Meeting
本次会议为Beta阶段第3次Scrum Meeting会议 会议概要 会议时间:2021年6月2日 会议地点:「腾讯会议」线上进行 会议时长:0.5小时 会议内容简介:对完成工作进行阶段性汇报:对下一 ...
- [no code][scrum meeting] Alpha 5
项目 内容 会议时间 2020-04-10 会议主题 后端技术讨论 会议时长 30min 参会人员 全体成员 $( "#cnblogs_post_body" ).catalog() ...
- SpringCloud 2020.0.4 系列之服务降级
1. 概述 老话说的好:做人要正直,做事要正派,胸怀坦荡.光明磊落,才会赢得他人的信赖与尊敬. 言归正传,之前聊了服务间通信的组件 Feign,今天我们来聊聊服务降级. 服务降级简单的理解就是给一个备 ...
- elasticsearch入门(简单的crud操作)
记录一下,elasticsearch从创建索引到插入数据的一个crud操作. 一.创建索引 curl -XPUT "http://192.168.99.1:9200/productindex ...
- IOC和DI之刨根问底之第一节
很多freshman上来就想搞清楚什么是IOC和DI,其实很多先进的理论和技术都在老的基础上升华出来的,最终目的是为了解放生产力. 所以先来说说下面两点基础知识: Direct Dependency( ...