博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(STL之vector)spoj-Ada and List(易)
阅读量:5020 次
发布时间:2019-06-12

本文共 2127 字,大约阅读时间需要 7 分钟。

Ada the Ladybug has a TODO-list (containing only numbers - for simplicity). She is still doing something, so she sometimes erases kth number, sometimes she inserts something on kth position and sometime she asks for kth number.

Sadly, she is now searching for a work at position k so she doesn't have time to do this herself. Can you help her?

Input

The first line will contain 0 < N ≤ 105,0 < Q < 5*105, the number of elements in TODO-list and number of queries.

Then a line with N numbers follows. Each number 0 ≤ Ak ≤ 109 means kth number in her TODO-list.

Afterward, Q lines follow, each beginning with number 1 ≤ a ≤ 3

1 k x means that you will add number x to position k

2 k means that you will erase number from position k

3 k means that you will print number from position k

For all queries, it is true that 1 ≤ k ≤ #SizeOfList, 0 ≤ x ≤ 109 (for query 1, it can be also put to position #SizeOfList + 1)

You will never get query of type 2 or 3 if the list is empty

Output

For each query of type 3, print kth numbers

Example Input

6 101 2 4 8 16 323 41 1 73 22 22 23 21 6 6663 62 13 1

Example Output

8146664

Queries explanations

1 2 4 8 16 327 1 2 4 8 16 327 1 2 4 8 16 327 2 4 8 16 327 4 8 16 327 4 8 16 327 4 8 16 32 6667 4 8 16 32 6664 8 16 32 6664 8 16 32 666

使用vector就可以水过……

记住insert函数!

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #define mp make_pair13 typedef long long ll;14 typedef unsigned long long ull;15 const int MAX=1e6+5;16 const int INF=-1e9;17 using namespace std;18 typedef pair
pii;19 int n,q;20 int a,b,k;21 int main()22 {23 scanf("%d%d",&n,&q);24 vector
x;25 for(int i=1;i<=n;i++)26 {27 scanf("%d",&a);x.push_back(a);28 }29 for(int i=1;i<=q;i++)30 {31 scanf("%d%d",&a,&b);32 if(a==1)33 {34 scanf("%d",&k);35 x.insert(x.begin()+b-1,k);36 }37 else if(a==2)38 {39 x.erase(x.begin()+b-1);40 }41 else42 {43 printf("%d\n",x[b-1]);44 }45 }46 }

 

转载于:https://www.cnblogs.com/quintessence/p/6676157.html

你可能感兴趣的文章
Android: NDK编程入门笔记
查看>>
深刻理解Linux进程间通信(IPC)
查看>>
windows 7中添加新硬件的两种方法(本地回环网卡)
查看>>
javascript 高级程序设计学习笔记(面向对象的程序设计) 2
查看>>
支配集,点覆盖集,点独立集之间的联系
查看>>
SetCapture ReleaseCapture
查看>>
DataGridView ——管理员对用户的那点操作
查看>>
POJ - 1185 炮兵阵地 (状态压缩)
查看>>
ios7 JavaScriptCore.framework
查看>>
算法6-5:哈希表应用之集合
查看>>
压力单位MPa、Psi和bar之间换算公式
查看>>
Moscow Pre-Finals Workshop 2016. National Taiwan U Selection
查看>>
程序员面试、算法研究、编程艺术、红黑树4大系列集锦与总结 .
查看>>
idea tomcat 配置
查看>>
冲刺第二天
查看>>
LeetCode 405. Convert a Number to Hexadecimal (把一个数转化为16进制)
查看>>
ASP.NET MVC 3–Global Action Filters
查看>>
OFFICE安装提示1935错误
查看>>
jva基础网络编程
查看>>
js 正计时和倒计时
查看>>