답안 #646158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646158 2022-09-28T20:05:22 Z Hacv16 Deda (COCI17_deda) C++17
140 / 140
99 ms 10988 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define sc second
#define fr first
#define all(x) x.begin(), x.end()
#define sz(x) (ll) x.size()
#define dbg(x) cerr << #x << ": [ " << x << " ]\n"

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = 2e5 + 15;
const int INF = 0x3f3f3f3f;

ll n, q, seg[4 * MAX];

void update(ll i, ll x, ll p, ll l, ll r){
    if(i > r || i < l) return;
    if(l == r){
        seg[p] = x;
        return;
    }

    ll m = (l + r) >> 1, e = 2 * p, d = e + 1;
    update(i, x, e, l, m);
    update(i, x, d, m + 1, r);

    seg[p] = min(seg[e], seg[d]);
}

ll bbin(ll i, ll x, ll p, ll l, ll r){
    if(seg[p] > x) return -1;
    if(l == r) return l;

    ll m = (l + r) >> 1, e = 2 * p, d = e + 1;
    if(i > m) return bbin(i, x, d, m + 1, r);

    ll esq = bbin(i, x, e, l, m);

    if(esq == -1) return bbin(i, x, d, m + 1, r);
    return esq;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> q;

    memset(seg, INF, sizeof(seg));

    while(q--){
        char op; cin >> op;

        if(op == 'M'){
            ll x, a; cin >> x >> a;
            update(a, x, 1, 1, n);
        }else{
            ll y, b; cin >> y >> b;
            cout << bbin(b, y, 1, 1, n) << '\n';
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 5 ms 6608 KB Output is correct
4 Correct 73 ms 10988 KB Output is correct
5 Correct 85 ms 10588 KB Output is correct
6 Correct 87 ms 10772 KB Output is correct
7 Correct 99 ms 10972 KB Output is correct