Submission #992043

# Submission time Handle Problem Language Result Execution time Memory
992043 2024-06-03T16:59:04 Z NoLove Deda (COCI17_deda) C++14
80 / 140
214 ms 65536 KB
/**
 *    author : Lăng Trọng Đạt
 *    created: 03-06-2024 
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i++))
#define si(x) (int)(x.size())
void inline mx(int& a, int b) { if (b > a) a = b; }
void inline mi(int& a, int b) { if (b < a) a = b; }
using pii = pair<int, int>;
const int INF = 1e18;

bool start;
const int MAXN = 1e6 + 5;
int g[MAXN];
int n;
set<int> bit[MAXN];

vector<int> pos;
int id(int p) {
    return upper_bound(all(pos), p) - pos.begin();
}
int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    if (fopen("hi.inp", "r")) {
        freopen("hi.inp", "r", stdin);
        freopen("./deda/deda.in.7", "r", stdin);
       freopen("hi.out", "w", stdout);
    } 

    int n, m, a, b;
    cin >> n >> m;
    char type;
    map<int, int> vals;
    vector<array<int, 3>> events;
    FOR(i, 1, m) {
        // a is rope, b is age
        cin >> type >> a >> b;
        events.pb({a, b, type == 'D'});
        pos.pb(a);
    }
    sort(all(pos));
    pos.resize(unique(all(pos)) - pos.begin());

    for (auto[a, b, t] : events) {
        if (t) {
            int ans = INF;
            for (int p = id(a); p > 0; p -= p & -p) {
                auto it = bit[p].lower_bound(b);
                if (it != bit[p].end())
                    mi(ans, *it);
            } 
            cout << (ans == INF ? -1 : ans) << "\n";
        } else {
            for (int p = id(a); p <= si(pos); p += p & -p) {
                bit[p].insert(b);
            }
        }
    }
}

Compilation message

deda.cpp:20:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   20 | const int INF = 1e18;
      |                 ^~~~
deda.cpp: In function 'int32_t main()':
deda.cpp:15:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i++))
      |                               ^
deda.cpp:45:5: note: in expansion of macro 'FOR'
   45 |     FOR(i, 1, m) {
      |     ^~~
deda.cpp:54:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |     for (auto[a, b, t] : events) {
      |              ^
deda.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen("hi.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
deda.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen("./deda/deda.in.7", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
deda.cpp:37:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |        freopen("hi.out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 47704 KB Output is correct
2 Correct 7 ms 47748 KB Output is correct
3 Correct 10 ms 48220 KB Output is correct
4 Correct 100 ms 53244 KB Output is correct
5 Runtime error 165 ms 65536 KB Execution killed with signal 9
6 Runtime error 202 ms 65536 KB Execution killed with signal 9
7 Runtime error 214 ms 65536 KB Execution killed with signal 9