Submission #545388

# Submission time Handle Problem Language Result Execution time Memory
545388 2022-04-04T12:21:00 Z noedit Deda (COCI17_deda) C++17
120 / 140
1000 ms 3960 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 << '\n';
            else
                cout << r + 1 << '\n';
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 8 ms 340 KB Output is correct
4 Execution timed out 1079 ms 3960 KB Time limit exceeded
5 Correct 653 ms 2176 KB Output is correct
6 Correct 822 ms 3212 KB Output is correct
7 Correct 936 ms 3368 KB Output is correct