답안 #257749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257749 2020-08-04T17:09:08 Z doowey 케이크 (CEOI14_cake) C++14
0 / 100
11 ms 1408 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 250010;

int A[N];

int tree[N * 2 + 512];

int lim;
void setid(int x, int v){
    x += lim;
    tree[x] = v;
    x /= 2;
    while(x > 0){
        tree[x] = max(tree[x * 2], tree[x * 2 + 1]);
        x /= 2;
    }
}

int ask(int l, int r){
    int ans = 0;
    l += lim;
    r += lim;
    while(l <= r){
        if(l % 2 == 1) ans = max(ans, tree[l ++ ]);
        if(r % 2 == 0) ans = max(ans, tree[r -- ]);
        l /= 2;
        r /= 2;
    }
    return ans;
}

int main(){
    fastIO;
    int n, st;
    cin >> n >> st;
    vector<int> top(10);
    lim = n + 2;
    for(int i = 1; i <= n; i ++ ){
        cin >> A[i];
        if(n - A[i] > 0){
            top[n-A[i]] = i;
        }
        setid(i, A[i]);
    }
    int q;
    cin >> q;
    int nx;
    int res;
    char typ;
    int mx;
    int ly;
    int li;
    int nw = n;
    int sz;
    int pp;
    for(int i = 1; i <= q; i ++ ){
        cin >> typ;
        if(typ == 'F'){
            cin >> nx;
            res = 1;
            if(nx > st){
                res += nx - st;
                mx = ask(st + 1, nx);
                ly = st;
                for(int lg = 19; lg >= 0; lg -- ){
                    li = ly - (1 << lg);
                    if(li <= 0) continue;
                    if(ask(li, st - 1) < mx){
                        ly = li;
                    }
                }
                res += st - ly;
            }
            else if(nx < st){
                res += st - nx;
                mx = ask(nx, st - 1);
                ly = st;
                for(int lg = 19; lg >= 0 ; lg -- ){
                    li = ly + (1 << lg);
                    if(li > n) continue;
                    if(ask(st + 1, li) < mx){
                        ly = li;
                    }
                }
                res += ly - st;
            }
            cout << res - 1 << "\n";
        }
        else{
            cin >> nx >> mx;
            mx -- ;
            vector<int> niw;
            bool ok = false;
            for(int j = 0; j < 10 ; j ++ ){
                if(top[j] == nx && j == mx){
                    ok = true;
                }
            }
            if(ok) continue; // nothing changes
            nw += 10;
            for(int j = 0 ; j < 10; j ++ ){
                if(top[j] == nx) continue;
                if(j == mx){
                    sz = niw.size();
                    pp = nw - sz;
                    setid(nx, pp);
                    niw.push_back(nx);
                }
                else{
                    sz = niw.size();
                    pp = nw - sz;
                    setid(top[j], pp);
                    niw.push_back(top[j]);
                }
            }
            top = niw;
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 4 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 4 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 5 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 7 ms 1408 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 8 ms 1408 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 11 ms 1408 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 9 ms 1408 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Correct 0 ms 384 KB Output is correct
5 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 3 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 4 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 4 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 3 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 6 ms 1280 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)