Skip to content

Latest commit

 

History

History
128 lines (124 loc) · 3.31 KB

1087_Diablo.md

File metadata and controls

128 lines (124 loc) · 3.31 KB

Algorithm: Data Structure

Problem: 1087 Diablo

#include <bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
#define ll long long
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define vb vector<bool>
#define vs vector<string>
///............x...........///
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define UNIQUE(X) (X).erase(unique(all(X)), (X).end())
#define ft cout << "for test"<<endl;
#define read(v, a, n) for (int i = a; i<n; i++)cin>>v[i];
#define print(v) for (auto it : v)cout << it<<" ";cout << endl;
#define PI acos(-1.0)
#define yes cout <<"Yes"<< endl
#define no cout<<"No"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test, cs = 1;cin>>test;while (test--)
#define casep cout<<"Case "<< cs++<<": ";
///................function.....................///

#define D(a) (double)(a)
#define siz(s) (int)(s.size())
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define Min(a) *min_element(all(a))
///#define mod 1000000007
///.........Graph.........///
int X[] = {1, -1, 0, 0};
int Y[] = {0, 0, 1, -1};
///........constant........///
const ll N = 1e6+5;
void file(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
#define lft nd*2
#define rgt nd*2+1
#define mid (b+e)/2
class segtree{
    public:
    int n;
    vector<int> tree,v;
    segtree(int _n){
        n=_n;
        tree.resize(n*4);
    }
    void update(int nd, int b, int e, int l, int x){
        if(b>e or e<l or l<b)return;
        if(b==e and l==b){
            tree[nd]+=x;
            return;
        }
        update(lft,b,mid,l,x);
        update(rgt,mid+1,e,l,x);
        tree[nd]=tree[lft]+tree[rgt];
    }
    int query(int nd, int b, int e, int x){
        if(tree[nd]<x)return -1;
        if(b==e){
            return b;
        }
        if(tree[lft]>=x){
            return query(lft,b,mid,x);
        }
        else{
            return query(rgt,mid+1,e,x-tree[lft]);
        }
    }
};
int main(){
    FIO;
    // file();
    t_c{
        int n,m,i,j;
        cin>>n>>m;
        int x = n+m+5;
        segtree obj(x);
        vi v={0};
        for(i=1; i<=n; i++){
            cin>>j;
            v.pb(j);
            obj.update(1,1,x,i,1);
        }
        int pos=n+1;
        cout<<"Case "<<cs++<<":"<<endl;
        while(m--){
            string s;
            cin>>s>>j;
            if(s.front()=='c'){
                int ans=obj.query(1,1,x,j);
                if(~ans){
                    cout<<v[ans]<<endl;
                    obj.update(1,1,x,ans,-1);
                }
                else cout<<"none"<<endl;
            }
            else{
                v.pb(j);
                obj.update(1,1,x,pos,1);
                pos++;
            }
        }
        
    }

}