Submission #222896

# Submission time Handle Problem Language Result Execution time Memory
222896 2020-04-14T10:24:17 Z ngot23 Deda (COCI17_deda) C++11
20 / 140
161 ms 8184 KB
#include <bits/stdc++.h>

using namespace std;
#define pii pair<int, int >
#define F first
#define S second
#define mp make_pair
pair<pii, pii > a[200005];
int ans[200005];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("output.txt", "w", stdout);
    if(fopen(".inp", "r")) freopen(".inp", "r", stdin);
    int n, Q; cin >> n >> Q;
    for(int i=1 ; i<=Q ; ++i) {
        char c; cin >> c;
        int A, B; cin >> A >> B;
        if(c=='M') a[i] = mp( mp(A, 0), mp(B, 0) );
        else a[i] = mp( mp(A, 1), mp(B, i ) );

    }
    set <int > s;
    sort(a+1, a+Q+1);
    for(int i=1; i<=Q ; ++i) {
        if(a[i].F.S==0) s.insert(a[i].S.F);
        else {
            auto id = s.lower_bound(a[i].S.F);
            if(id==s.end()) ans[a[i].S.S]=-1;
            else ans[a[i].S.S]=*id;

            if(a[i].F.F==1e9) ans[a[i].S.S]=a[i].S.F;
        }
    }
    for(int i=1 ; i<=Q ; ++i) {
        if(ans[i]) cout << ans[i] << '\n';
    }
    return 0;
}

Compilation message

deda.cpp: In function 'int main()':
deda.cpp:14: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);
                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Incorrect 7 ms 512 KB Output isn't correct
4 Incorrect 105 ms 5368 KB Output isn't correct
5 Incorrect 161 ms 8184 KB Output isn't correct
6 Incorrect 130 ms 7492 KB Output isn't correct
7 Incorrect 123 ms 7160 KB Output isn't correct