set使用实例1+lower_bound(val)(个人模版)

简介: set使用实例1+lower_bound(val): 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 ...

set使用实例1+lower_bound(val):

 1 #include<stdio.h>  
 2 #include<set>  
 3 #include<iostream>  
 4 #include<algorithm>  
 5 #include<string.h>  
 6 #include<map>  
 7 using namespace std;  
 8 int main()  
 9 {  
10     int n;  
11     while(~scanf("%d",&n))  
12     {  
13         map<int ,int>lson,rson;  
14         set<int >s;  
15         set<int >::iterator pos;  
16         for(int i=0;i<n;i++)  
17         {  
18             int x;  
19             scanf("%d",&x);  
20             if(i==0)  
21             {  
22                 s.insert(x);  
23                 continue;  
24             }  
25             pos=s.lower_bound(x);  
26             if(pos!=s.end()&&lson[*pos]==0)  
27             {  
28                 lson[*pos]=x;  
29             }  
30             else  
31             {  
32                 pos--;  
33                 rson[*pos]=x;  
34             }  
35             printf("%d ",*pos);  
36             s.insert(x);  
37         }  
38         printf("\n");  
39     }  
40 }  

 

目录
相关文章
|
2月前
|
存储 关系型数据库 MySQL
lower_case_table_names 修改为何不生效
lower_case_table_names 是 MySQL 和 MariaDB 中的一个系统变量,它决定了数据库和表名在存储和引用时的大小写敏感性。这个变量有以下几个可能的值: 0:表名存储为给定的大小写,并区分大小写。这是大多数 Unix 系统的默认设置。 1:表名在存储和引用时都转换为小写,不区分大小写。这是 Windows 和 macOS 的默认设置。 2:表名存储为给定的大小写,但引用时不区分大小写。 如果你尝试修改 lower_case_table_names 的值但发现它不生效,可能是由以下几个原因造成的: 配置文件位置不正确:确保你在正确的配置文件中进行了修改。对于 MyS
103 2
二分查找模板 low_bound、upper_bound
二分查找模板 low_bound、upper_bound
|
9月前
|
算法 IDE 开发工具
【Python语法】类型提示(self, nums: List[int]) -> List[int],报错NameError: name ‘List‘ is not defined解决
【Python语法】类型提示(self, nums: List[int]) -> List[int],报错NameError: name ‘List‘ is not defined解决
LeetCode 307. Range Sum Query - Mutable
update(i, val) 函数可以通过将下标为 i 的数值更新为 val,从而对数列进行修改。
76 0
LeetCode 307. Range Sum Query - Mutable
LeetCode 304. Range Sum Query 2D - Immutable
给定一个二维矩阵,计算其子矩形范围内元素的总和,该子矩阵的左上角为 (row1, col1) ,右下角为 (row2, col2)。
76 0
LeetCode 304. Range Sum Query 2D - Immutable
|
索引
LeetCode 303. Range Sum Query - Immutable
给定一个整数数组 nums,求出数组从索引 i 到 j (i ≤ j) 范围内元素的总和,包含 i, j 两点。
65 0
LeetCode 303. Range Sum Query - Immutable
|
JSON 数据格式 索引
Elastic:doc[‘field‘].value与params._source[‘field‘]的区别;doc循环依赖问题
今天有同学问到doc['field'].value与params._source['field']用法的区别,起因在于下述的一道题的解法上,下面详细讲述下我的看法
158 0
Elastic:doc[‘field‘].value与params._source[‘field‘]的区别;doc循环依赖问题
成功解决random.py"之TypeError: 'range' object does not support item assignment 解决问题
成功解决random.py"之TypeError: 'range' object does not support item assignment

热门文章

最新文章