Submission #101666

# Submission time Handle Problem Language Result Execution time Memory
101666 2019-03-19T07:56:58 Z rocketninja7 Cake (CEOI14_cake) C++14
0 / 100
1533 ms 29312 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

struct node{
    int s, e, m, v;
    node *l, *r;
    node(int _s, int _e): s(_s), e(_e), m((_s+_e)/2), v(0){
        if(s<e){
            l=new node(s, m);
            r=new node(m+1, e);
        }
    }
    void update(int i, int val){
        if(s==i&&e==i){
            v=val;
        }
        else{
            if(i<=m){
                l->update(i, val);
            }
            else{
                r->update(i, val);
            }
            v=max(l->v, r->v);
        }
    }
    int query(int si, int ei){
        if(s==si&&e==ei){
            return v;
        }
        if(ei<=m){
            return l->query(si, ei);
        }
        if(si>m){
            return r->query(si, ei);
        }
        return max(l->query(si, m), r->query(m+1, ei));
    }
};

int main(){
    int N, a;
    scanf("%d%d", &N, &a);
    node *root=new node(1, N);
    int d[N+1];
    vector<pair<int, int> > best;
    for(int i=1;i<N+1;i++){
        scanf("%d", &d[i]);
        best.push_back(make_pair(-d[i], i));
        root->update(i, d[i]);
    }
    sort(best.begin(), best.end());
    while(best.size()>10){
        best.pop_back();
    }
    int Q;
    scanf("%d", &Q);
    while(Q--){
        char op;
        scanf("\n%c", &op);
        if(op=='E'){
            int i, e;
            scanf("%d%d", &i, &e);
            if(N==1){
                continue;
            }
            int tempE=e;
            e--;
            for(int j=0;j<best.size();j++){
                if(best[j].second==i){
                    best.erase(best.begin()+j);
                }
            }
            int j=0;
            while(e--){
                --best[j].first;
                root->update(best[j].second, ++d[best[j].second]);
                j++;
            }
            if(tempE>1){
                d[i]=d[best[j-1].second]-1;
            }
            else{
                d[i]=d[best[j].second]+1;
            }
            root->update(i, d[i]);
            best.insert(best.begin()+tempE-1, make_pair(-d[i], i));
            if(best.size()>10){
                best.erase(--best.end());
            }
        }
        else{
            int b;
            scanf("%d", &b);
            if(b==a){
                printf("0\n");
                continue;
            }
            if(b<a){
                int left=root->query(b, a);
                int s=a, e=N+1;
                while(s<e-1){
                    int m=(s+e)/2;
                    if(root->query(a, m)<left){
                        s=m;
                    }
                    else{
                        e=m;
                    }
                }
                //printf("1. %d, %d\n", b, s);
                printf("%d\n", s-b);
            }
            else{
                int right=root->query(a, b);
                int s=1, e=a+1;
                while(s<e-1){
                    int m=(s+e)/2;
                    if(root->query(m, a)<right){
                        e=m;
                    }
                    else{
                        s=m;
                    }
                }
                //printf("2. %d, %d\n", b, s);
                printf("%d\n", b-s);
            }
        }
    }
    return 0;
}

Compilation message

cake.cpp: In function 'int main()':
cake.cpp:71:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=0;j<best.size();j++){
                         ~^~~~~~~~~~~~
cake.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &a);
     ~~~~~^~~~~~~~~~~~~~~~
cake.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &d[i]);
         ~~~~~^~~~~~~~~~~~~
cake.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &Q);
     ~~~~~^~~~~~~~~~
cake.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("\n%c", &op);
         ~~~~~^~~~~~~~~~~~~
cake.cpp:65:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d", &i, &e);
             ~~~~~^~~~~~~~~~~~~~~~
cake.cpp:96:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &b);
             ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 392 ms 1976 KB Output isn't correct
2 Incorrect 210 ms 2296 KB Output isn't correct
3 Incorrect 279 ms 2392 KB Output isn't correct
4 Incorrect 201 ms 2396 KB Output isn't correct
5 Incorrect 391 ms 3748 KB Output isn't correct
6 Incorrect 322 ms 4056 KB Output isn't correct
7 Incorrect 334 ms 3832 KB Output isn't correct
8 Incorrect 192 ms 3960 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 351 ms 12204 KB Output isn't correct
2 Incorrect 207 ms 12000 KB Output isn't correct
3 Incorrect 199 ms 11880 KB Output isn't correct
4 Incorrect 2 ms 384 KB Output isn't correct
5 Incorrect 412 ms 27972 KB Output isn't correct
6 Incorrect 545 ms 28020 KB Output isn't correct
7 Incorrect 280 ms 27496 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 1016 KB Output isn't correct
2 Incorrect 63 ms 1280 KB Output isn't correct
3 Incorrect 212 ms 6232 KB Output isn't correct
4 Incorrect 172 ms 6260 KB Output isn't correct
5 Incorrect 136 ms 1272 KB Output isn't correct
6 Incorrect 369 ms 8292 KB Output isn't correct
7 Incorrect 193 ms 2432 KB Output isn't correct
8 Incorrect 211 ms 11372 KB Output isn't correct
9 Incorrect 1533 ms 29312 KB Output isn't correct
10 Incorrect 413 ms 2044 KB Output isn't correct
11 Incorrect 650 ms 4672 KB Output isn't correct
12 Incorrect 1323 ms 23948 KB Output isn't correct
13 Incorrect 1299 ms 29260 KB Output isn't correct