답안 #200900

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200900 2020-02-08T13:08:23 Z SamAnd Deda (COCI17_deda) C++17
80 / 140
496 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 200005, INF = 1000000009;
struct ban
{
    char ty;
    int x, a;
};

int n, q;
ban b[N];

set<int> t[N * 4];

void ubd(int tl, int tr, int x, int y, int pos)
{
    t[pos].insert(y);
    if (tl == tr)
        return;
    int m = (tl + tr) / 2;
    if (x <= m)
        ubd(tl, m, x, y, pos * 2);
    else
        ubd(m + 1, tr, x, y, pos * 2 + 1);
}

int qry(int tl, int tr, int l, int r, int y, int pos)
{
    if (l > r)
        return INF;
    if (tl == l && tr == r)
    {
        set<int>::iterator it = t[pos].lower_bound(y);
        if (it != t[pos].end())
            return (*it);
        return INF;
    }
    int m = (tl + tr) / 2;
    return min(qry(tl, m, l, min(m, r), y, pos * 2),
               qry(m + 1, tr, max(m + 1, l), r, y, pos * 2 + 1));
}

int main()
{
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= q; ++i)
    {
        scanf(" %c%d%d", &b[i].ty, &b[i].x, &b[i].a);
    }
    int z = 0;
    vector<int> v;
    map<int, int> mp;
    for (int i = 1; i <= q; ++i)
        v.push_back(b[i].x);
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); ++i)
    {
        if (!i || v[i] != v[i - 1])
            mp[v[i]] = ++z;
    }
    for (int i = 1; i <= q; ++i)
    {
        b[i].x = mp[b[i].x];
    }
    for (int i = 1; i <= q; ++i)
    {
        if (b[i].ty == 'M')
        {
            ubd(1, z, b[i].x, b[i].a, 1);
        }
        else
        {
            int ans = qry(1, z, 1, b[i].x, b[i].a, 1);
            if (ans == INF)
                printf("-1\n");
            else
                printf("%d\n", ans);
        }
    }
    return 0;
}

Compilation message

deda.cpp: In function 'int main()':
deda.cpp:56:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
deda.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~
deda.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c%d%d", &b[i].ty, &b[i].x, &b[i].a);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 37880 KB Output is correct
2 Correct 30 ms 38008 KB Output is correct
3 Correct 36 ms 38776 KB Output is correct
4 Correct 373 ms 53356 KB Output is correct
5 Runtime error 469 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 463 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 496 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)