Language: C++

#include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif
s
typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

//range add,compute range max
template<class T> class segtree{
public:
    int n,size;
    vector<T> dat,sum; //????????????,?????????????§?????¶?????????????
    segtree()=default;
    segtree(int size_,T x){ init(size_,x); }
    void init(int size_,T x){
        size=size_;
        n=1;
        while(n<size) n*=2;
        dat.assign(2*n-1,0);
        sum.assign(2*n-1,0);
        for(int i=0; i<size; ++i) add(i,i+1,x);
    }
    void add(int a,int b,T x){ add(a,b,x,0,0,n); }
    T add(int a,int b,T x,int k,int l,int r){
        if(b<=l or r<=a) return dat[k];
        if(a<=l and r<=b){
            sum[k]+=x;
            return dat[k]+=x;
        }
        int m=(l+r)/2;
        return dat[k]=max(add(a,b,x,2*k+1,l,m),add(a,b,x,2*k+2,m,r))+sum[k];
    }
    T query(int a,int b){ return query(a,b,0,0,n); }
    T query(int a,int b,int k,int l,int r){
        if(b<=l or r<=a) return numeric_limits<ll>::min();
        if(a<=l and r<=b) return dat[k];
        int m=(l+r)/2;
        return max(query(a,b,2*k+1,l,m),query(a,b,2*k+2,m,r))+sum[k];
    }
};

void solve(int q,int lim){
    map<int,int> m1,m2; //segtree?????§???index
    segtree<ll> seg(q,numeric_limits<int>::min());
    int tail=0,size=0;

    auto get_pos=[&](int x){ //?????????x??????????????????segtree?????§???index????±???????
        int lb=-1,ub=q-1;
        while(ub-lb>1){
            int m=(lb+ub)/2;
            if(seg.query(0,m+1)>=x) ub=m;
            else lb=m;
        }
        return ub;
    };

    auto erase=[&](int k){ //segtree?????§???index??§k???????????????????????????
        seg.add(k,k+1,numeric_limits<int>::min());
        seg.add(k+1,q,-1);
    };

    rep(i,0,q){
        int query,x;
        cin >> query >> x;
        if(query==0){
            if(size==lim){
                erase(get_pos(0));
                --size;
            }
            m1[x]=tail;
            m2[tail]=x;
            ll tmp=seg.query(tail,tail+1);
            seg.add(tail,tail+1,-tmp);
            seg.add(tail,tail+1,size);
            ++tail;
            ++size;
        }else if(query==1){
            erase(get_pos(x-1));
            --size;
        }else if(query==2) cout << m2[get_pos(x-1)] << endl;
        else{
            erase(m1[x]);
            --size;
        }
    }
    cout << "end" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    while(true){
        int q,lim;
        cin >> q >> lim;
        if(q==0 and lim==0) break;
        solve(q,lim);
    }
    return 0;
}

Compiler output:
a.cc:13:1: error: 's' does not name a type
   13 | s
      | ^
a.cc: In member function 'T segtree<T>::query(int, int, int, int, int)':
a.cc:59:48: error: 'll' was not declared in this scope; did you mean 'l'?
   59 |         if(b<=l or r<=a) return numeric_limits<ll>::min();
      |                                                ^~
      |                                                l
a.cc:59:50: error: template argument 1 is invalid
   59 |         if(b<=l or r<=a) return numeric_limits<ll>::min();
      |                                                  ^
a.cc: In function 'void solve(int, int)':
a.cc:68:13: error: 'll' was not declared in this scope
   68 |     segtree<ll> seg(q,numeric_limits<int>::min());
      |             ^~
a.cc:68:15: error: template argument 1 is invalid
   68 |     segtree<ll> seg(q,numeric_limits<int>::min());
      |               ^
a.cc:68:49: error: expression list treated as compound expression in initializer [-fpermissive]
   68 |     segtree<ll> seg(q,numeric_limits<int>::min());
      |                                                 ^
a.cc: In lambda function:
a.cc:75:20: error: request for member 'query' in 'seg', which is of non-class type 'int'
   75 |             if(seg.query(0,m+1)>=x) ub=m;
      |                    ^~~~~
a.cc: In lambda function:
a.cc:82:13: error: request for member 'add' in 'seg', which is of non-class type 'int'
   82 |         seg.add(k,k+1,numeric_limits<int>::min());
      |             ^~~
a.cc:83:13: error: request for member 'add' in 'seg', which is of non-class type 'int'
   83 |         seg.add(k+1,q,-1);
      |             ^~~
a.cc: In function 'void solve(int, int)':
a.cc:96:15: error: expected ';' before 'tmp'
   96 |             ll tmp=seg.query(tail,tail+1);
      |               ^~~~
      |               ;
a.cc:97:17: error: request for member 'add' in 'seg', which is of non-class type 'int'
   97 |             seg.add(tail,tail+1,-tmp);
      |                 ^~~
a.cc:97:34: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   97 |             seg.add(tail,tail+1,-tmp);
      |                                  ^~~
      |                                  tm
a.cc:98:17: error: request for member 'add' in 'seg', which is of non-class type 'int'
   98 |             seg.add(tail,tail+1,size);
      |                 ^~~