답안 #101536

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
101536 2019-03-19T03:48:51 Z shenxy 케이크 (CEOI14_cake) C++11
0 / 100
2000 ms 40156 KB
#include <cstdio>
#include <algorithm>
#include <queue>
#include <utility>
#define int long long
using namespace std;
typedef pair<int, int> ii;
struct segnode {
    int first, last, middle, maxval;
    segnode *l, *r;
    segnode(int s, int e) {
        first = s;
        last = e;
        middle = (first + last) / 2;
        maxval = 0;
        if (first != last) {
            l = new segnode(first, middle);
            r = new segnode(middle + 1, last);
        }
    }
    void point_update(int i, int x) {
        if (first == last) {
            maxval = x;
            return;
        }
        if (i > middle) r -> point_update(i, x);
        else l -> point_update(i, x);
        maxval = max(l -> maxval, r -> maxval);
    }
    int rangemaxq(int a, int b) {
        if (first == a && last == b) return maxval;
        if (a > middle) return r -> rangemaxq(a, b);
        if (b <= middle) return l -> rangemaxq(a, b);
        return max(l -> rangemaxq(a, middle), r -> rangemaxq(middle + 1, b));
    }
} *root;
main() {
    //freopen("cakein.txt", "r", stdin);
    int N, a, nextint;
    scanf("%lld %lld", &N, &a);
    root = new segnode(1, N);
    priority_queue<ii> topten;
    for (int i = 1; i <= N; i++) {
        scanf("%lld", &nextint);
        if (i != a) {
            root -> point_update(i, nextint);
            topten.push(ii(nextint, i));
        }
    }
    int realtop[10];
    for (int i = 0; i < 10; i++) {
        realtop[i] = topten.top().second;
        topten.pop();
    }
    int Q, id, b;
    char c;
    scanf("%d", &Q);
    for (int i = 0; i < Q; i++) {
        scanf(" %c", &c);
        if (c == 'E') {
            scanf("%lld %lld", &id, &b);
            for (int j = 0; j < b - 1; j++) root -> point_update(realtop[j], root -> rangemaxq(realtop[j], realtop[j]) + 1);
            for (int j = b; j < 10; j++) realtop[j] = realtop[j - 1];
            realtop[b - 1] = id;
            if (b != 10) root -> point_update(id, root -> rangemaxq(realtop[b], realtop[b]) + 1);
            else root -> point_update(id, root -> rangemaxq(realtop[b - 2], realtop[b - 2]) - 1);
        } else {
            scanf("%lld", &id);
            if (id == a) {
                printf("0\n");
                continue;
            } else if (id > a) {
                int bstaval = root -> rangemaxq(a + 1, id);
                int lower = 1, upper = a - 1;
                while (lower != upper) {
                    int midval = (lower + upper) / 2;
                    if (root -> rangemaxq(a - midval, a - 1) < bstaval) lower = midval + 1;
                    else upper = midval;
                }
                if (root -> rangemaxq(1, a - 1) < bstaval) lower = a;
                printf("%lld\n", lower - 1 + id - a);
            } else {
                int bstaval = root -> rangemaxq(id, a - 1);
                int lower = 1, upper = N - a;
                while (lower != upper) {
                    int midval = (lower + upper) / 2;
                    if (root -> rangemaxq(a + 1, a + midval) < bstaval) lower = midval + 1;
                    else upper = midval;
                }
                if (root -> rangemaxq(a + 1, N) < bstaval) lower = N - a + 1;
                printf("%lld\n", lower - 1 + a - id);
            }
        }
    }
    return 0;
}

Compilation message

cake.cpp:37:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
cake.cpp: In function 'int main()':
cake.cpp:57:19: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
     scanf("%d", &Q);
                 ~~^
cake.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld", &N, &a);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
cake.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &nextint);
         ~~~~~^~~~~~~~~~~~~~~~~~
cake.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &Q);
     ~~~~~^~~~~~~~~~
cake.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c", &c);
         ~~~~~^~~~~~~~~~~
cake.cpp:61:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld %lld", &id, &b);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
cake.cpp:68:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld", &id);
             ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2025 ms 3840 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2005 ms 1792 KB Time limit exceeded
2 Execution timed out 2035 ms 1920 KB Time limit exceeded
3 Execution timed out 2036 ms 1920 KB Time limit exceeded
4 Execution timed out 2012 ms 1996 KB Time limit exceeded
5 Execution timed out 2012 ms 4092 KB Time limit exceeded
6 Execution timed out 2099 ms 4096 KB Time limit exceeded
7 Execution timed out 2048 ms 4096 KB Time limit exceeded
8 Execution timed out 2035 ms 4096 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2017 ms 18108 KB Time limit exceeded
2 Execution timed out 2047 ms 16560 KB Time limit exceeded
3 Execution timed out 2009 ms 17060 KB Time limit exceeded
4 Execution timed out 2050 ms 3956 KB Time limit exceeded
5 Execution timed out 2041 ms 39184 KB Time limit exceeded
6 Execution timed out 2082 ms 39440 KB Time limit exceeded
7 Execution timed out 2060 ms 40156 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2029 ms 5056 KB Time limit exceeded
2 Execution timed out 2021 ms 1272 KB Time limit exceeded
3 Execution timed out 2024 ms 11144 KB Time limit exceeded
4 Execution timed out 2052 ms 7796 KB Time limit exceeded
5 Execution timed out 2059 ms 1016 KB Time limit exceeded
6 Execution timed out 2025 ms 10172 KB Time limit exceeded
7 Execution timed out 2036 ms 2548 KB Time limit exceeded
8 Execution timed out 2057 ms 14960 KB Time limit exceeded
9 Execution timed out 2035 ms 37536 KB Time limit exceeded
10 Execution timed out 2027 ms 6208 KB Time limit exceeded
11 Execution timed out 2025 ms 8824 KB Time limit exceeded
12 Execution timed out 2041 ms 31656 KB Time limit exceeded
13 Execution timed out 2023 ms 37516 KB Time limit exceeded