답안 #222948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
222948 2020-04-14T11:55:39 Z ngot23 Deda (COCI17_deda) C++11
60 / 140
1000 ms 3900 KB
#include <bits/stdc++.h>

using namespace std;
const int N=200005;
int t[N*4], n, Q;

void update(int l, int r, int id, int u, int val) {
    if(u<l || u>r) return;
    if(l==r) {t[id]=val;return;}
    int mid=(r+l)>>1;
    update(l, mid, id*2, u, val);
    update(mid+1, r, id*2+1, u, val);
    t[id]=min(t[id*2], t[id*2+1]);
}

int get(int l, int r, int id, int u, int val) {
    if(r<u) return -1;
    if(l==r) {
        if(t[id]<=val) return l;
        return -1;
    }

    int mid = (r+l)>>1;
    if(u<=mid) {
        int x=get(l, mid, id*2, u, val);
        if(x!=-1) return x;
        int y=get(mid+1, r, id*2+1, u, val);
        if(y!=-1) return y;
    } else {
        int x=get(mid+1, r, id*2+1, u, val);
        return x;
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(fopen(".inp", "r")) freopen(".inp", "r", stdin);
    cin >> n >> Q;
    for(int i=0 ; i<=n*4 ; ++i) t[i]=1e9+1;
    for(int i=1 ; i<=Q ; ++i) {
        int c, d; char x;
        cin >> x >> c >> d;
        if(x=='M') {
            update(1, n, 1, d, c);
        } else {
            int id=get(1, n, 1, d, c);
            cout << id << '\n';
        }
    }


    return 0;
}

Compilation message

deda.cpp: In function 'int get(int, int, int, int, int)':
deda.cpp:33:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
deda.cpp: In function 'int main()':
deda.cpp:37:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     if(fopen(".inp", "r")) freopen(".inp", "r", stdin);
                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 10 ms 512 KB Output is correct
4 Execution timed out 1087 ms 3576 KB Time limit exceeded
5 Execution timed out 1092 ms 2680 KB Time limit exceeded
6 Execution timed out 1093 ms 3392 KB Time limit exceeded
7 Execution timed out 1093 ms 3900 KB Time limit exceeded