Submission #90819

# Submission time Handle Problem Language Result Execution time Memory
90819 2018-12-24T15:04:45 Z EntityIT Cake (CEOI14_cake) C++14
0 / 100
382 ms 7440 KB
#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define fi first
#define se second
typedef pair<int, int> ii;

const int N = 250005, inf = 1e9 + 123;
int n, start, q, cur;
ii pos[11];
vector<int> a[2];

struct It {
    int node[N << 2];
    void build_tree (bool _, int nd, int Left, int Right) {
        if (Left == Right) {
            node[nd] = a[_][Left];
            return ;
        }
        int mid = Left + Right >> 1;
        build_tree(_, nd << 1, Left, mid); build_tree(_, nd << 1 | 1, mid + 1, Right);
        node[nd] = max(node[nd << 1], node[nd << 1 | 1]);
    }
    void update (int nd, int Left, int Right, int pos, int val) {
        if (pos < Left || Right < pos) return ;
        if (Left == Right) { node[nd] = val; return ; }
        int mid = Left + Right >> 1;
        update(nd << 1, Left, mid, pos, val); update(nd << 1 | 1, mid + 1, Right, pos, val);
        node[nd] = max(node[nd << 1], node[nd << 1 | 1]);
    }
    int get (int nd, int Left, int Right, int l, int r) {
//        cout << "l = " << l << "  r = " << r << '\n';
        if (Right < l || r < Left) return 0;
        if (l <= Left && Right <= r) return node[nd];
        int mid = Left + Right >> 1;
        return max(get(nd << 1, Left, mid, l, r), get(nd << 1 | 1, mid + 1, Right, l, r) );
    }
    int getPos (int nd, int Left, int Right, int val) {
        if (Left == Right) return Left;
        int mid = Left + Right >> 1;
        if (node[nd << 1] > val) return getPos(nd << 1, Left, mid, val);
        else return getPos(nd << 1 | 1, mid + 1, Right, val);
    }
} it[2];

ii getRealPos (int b) {
    if (b == start) return ii(-1, -1);
    if (b > start) return ii(1, b - start - 1);
    return ii(0, start - b - 1);
}

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen("cake.in", "r", stdin);
    cin >> n >> start; cur = n;
    for (int i = 1; i <= n; ++i) {
        int inp; cin >> inp;
        if (n - inp + 1 <= 10) pos[n - inp + 1] = getRealPos(i);
        if (i < start) a[0].pb(inp);
        else if (i > start) a[1].pb(inp);
    }
    reverse(a[0].begin(), a[0].end() );
    a[0].pb(inf);
    a[1].pb(inf);

//    for (auto _ : a[0]) cout << _ << ' '; cout << '\n';
//    for (auto _ : a[1]) cout << _ << ' '; cout << '\n';
//    for (int i = 1; i <= min(10, n); ++i) cout << pos[i].fi << '-' << pos[i].se << ' '; cout << '\n';

    it[0].build_tree(0, 1, 0, (int)a[0].size() - 1);
    it[1].build_tree(1, 1, 0, (int)a[1].size() - 1);

    cin >> q;

    while (q --) {
        char c; int b; cin >> c >> b;
        ii realPos = getRealPos(b);
        if (c == 'F') {
            if (realPos == ii(-1, -1) ) cout << "0\n";
            else cout << realPos.se + it[realPos.fi ^ 1].getPos(1, 0, (int)a[realPos.fi].size() - 1, it[realPos.fi].get(1, 0, (int)a[realPos.fi].size() - 1, 0, realPos.se) ) + 1 << '\n';
        }
        else {
            int e; cin >> e;
            for (int i = 10; i > e; --i) pos[i] = pos[i - 1];
            pos[e] = realPos;
            for (int i = e; i > 0; --i) {
                cur ++;
                if (pos[i].fi == -1) continue ;
                it[ pos[i].fi ].update(1, 0, (int)a[ pos[i].fi ].size() - 1, pos[i].se, cur);
            }
        }
    }

    return 0;
}

Compilation message

cake.cpp: In member function 'void It::build_tree(bool, int, int, int)':
cake.cpp:22:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = Left + Right >> 1;
                   ~~~~~^~~~~~~
cake.cpp: In member function 'void It::update(int, int, int, int, int)':
cake.cpp:29:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = Left + Right >> 1;
                   ~~~~~^~~~~~~
cake.cpp: In member function 'int It::get(int, int, int, int, int)':
cake.cpp:37:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = Left + Right >> 1;
                   ~~~~~^~~~~~~
cake.cpp: In member function 'int It::getPos(int, int, int, int)':
cake.cpp:42:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = Left + Right >> 1;
                   ~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 198 ms 1536 KB Output isn't correct
2 Incorrect 107 ms 1536 KB Output isn't correct
3 Incorrect 151 ms 1536 KB Output isn't correct
4 Incorrect 106 ms 1672 KB Output isn't correct
5 Incorrect 208 ms 1800 KB Output isn't correct
6 Incorrect 160 ms 1824 KB Output isn't correct
7 Incorrect 167 ms 1824 KB Output isn't correct
8 Incorrect 111 ms 1824 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 3548 KB Output isn't correct
2 Incorrect 48 ms 3548 KB Output isn't correct
3 Incorrect 40 ms 3548 KB Output isn't correct
4 Incorrect 2 ms 3548 KB Output isn't correct
5 Incorrect 75 ms 5332 KB Output isn't correct
6 Incorrect 70 ms 5332 KB Output isn't correct
7 Incorrect 58 ms 5332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 5332 KB Output isn't correct
2 Incorrect 20 ms 5332 KB Output isn't correct
3 Incorrect 39 ms 5332 KB Output isn't correct
4 Incorrect 48 ms 5332 KB Output isn't correct
5 Incorrect 67 ms 5332 KB Output isn't correct
6 Incorrect 74 ms 5332 KB Output isn't correct
7 Incorrect 76 ms 5332 KB Output isn't correct
8 Incorrect 88 ms 5332 KB Output isn't correct
9 Incorrect 382 ms 6252 KB Output isn't correct
10 Incorrect 213 ms 6252 KB Output isn't correct
11 Incorrect 260 ms 6252 KB Output isn't correct
12 Incorrect 356 ms 6252 KB Output isn't correct
13 Incorrect 291 ms 7440 KB Output isn't correct