zoukankan      html  css  js  c++  java
  • (STL之vector)spoj-Ada and List(易)

    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 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

    使用vector就可以水过……

    记住insert函数!

     1 #include <iostream>
     2 #include <string>
     3 #include <algorithm>
     4 #include <cstring>
     5 #include <cstdio>
     6 #include <cmath>
     7 #include <queue>
     8 #include <set>
     9 #include <map>
    10 #include <list>
    11 #include <stack>
    12 #define mp make_pair
    13 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<int,int> pii;
    19 int n,q;
    20 int a,b,k;
    21 int main()
    22 {
    23     scanf("%d%d",&n,&q);
    24     vector <int> 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         else
    42         {
    43             printf("%d
    ",x[b-1]);
    44         }
    45     }
    46 }
  • 相关阅读:
    counter的使用
    Keras保存模型
    pytorch中F.avg_pool1d()和F.avg_pool2d()
    为什么要进行batchNormalization?
    利用Ajax完成前后端数据传输有关知识(day67)
    ORM中choice参数的设计、Ajax介绍(day66)
    聚合分组查询、F与Q查询、常用字段知识(day65)
    ORM数据库查询操作(单表,多表)(day64)
    CBV源码剖析,模板语法(day63)
    小程序加入购物车抛物线效果
  • 原文地址:https://www.cnblogs.com/quintessence/p/6676157.html
Copyright © 2011-2022 走看看