LightOJ 1087 - Diablo

// Although my Run time is not good but it is peculiar that I have got // AC using Vector erase function
// try with Segment Tree or BIT or BST

//Next Codeforces Round #354 (Div. 2)
#include<bits/stdc++.h>

//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>

using namespace std;

#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
//#define i64 long long
#define high 100005

typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef map<int, int>mpii;

int main()
{
    int t , tc=0 , n , q , i , x;
    vii v;
    char ch[3];
    sf("%d", &t);
    while(t--)
    {
        v.clear();

        sf("%d %d", &n , &q);

        for(i=0; i<n; i++)
        {
            sf("%d", &x);
            v.push_back(x);
        }

        pf("Case %d:\n", ++tc);

        while(q--)
        {
            sf("%s %d" , &ch , &x);

            if(ch[0] == 'a')
            {
                v.push_back(x);
            }

            else
            {
                if(v.size()==x-1 or v.size() < x-1)
                {
                    pf("none\n");
                }

                else
                {
                    pf("%d\n", v[x-1]);
                    v.erase(v.begin() + (x-1));
                }
            }
        }
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number