답안 #834293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834293 2023-08-22T12:41:01 Z serifefedartar Deda (COCI17_deda) C++17
60 / 140
1000 ms 6520 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 200005

const int INF = 2000000000;
int sg[4*MAXN];
void update(int k, int a, int b, int plc, int val) {
    if (b < plc || a > plc)
        return ;
    if (a == b) {
        sg[k] = val;
        return ;
    }
    update(2*k, a, (a+b)/2, plc, val);
    update(2*k+1, (a+b)/2+1, b, plc, val);
    sg[k] = min(sg[2*k], sg[2*k+1]);
}

int query(int k, int a, int b, int q_l, int q_r, int mx_stops) {
    if (b < q_l || a > q_r || sg[k] == INF || sg[k] > mx_stops)
        return INF;
    if (a == b)
        return a;        
    int leftQ = query(2*k, a, (a+b)/2, q_l, q_r, mx_stops);
    int rightQ = query(2*k+1, (a+b)/2+1, b, q_l, q_r, mx_stops);

    if (leftQ != INF)
        return leftQ;
    if (rightQ != INF)
        return rightQ;
    return INF;
}

int main() {
	fast
    int N, Q;
    cin >> N >> Q;
    
    for (int i = 0; i < MAXN; i++)
        sg[i] = INF;
    while (Q--) {
        char ch;
        cin >> ch;
        if (ch == 'M') {
            int plc, val;
            cin >> val >> plc;
            update(1, 1, N, plc, val);
        } else {
            int stops, mn;
            cin >> stops >> mn;
            int q = query(1, 1, N, mn, N, stops);
            if (q == INF)
                cout << -1 << "\n";
            else
                cout << q << "\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 6 ms 1108 KB Output is correct
4 Execution timed out 1067 ms 6520 KB Time limit exceeded
5 Execution timed out 1072 ms 2044 KB Time limit exceeded
6 Execution timed out 1084 ms 3008 KB Time limit exceeded
7 Execution timed out 1083 ms 3044 KB Time limit exceeded