답안 #920177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920177 2024-02-02T07:47:49 Z vjudge1 Deda (COCI17_deda) C++17
140 / 140
130 ms 7748 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O2")

#define int long long
#define vb vector<bool>
#define vvb vector<vb>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpi vector<pii>
#define vvpi vector<vpi>
#define fi first
#define se second
#define F(i, s, e) for (int i = s; i < e; i++)
#define endl '\n'
#define sp << ' ' <<
#define pb push_back

const int MOD = 1e9 + 7;
const int inf = 1e16;

const int N = 2e5 + 7;
int t[4*N];
int a[N];

void build(int node, int l, int r) {
    if(l == r) {
        t[node] = a[l];
        return;
    }
    int m = (l + r) >> 1;
    build(node*2+1, l, m);
    build(node*2+2, m+1, r);

    t[node] = min(t[node*2+1], t[node*2+2]);
}

void update(int node, int l, int r, int i, int v) {
    if(l > i || r < i) return;
    if(l == r) {
        t[node] = v;
        return;
    }

    int m = (l + r) >> 1;
    update(node*2+1, l, m, i, v);
    update(node*2+2, m+1, r, i, v);

    t[node] = min(t[node*2+1], t[node*2+2]);
}

int walk(int node, int l, int r, int L, int R, int v) {
    if(l > R || r < L) return inf;
    int m = (l + r) >> 1;
    if(l == r) {
        if(t[node] <= v) return l;
        return inf;
    } 
    if(l >= L && r <= R) {
        if(t[node*2+1] <= v) return walk(node*2+1, l, m, L, R, v);
        if(t[node*2+2] <= v) return walk(node*2+2, m+1, r, L, R, v);
        return inf;
    }

    return min(walk(node*2+1, l, m, L, R, v), walk(node*2+2, m+1, r, L, R, v));
}

void solve()
{
    int n, q;
    cin >> n >> q;
    F(i, 0, n+1) a[i] = inf;

    build(0, 1, n);

    string s;
    int x, y;
    
    F(i, 0, q) {
        cin >> s >> x >> y;
        if(s[0] == 'D') {
            int res = walk(0, 1, n, y, n, x);
            if(res == inf) cout << -1 << endl;
            else cout << res << endl;
        } else {
            //cout << "updating" << endl;
            update(0, 1, n, y, x);
        }
    }
}

void setIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef Local
        freopen("local.in", "r", stdin);
        freopen("local.out", "w", stdout);
    #endif
}

int32_t main()
{
    setIO();
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 108 ms 7644 KB Output is correct
5 Correct 111 ms 5456 KB Output is correct
6 Correct 120 ms 7504 KB Output is correct
7 Correct 130 ms 7748 KB Output is correct