답안 #545379

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545379 2022-04-04T12:07:46 Z noedit Deda (COCI17_deda) C++17
100 / 140
1000 ms 6872 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//#define int long long
typedef long long ll;

const int MAXN = 2e5;
const int INF = 2e9;

int t[4 * MAXN];

void build(int v, int tl, int tr)
{
    if (tl == tr)
    {
        t[v] = INF;
    }
    else
    {
        int tm = (tl + tr) >> 1;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = min(t[v * 2], t[v * 2 + 1]);
    }
}

void update(int v, int tl, int tr, int p, int x)
{
    if (tl == tr)
    {
        t[v] = x;
        return;
    }
    int tm = (tl + tr) >> 1;
    if (p <= tm)
        update(v * 2, tl, tm, p, x);
    else
        update(v * 2 + 1, tm + 1, tr, p, x);
    t[v] = min(t[v * 2], t[v * 2 + 1]);
}

int get(int v, int tl, int tr, int l, int r)
{
    if (l > r || l < tl || tr < r) return INF;
    if (tl == l && tr == r)
    {
        return t[v];
    }
    int tm = (tl + tr) >> 1;
    int ql = get(v * 2, tl, tm, l, min(r, tm));
    int qr = get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
    return min(ql, qr);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    build(1, 0, n - 1);
    while (q--)
    {
        char c;
        cin >> c;
        if (c == 'M')
        {
            int x, a;
            cin >> x >> a;
            a--;
            update(1, 0, n - 1, a, x);
        }
        else
        {
            int y, b;
            cin >> y >> b;
            b--;
            int l = b - 1, r = n - 1;
            while (r - l > 1)
            {
                int mid = (l + r) >> 1;
                if (get(1, 0, n - 1, b, mid) <= y)
                {
                    r = mid;
                }
                else
                {
                    l = mid;
                }
            }
            if (get(1, 0, n - 1, b, r) > y)
                cout << -1 << endl;
            else
                cout << r + 1 << endl;
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 13 ms 400 KB Output is correct
4 Execution timed out 1086 ms 6336 KB Time limit exceeded
5 Correct 807 ms 5300 KB Output is correct
6 Correct 914 ms 6756 KB Output is correct
7 Execution timed out 1066 ms 6872 KB Time limit exceeded