제출 #1347195

#제출 시각아이디문제언어결과실행 시간메모리
1347195iamhereforfunDeda (COCI17_deda)C++20
140 / 140
333 ms50476 KiB

#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i++))
#define si(x) (int)(x.size())
void inline mx(int& a, int b) { if (b > a) a = b; }
void inline mi(int& a, int b) { if (b < a) a = b; }
using pii = pair<int, int>;
const int INF = 1e9;

bool start;
const int MAXN = 4e5 + 5;
int n;
set<int> bit[MAXN];

vector<int> pos;
int id(int p) {
    return upper_bound(all(pos), p) - pos.begin();
}
int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, m, a, b;
    cin >> n >> m;
    char type;
    map<int, int> vals;
    vector<array<int, 3>> events;
    FOR(i, 1, m) {
        // a is rope, b is age
        cin >> type >> a >> b;
        events.pb({a, b, type == 'D'});
        pos.pb(a);
    }
    sort(all(pos));
    pos.resize(unique(all(pos)) - pos.begin());

    for (auto[a, b, t] : events) {
        if (t) {
            int ans = INF;
            for (int p = id(a); p > 0; p -= p & -p) {
                auto it = bit[p].lower_bound(b);
                if (it != bit[p].end())
                    mi(ans, *it);
            } 
            cout << (ans == INF ? -1 : ans) << "\n";
        } else {
            for (int p = id(a); p <= si(pos); p += p & -p) {
                bit[p].insert(b);
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...