Language: C++

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n;

    while (cin >> n, n) {

        vector<tuple<ll, ll, ll>> files; // (l, r, i) means [l, r) is a part of the file i
        
        REP(i, n) {

            char cmd; cin >> cmd;

            if (cmd == 'R') {

                ll p; cin >> p;
                bool found = false;
                for (auto &f : files) {
                    if (get<0>(f) <= p && p < get<1>(f)) {
                        cout << get<2>(f) << endl;
                        found = true;
                        break;
                    }
                }
                if (!found) cout << "-1" << endl;

            } else if (cmd == 'D') {

                ll i; cin >> i;
                files.erase(remove_if(ALL_OF(files), [&i](auto f) -> bool { return get<2>(f) == i; }), files.end());

            } else if (cmd == 'W') {

                ll i, s; cin >> i >> s;

                if (!files.empty()) {
                    if (get<0>(files.front()) > 0) {
                        ll gap = min(get<0>(files.front()), s);
                        s -= gap;
                        files.insert(files.begin(), {0, gap, i});
                    }
                    if (s >= 0) REP(j, files.size() - 1) {
                        ll gap = get<0>(files[j+1]) - get<1>(files[j]);
                        if (gap > 0) {
                            chmin(gap, s);
                            s -= gap;
                            ll bk = get<1>(files[i]);
                            files.emplace_back(bk, bk + gap, i);
                            if (s <= 0) break;
                        }
                    }
                }

                if (s > 0) {
                    ll bk = files.empty() ? 0 : get<1>(files.back());
                    files.emplace_back(bk, bk + s, i);
                }

                sort(ALL_OF(files));

            }

        }

        cout << endl;

    }
    
}


Compiler output:
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:5:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<std::tuple<long long int, long long int, long long int>, std::allocator<std::tuple<long long int, long long int, long long int> > >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = std::tuple<long long int, long long int, long long int>]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here
  132 |       struct _Vector_impl
      |              ^~~~~~~~~~~~