Submission #391841

# Submission time Handle Problem Language Result Execution time Memory
391841 2021-04-20T03:32:35 Z i_am_noob Cake (CEOI14_cake) C++17
25 / 100
266 ms 3900 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define pb push_back
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))

#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << " " << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T x, S ...y){cerr << x << ", ";_do(y...);}
#else
#define bug(...) 49
#endif

const int maxn=200005;

int n,x,a[maxn],q,cur;
vector<int> vec;
vector<pii> vecl,vecr;

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> x;
    x--;
    rep(n) cin >> a[i];
    rep(n) a[i]--;
    vec.resize(min(n,10ll));
    rep(n) if(a[i]>=n-10) vec[n-a[i]-1]=i;
    rep3(i,x-1,0){
        if(vecl.empty()||a[i]>vecl.back().first) vecl.pb({a[i],i});
    }
    rep2(i,x+1,n){
        if(vecr.empty()||a[i]>vecr.back().first) vecr.pb({a[i],i});
    }
    vecl.pb({inf,-1}),vecr.pb({inf,n});
    cur=n;
    cin >> q;
    while(q--){
        char op;
        cin >> op;
        if(op=='E'){
            int pos,val;
            cin >> pos >> val;
            pos--,val--;
            if(pos==x) continue;
            rep(val) a[vec[i]]++;
            a[pos]=a[vec[val]]+1;
            if(pos<x){
                vector<pii> tmp;
                for(int i=sz(vecl)-1; i>=0&&vecl[i].first>=a[pos]&&vecl[i].second!=pos; --i) vecl[i].first++;
                while(sz(vecl)&&(vecl.back().second<=pos)){
                    if(vecl.back().first>a[pos]) tmp.pb(vecl.back());
                    vecl.pop_back();
                }
                if(vecl.empty()||(vecl.back().second>pos&&vecl.back().first<a[pos])) vecl.pb({a[pos],pos});
                while(sz(tmp)) vecl.pb(tmp.back()),tmp.pop_back();


                for(int i=sz(vecr)-1; i>=0&&vecr[i].first>=a[pos]; --i) vecr[i].first++;
            }
            else{
                vector<pii> tmp;
                for(int i=sz(vecr)-1; i>=0&&vecr[i].first>=a[pos]&&vecr[i].second!=pos; --i) vecr[i].first++;
                while(sz(vecr)&&vecr.back().second>=pos){
                    if(vecr.back().first>a[pos]) tmp.pb(vecr.back());
                    vecr.pop_back();
                }
                if(vecr.empty()||(vecr.back().second<pos&&vecr.back().first<a[pos])) vecr.pb({a[pos],pos});
                while(sz(tmp)) vecr.pb(tmp.back()),tmp.pop_back();

                for(int i=sz(vecl)-1; i>=0&&vecl[i].first>=a[pos]; --i) vecl[i].first++;
            }
            cur++;
            rep(sz(vec)) if(vec[i]==pos||i==sz(vec)-1){
                vec.erase(vec.begin()+i);
                break;
            }
            vec.insert(vec.begin()+val,pos);
            for(auto i: vecl) bug(i.first,i.second);
            for(auto i: vecr) bug(i.first,i.second);
        }
        else{
            int pos;
            cin >> pos;
            pos--;
            if(pos==x){
                cout << "0\n";
                continue;
            }
            if(pos<x){
                pii tmp={a[pos],pos};
                pii p=*--upper_bound(all(vecl),tmp,[&](const pii& i,const pii& j){return i.second>j.second;});
                pii q=*upper_bound(all(vecr),p);
                cout << q.second-pos-1 << "\n";
            }
            else{
                pii tmp={a[pos],pos};
                pii p=*--upper_bound(all(vecr),tmp,[&](const pii& i,const pii& j){return i.second<j.second;});
                pii q=*upper_bound(all(vecl),p);
                cout << pos-q.second-1 << "\n";
            }
        }
    }
}

Compilation message

cake.cpp: In function 'int main()':
cake.cpp:22:18: warning: statement has no effect [-Wunused-value]
   22 | #define bug(...) 49
      |                  ^~
cake.cpp:89:31: note: in expansion of macro 'bug'
   89 |             for(auto i: vecl) bug(i.first,i.second);
      |                               ^~~
cake.cpp:89:22: warning: variable 'i' set but not used [-Wunused-but-set-variable]
   89 |             for(auto i: vecl) bug(i.first,i.second);
      |                      ^
cake.cpp:22:18: warning: statement has no effect [-Wunused-value]
   22 | #define bug(...) 49
      |                  ^~
cake.cpp:90:31: note: in expansion of macro 'bug'
   90 |             for(auto i: vecr) bug(i.first,i.second);
      |                               ^~~
cake.cpp:90:22: warning: variable 'i' set but not used [-Wunused-but-set-variable]
   90 |             for(auto i: vecr) bug(i.first,i.second);
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Incorrect 2 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 158 ms 332 KB Output is correct
2 Correct 119 ms 380 KB Output is correct
3 Correct 154 ms 384 KB Output is correct
4 Correct 135 ms 380 KB Output is correct
5 Correct 154 ms 496 KB Output is correct
6 Correct 150 ms 504 KB Output is correct
7 Correct 142 ms 508 KB Output is correct
8 Correct 124 ms 496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 1600 KB Output is correct
2 Correct 32 ms 1536 KB Output is correct
3 Correct 42 ms 1472 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Runtime error 29 ms 3524 KB Execution killed with signal 11
6 Runtime error 21 ms 3524 KB Execution killed with signal 11
7 Runtime error 26 ms 3900 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 460 KB Output isn't correct
2 Incorrect 21 ms 440 KB Output isn't correct
3 Incorrect 26 ms 896 KB Output isn't correct
4 Correct 34 ms 912 KB Output is correct
5 Incorrect 43 ms 580 KB Output isn't correct
6 Correct 49 ms 1184 KB Output is correct
7 Correct 51 ms 768 KB Output is correct
8 Correct 68 ms 1104 KB Output is correct
9 Runtime error 21 ms 3564 KB Execution killed with signal 11
10 Incorrect 161 ms 1424 KB Output isn't correct
11 Correct 142 ms 1804 KB Output is correct
12 Correct 266 ms 3396 KB Output is correct
13 Runtime error 21 ms 3516 KB Execution killed with signal 11