[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 ...
随机推荐
- Docker-初见
目录 Docker概述 Docker历史 Docker Docker的基本组成 Docker安装 使用流程 底层原理 Docker的常用命令 Portainer 可视化面板安装 镜像原理之联合文件系统 ...
- 你了解一条sql的执行顺序吗
sql是后端开发人员经常碰到的问题,我们经常会写这样的sql:select name,id from student where id=12 order by id desc,把这条sql放到数据库中 ...
- Data Interoperability Tools
这里的工具貌似没有对应函数~~~
- LOJ6469 Magic(trie)
纪念我菜的真实的一场模拟赛 首先看到这个题目,一开始就很毒瘤.一定是没有办法直接做的. 我们考虑转化问题 假设,我们选择枚举\(x\),其中\(x\)是\(10\)的若干次方,那么我们只需要求有多少对 ...
- 洛谷4366——最短路(dijkstra,思维,异或)
题目大意 给定一个n个点,m条边的图,每条边有边权,而每个点\(i\)也可以直接到达\(j\),代价是\(i\ xor\ j\),给定一个S和T,求S到T的最小代价 其中\(n\le100000,m\ ...
- 云原生的弹性 AI 训练系列之三:借助弹性伸缩的 Jupyter Notebook,大幅提高 GPU 利用率
Jupyter Notebooks 在 Kubernetes 上部署往往需要绑定一张 GPU,而大多数时候 GPU 并没有被使用,因此利用率低下.为了解决这一问题,我们开源了 elastic-jupy ...
- 小白自制Linux开发板 五. Debian文件系统制作,以及WIFI配置、交换分区配置
该片文章将完整记录一个Debian的最小文件系统的生成,以及自定义配置WIFI组件.网络组件和交换分区配置 本文章参考:https://whycan.com/t_4236.htmlhttp://www ...
- Succeed_School
# Author kevin_hou class School(object): def __init__(self,name,addr): self.name = name self.addr = ...
- eureka服务端的高可用
eureka client的高可用这个很简单,只需要向eureka服务端上多注册几个实例即可,那么eureka server端如何实现高可用呢?其实eureka server 端也是可以做为一个客户端 ...
- luogu P2746 [USACO5.3]校园网Network of Schools 题解
前言: 火星题... 但是我调了半天,最后看了题解才明白. Wtcl 解析: 显然先缩个点. 第一问,就是问多少入度为0的点. 第二问,抽象一下就是要添加一些边,让一个DAG变成一个SCC,求最小边数 ...