답안 #872029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872029 2023-11-12T06:48:15 Z vjudge1 Deda (COCI17_deda) C++17
140 / 140
118 ms 2136 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 200'000 + 7, SQ = 460;
int n, q, s[N], mn[SQ + 7];

void read_input() {
    cin >> n >> q;
}

void pre_process() {
    fill(s, s + N, 1e9 + 1);
    fill(mn, mn + SQ + 7, 1e9 + 1);
}

void change(int x, int a) {
    s[a] = x;
    mn[a / SQ] = min(mn[a / SQ], x);
}

int get(int y, int b) {
    for (int i = b; i < n && (i / SQ) <= (b / SQ); i++)
        if (s[i] <= y)
            return i;

    for (int i = b / SQ + 1; i * SQ < n; i++)
        if (mn[i] <= y) {
            for (int j = i * SQ; j < n && j < (i + 1) * SQ; j++)
                if (s[j] <= y)
                    return j;
            assert(false);
        }
    
    return -1;
}

void solve() {
    while (q--) {
        char c;
        int x, y;
        cin >> c >> x >> y;

        if (c == 'M') {
            change(x, y - 1);
        } else if (c == 'D') {
            int t = get(x, y - 1);
            cout << (t == -1 ? -1 : t + 1) << '\n';
        } else {
            assert(false);
        }
    }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    read_input();
    pre_process();
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 118 ms 2132 KB Output is correct
5 Correct 55 ms 1876 KB Output is correct
6 Correct 65 ms 2008 KB Output is correct
7 Correct 71 ms 2136 KB Output is correct