Submission #90820

# Submission time Handle Problem Language Result Execution time Memory
90820 2018-12-24T15:12:04 Z EntityIT Cake (CEOI14_cake) C++14
0 / 100
370 ms 7112 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 ^ 1].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 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 192 ms 1368 KB Output isn't correct
2 Correct 105 ms 1404 KB Output is correct
3 Correct 147 ms 1436 KB Output is correct
4 Correct 103 ms 1436 KB Output is correct
5 Incorrect 203 ms 1728 KB Output isn't correct
6 Correct 157 ms 1728 KB Output is correct
7 Correct 159 ms 1728 KB Output is correct
8 Correct 109 ms 1728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 3404 KB Output is correct
2 Correct 46 ms 3404 KB Output is correct
3 Correct 44 ms 3404 KB Output is correct
4 Incorrect 2 ms 3404 KB Output isn't correct
5 Correct 75 ms 5052 KB Output is correct
6 Incorrect 69 ms 5120 KB Output isn't correct
7 Correct 59 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 5120 KB Output isn't correct
2 Correct 20 ms 5120 KB Output is correct
3 Correct 38 ms 5120 KB Output is correct
4 Correct 49 ms 5120 KB Output is correct
5 Incorrect 65 ms 5120 KB Output isn't correct
6 Correct 70 ms 5120 KB Output is correct
7 Correct 75 ms 5120 KB Output is correct
8 Correct 87 ms 5120 KB Output is correct
9 Incorrect 361 ms 6104 KB Output isn't correct
10 Incorrect 215 ms 6104 KB Output isn't correct
11 Correct 253 ms 6104 KB Output is correct
12 Correct 370 ms 6104 KB Output is correct
13 Incorrect 286 ms 7112 KB Output isn't correct