A - Ada and List

AdatheLadybug有一份包含数字的待办事项列表。她需要在列表中进行插入、删除和查询操作。本篇介绍了一种使用C++ STL中的deque来高效处理这些操作的方法。

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

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

k means that you will erase number from position k

k means that you will print number from position k

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

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

Output

For each query of type 3, print kth numbers

Example Input

6 10
1 2 4 8 16 32
3 4
1 1 7
3 2
2 2
2 2
3 2
1 6 666
3 6
2 1
3 1

Example Output

8
1
4
666
4

Queries explanations

1 2 4 8 16 32
7 1 2 4 8 16 32
7 1 2 4 8 16 32
7 2 4 8 16 32
7 4 8 16 32
7 4 8 16 32
7 4 8 16 32 666
7 4 8 16 32 666
4 8 16 32 666

4 8 16 32 666

解析:

STL模拟;

#include<bits/stdc++.h>
using namespace std;
deque<int>q;
int n,Q;
int  num;
int a;
int k;
int x;

int main()
{
    scanf("%d%d",&n,&Q);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&num);
        q.push_back(num);
    }
    while(Q--)
    {
        scanf("%d",&a);
        if(a==1)
        {
            scanf("%d%d",&k,&x);
            ///long long tem=q.at(k-1)+x;
            ///cout<<tem<<endl;
            q.insert(q.begin()+k-1,x);
            ///q.erase(q.begin()+k);

        }
        else if(a==2)
        {
            scanf("%d",&k);
            q.erase(q.begin()+k-1);
        }
        else {
            scanf("%d",&k);
            printf("%d\n",q.at(k-1));
        }
    }
}


INFO nova.compute.manager [None req-9be3f6e9-9915-46f7-8c33-8aed3dff85dc 791bfb1306104da487e042b899dcc0dd 4e2db1f9c56e45ee9f7563120e77bca0 - - default default] [instance: 0414cda2-2b5e-44d4-b2a8-a95db2ccb45e] Terminating instance 2025-05-28 15:11:54.305 13769 INFO nova.virt.libvirt.driver [-] [instance: 0414cda2-2b5e-44d4-b2a8-a95db2ccb45e] Instance destroyed successfully. 2025-05-28 15:11:54.309 13769 INFO os_vif [None req-9be3f6e9-9915-46f7-8c33-8aed3dff85dc 791bfb1306104da487e042b899dcc0dd 4e2db1f9c56e45ee9f7563120e77bca0 - - default default] Successfully unplugged vif VIFOpenVSwitch(active=False,address=fa:16:3e:83:93:22,bridge_name='br-int',has_traffic_filtering=True,id=4634ada1-ca39-43bc-94dc-0ebedee163b4,network=Network(d750c7f1-dc8b-444e-9cc1-89e4fe744a00),plugin='ovs',port_profile=VIFPortProfileOpenVSwitch,preserve_on_delete=False,vif_name='tap4634ada1-ca') 2025-05-28 15:11:54.330 13769 INFO nova.virt.libvirt.driver [None req-9be3f6e9-9915-46f7-8c33-8aed3dff85dc 791bfb1306104da487e042b899dcc0dd 4e2db1f9c56e45ee9f7563120e77bca0 - - default default] [instance: 0414cda2-2b5e-44d4-b2a8-a95db2ccb45e] Deletion of /var/lib/nova/instances/0414cda2-2b5e-44d4-b2a8-a95db2ccb45e_del complete 2025-05-28 15:11:54.354 13769 INFO nova.compute.manager [None req-9be3f6e9-9915-46f7-8c33-8aed3dff85dc 791bfb1306104da487e042b899dcc0dd 4e2db1f9c56e45ee9f7563120e77bca0 - - default default] [instance: 0414cda2-2b5e-44d4-b2a8-a95db2ccb45e] Took 0.05 seconds to destroy the instance on the hypervisor. 2025-05-28 15:11:54.805 13769 ERROR nova.volume.cinder [None req-9be3f6e9-9915-46f7-8c33-8aed3dff85dc 791bfb1306104da487e042b899dcc0dd 4e2db1f9c56e45ee9f7563120e77bca0 - - default default] Delete attachment failed for attachment 51bac83d-c4af-4207-87bc-e353e726c645. Error: ConflictNovaUsingAttachment: Detach volume from instance 0414cda2-2b5e-44d4-b2a8-a95db2ccb45e using the Compute API (HTTP 409) (Request-ID: req-c44c4f32-c59e-4ccf-ad52-f3e8dba1f70c) Code: 409: cinderclient.exceptions.ClientException: ConflictNovaUsingAttachment: Detach volume from instance 0414cda2-2b5e-44d4-b2a8-a95db2ccb45e using the Compute API (HTTP 409) (Request-ID: req-c44c4f32-c59e-4ccf-ad52-f3e8dba1f70c) 2025-05-28 15:11:54.806 13769 WARNING nova.compute.manager [None req-9be3f6e9-9915-46f7-8c33-8aed3dff85dc 791bfb1306104da487e042b899dcc0dd 4e2db1f9c56e45ee9f7563120e77bca0 - - default default] [instance: 0414cda2-2b5e-44d4-b2a8-a95db2ccb45e] Ignoring unknown cinder exception for volume 897705c8-0efb-4566-88bf-12f0a58d8797: ConflictNovaUsingAttachment: Detach volume from instance 0414cda2-2b5e-44d4-b2a8-a95db2ccb45e using the Compute API (HTTP 409) (Request-ID: req-c44c4f32-c59e-4ccf-ad52-f3e8dba1f70c): cinderclient.exceptions.ClientException: ConflictNovaUsingAttachment: Detach volume from instance 0414cda2-2b5e-44d4-b2a8-a95db2ccb45e using the Compute API (HTTP 409) (Request-ID: req-c44c4f32-c59e-4ccf-ad52-f3e8dba1f70c) 2025-05-28 15:11:54.807 13769 INFO nova.compute.manager [None req-9be3f6e9-9915-46f7-8c33-8aed3dff85dc 791bfb1306104da487e042b899dcc0dd 4e2db1f9c56e45ee9f7563120e77bca0 - - default default] [instance: 0414cda2-2b5e-44d4-b2a8-a95db2ccb45e] Took 0.45 seconds to detach 1 volumes for instance. 2025-05-28 15:11:55.122 13769 ERROR nova.compute.manager [None req-9be3f6e9-9915-46f7-8c33-8aed3dff85dc 791bfb1306104da487e042b899dcc0dd 4e2db1f9c56e45ee9f7563120e77bca0 - - default default] [instance: 0414cda2-2b5e-44d4-b2a8-a95db2ccb45e] Failed to build and run instance: libvirt.libvirtError: Secret not found: no secret with matching uuid 'cb617681-8414-4e3f-bad3-4d642d75056c'
最新发布
05-29
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值