Submission #709223

# Submission time Handle Problem Language Result Execution time Memory
709223 2023-03-13T08:45:23 Z ktkerem Cake (CEOI14_cake) C++17
0 / 100
1322 ms 20176 KB
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define llll std::pair<ll , ll>
#define pb push_back
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
#define debug std::cout << "!!ALERT ALERT!!" << std::endl;
const ll limit = 1e18+7;
const ll sus = 1e6;
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll a , ll b){
    return (rng() % (b-a+1)) + a;
}
/*global variables*/
ll n , k;
std::vector<llll> ar;
llll gt[15];
struct segt{
    std::vector<ll> valt;
    void upd(ll l , ll r , ll nt , ll a , ll vl){
        if(l == r){
            //std::cout << l << " " << r << " " << a << std::endl;
            valt[a] = vl;
            return ;
        }
        ll md = (l + r)/2;
        if(nt <= md){
            upd(l , md , nt , a*2 , vl);
        }
        else{
            upd(md+1 , r , nt , a*2+1 , vl);
        }
        valt[a] = std::max(valt[a*2] , valt[a*2+1]);
    }
    ll que(ll l , ll r , ll nl , ll nr , ll a){
        if(nl > r || nr < l){
            return 0;
        }
        if(nl >= l && nr <= r){
            return valt[a];
        }
        ll md = (nl + nr)/2;
        ll lf = que(l , r , nl , md , a*2) , rg = que(l , r , md+1 , nr , a*2+1);
        return std::max(lf , rg); 
    }
};
segt a;
/**/
/*functions*/
void addgte(ll y , ll ind){
    ll pl = std::min(10ll , n);
    for(ll i = pl;y <= i;i--){
        gt[i+1] = gt[i];
    }
    gt[y].sec = ind;
    for(ll i = y;0<=i;i--){
        gt[i].fi++;
        a.upd(0 , n-1 , gt[i].sec , 1 ,  gt[i].fi);
    }
    /*for(ll i = 0;pl>i;i++){
        std::cout << gt[i].fi << " " << gt[i].sec << "\n";
    }*/
}
void delgte(ll y){
    ll pl = std::min(10ll , n);
    for(ll i = y;pl>i;i++){
        gt[i] = gt[i-1];
    }
    gt[pl-1] = {0 , 0};
    /*for(ll i = 0;pl>i;i++){
        std::cout << gt[i].fi << " " << gt[i].sec << "\n";
    }
    std::cout << std::endl;*/
}
/**/
void solve(){
    std::cin >> n >> k;
    a.valt.resize(4*n+5);
    k--;
    ar.resize(n);
    for(ll i = 0 ; n>i;i++){
        std::cin >> ar[i].fi;
        ar[i].sec = i;
        a.upd(0 , n-1 , i , 1 , ar[i].fi);
    }
    std::sort(all(ar) , std::greater<llll>());
    ll pl = std::min(10ll , n);
    for(ll i = 0;pl>i;i++){
        gt[i] = ar[i];
    }
    ll q;std::cin >> q;
    while(q--){
        std::string h;ll x , y;std::cin >> h >> x;x--;
        if(h == "E"){
            std::cin >> y;y--;
            for(ll i = 0;pl>i;i++){
                if(gt[i].sec == x){
                    delgte(i);
                }
            }
            addgte(y , x);
        }
        else{
            if(k == n-1){
                std::cout << k - x;
            }
            else if(k == 0){
                std::cout << x - k;
            }
            else if(x > k){
                ll l = 0 , r = k-1;
                ll o = a.que(k+1 , x , 0 , n-1 , 1);
                while(r > l){
                    ll md = (l + r)/2;
                    ll s = a.que(md , k-1 , 0 , n-1 , 1);
                    if(s > o){
                        l = md+1;
                    }
                    else{
                        r = md;
                    }
                }
                ll ans = k - l;
                if(a.que(l , k-1 , 0 , n-1 , 1) > o){
                    ans = 0;
                }
                ans += x - k;
                std::cout << ans;
            }
            else if(k > x){
                ll l = k+1 , r = n-1;
                ll o = a.que(x , k-1 , 0 , n-1 , 1);
                //std::cout << o << "\n";
                while(r > l){
                    ll md = (l + r+1)/2;
                    ll s = a.que(k+1 , md , 0 , n-1 , 1);
                    if(s > o){
                        r = md-1;
                    }
                    else{
                        l = md;
                    }
                }
                ll ans = l - k;
                if(a.que(k+1 , l , 0 , n-1 , 1) > o){
                    ans = 0;
                }
                ans += k - x;
                std::cout << ans;
            }
            else{
                std::cout << "0";
            }
            if(q){
                std::cout << std::endl;
            }
        }
    
    }
    return;/**/
}
int main(){
    std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
    /*#ifndef ONLINE_JUDGE
        freopen("in.txt" , "r" , stdin);
        freopen("out.txt" , "w" , stdout);
    #endif*/
    ll t = 1;
    //std::cin >> t;
    while(t--){
        solve();
    }
}

Compilation message

cake.cpp:5:78: warning: "/*" within comment [-Wcomment]
    5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
      |
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 203 ms 5084 KB Output isn't correct
2 Correct 147 ms 5128 KB Output is correct
3 Correct 162 ms 5240 KB Output is correct
4 Correct 133 ms 5136 KB Output is correct
5 Incorrect 221 ms 6088 KB Output isn't correct
6 Incorrect 202 ms 6476 KB Output isn't correct
7 Correct 180 ms 6216 KB Output is correct
8 Correct 140 ms 6596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 419 ms 7084 KB Output is correct
2 Correct 330 ms 6936 KB Output is correct
3 Correct 329 ms 6680 KB Output is correct
4 Incorrect 1 ms 324 KB Output isn't correct
5 Correct 424 ms 15212 KB Output is correct
6 Incorrect 464 ms 15164 KB Output isn't correct
7 Correct 409 ms 14948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 952 KB Output isn't correct
2 Correct 86 ms 1104 KB Output is correct
3 Correct 175 ms 3876 KB Output is correct
4 Incorrect 175 ms 3772 KB Output isn't correct
5 Incorrect 246 ms 1784 KB Output isn't correct
6 Correct 341 ms 5452 KB Output is correct
7 Correct 299 ms 2780 KB Output is correct
8 Correct 117 ms 7436 KB Output is correct
9 Incorrect 1219 ms 19992 KB Output isn't correct
10 Incorrect 694 ms 5324 KB Output isn't correct
11 Correct 842 ms 6952 KB Output is correct
12 Incorrect 1180 ms 17484 KB Output isn't correct
13 Incorrect 1322 ms 20176 KB Output isn't correct