当前位置:网站首页>ZCMU--1367: Data Structure
ZCMU--1367: Data Structure
2022-06-26 17:42:00 【Little why】
Description
Give a set , Initially empty , Conduct N operations , There are three types of operations :
1 Add an element to the collection , If it already exists in the collection , There is no need to add again
2 Remove an element from the collection , If the element does not exist in the collection , You do not need to delete
3 Determine the rank of the element in the set ( The youngest is the eldest ), If the element does not exist, please output :"sorry"( No double quotes )
Input
Multiple sets of test data
Each group 1 That's ok :1 It's an integer N, Indicates the number of operations .(2<=N<=10000)
The first 2 - (N+1) That's ok : Each row 2 It's an integer k and s Corresponding to the mode of operation and the element to be operated (1<=k<=3,1<=s<=1000000)
Output
Corresponding to each operation 3, Give the corresponding results
Sample Input
8
3 1
2 1
1 1
1 1
1 2
3 2
2 2
3 2
5
1 1
1 100
1 1000000
2 99999
3 1000000
Sample Output
sorry
2
sorry
3
analysis : Find out if the element exists , We can use arrays to quickly determine , But who is in the back row , violence 1~N The traversal must have timed out , So we have to use set To store , Then use the iterator to traverse , Initial settings c=1, It means who is in the row , Traverse ,c++, Until you find the element , Output c Is the rank of the element in the collection .
#include <bits/stdc++.h>
using namespace std;
int a[1000005]; // Used to directly determine whether an element exists
int main()
{
int n,z,p,c;
while(~scanf("%d",&n)){
set<int>st;
set<int>::iterator it; // iterator , Prepare for the next ranking
memset(a,0,sizeof(a)); // initialization 0
while(n--){
c=1; // Who is the oldest
scanf("%d%d",&z,&p);
if(z==1){ // Instructions 1
if(a[p]==0) st.insert(p),a[p]=1;// If the element does not exist , Deposit in set, also a[p] Turn into 1
}else if(z==2){ // Instructions 2
if(a[p]==1){ // If it exists, delete it
st.erase(st.find(p)); // Delete
a[p]=0; //a[p] Set as 0, The element no longer exists
}
}else if(z==3){
if(a[p]==1){ // There is
for (it=st.begin();it!=st.end();it++){ // Iterator traversal
if(*it==p){ //*it Indicated value
printf("%d\n",c); // Found the element , Just output the ranking
break;
}
c++; // Did not find , ranking ++
}
}else printf("sorry\n"); //a[p]=0, The element does not exist , Direct output sorry
}
}
st.clear();
}
return 0;
}边栏推荐
- 小程序设置按钮分享功能
- Microservice architecture practice: business management background and SSO design: SSO design
- Various types of gypsum PBR multi-channel mapping materials, please collect them quickly!
- Prometeus 2.34.0 new features
- 链游系统开发技术方案设计丨NFT链游系统开发流程及源码
- Cache breakdown! Don't even know how to write code???
- Using redis for user access data statistics hyperloglog and bitmap advanced data types
- 物联网协议的王者:MQTT
- Programmer's essential toolkit, please collect!
- [buuctf.reverse] 126-130
猜你喜欢

Getting started with mongodb

Microservice architecture practice: business management background and SSO design, SSO client design

一起备战蓝桥杯与CCF-CSP之大模拟炉石传说

ACL 2022 | zero sample multilingual extracted text summarization based on neural label search

直播预告|程序员进击,如何提升研发效能?6月21日晚视频号、B站同步直播,不见不散!

Platform management background and merchant menu resource management: Design of platform management background data service

Niuke network: Design LRU cache structure design LFU cache structure

SIGIR 2022 | 港大等提出超图对比学习在推荐系统中的应用

vue--vuerouter缓存路由组件

#26class中get和set设置
随机推荐
无需人工先验!港大&同济&LunarAI&旷视提出基于语义分组的自监督视觉表征学习,显著提升目标检测、实例分割和语义分割任务!
清华&商汤&上海AI&CUHK提出Siamese Image Modeling,兼具linear probing和密集预测性能!
分布式架构概述
KDD 2022 | 如何在跨域推荐中使用对比学习?
Jouer avec Linux et installer et configurer MySQL facilement
类型多样的石膏PBR多通道贴图素材,速来收藏!
Viewing the task arrangement ability of monorepo tool from turborepo
SIGIR 2022 | 港大等提出超图对比学习在推荐系统中的应用
陈强:阿里千亿级大规模数字商业知识图谱助力业务增长
9、智慧交通项目(2)
Number of solutions for knapsack problem
Discussion: the next generation of stable coins
宝藏又小众的CTA动画素材素材网站分享
Vscode usage - Remote SSH configuration description
Necessary decorator mode for 3 years' work
The difference between round and truncate in SQL (round or truncate)
Live broadcast preview | how can programmers improve R & D efficiency? On the evening of June 21, the video number and station B will broadcast live at the same time. See you or leave!
Problems encountered this week
Here comes the hero League full skin Downloader
Deployment and operation of mongodb partitioned cluster