답안 #200901

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200901 2020-02-08T13:15:12 Z SamAnd Deda (COCI17_deda) C++17
140 / 140
861 ms 52200 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];

int z;
vector<int> v;
map<int, int> mp;

set<int> t[N];

void ubd(int x, int y)
{
    while (x <= z)
    {
        t[x].insert(y);
        x += (x & (-x));
    }
}

int qry(int x, int y)
{
    int ans = INF;
    set<int>::iterator it;
    while (x)
    {
        it = t[x].lower_bound(y);
        if (it != t[x].end())
            ans = min(ans, (*it));
        x -= (x & (-x));
    }
    return ans;
}

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);
    }
    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(b[i].x, b[i].a);
        }
        else
        {
            int ans = qry(b[i].x, b[i].a);
            if (ans == INF)
                printf("-1\n");
            else
                printf("%d\n", ans);
        }
    }
    return 0;
}

Compilation message

deda.cpp: In function 'int main()':
deda.cpp:52:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
deda.cpp:44: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:47: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 11 ms 9720 KB Output is correct
2 Correct 11 ms 9720 KB Output is correct
3 Correct 16 ms 10232 KB Output is correct
4 Correct 292 ms 21608 KB Output is correct
5 Correct 861 ms 52200 KB Output is correct
6 Correct 727 ms 45288 KB Output is correct
7 Correct 650 ms 41324 KB Output is correct