# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
708844 |
2023-03-12T13:11:15 Z |
ktkerem |
Cake (CEOI14_cake) |
C++17 |
|
1895 ms |
27848 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[11];
std::vector<llll> valt;
/**/
/*functions*/
void upd(ll nt , ll vl , ll l = 0 , ll r = n-1 , ll a = 1){
//std::cout << l << " " << r << std::endl;
if(l == r){
valt[a] = {vl , vl};
return;
}
ll md = (l + r)/2;
if(nt <= md){
upd(nt , vl , l , md , a*2);
}
else{
upd(nt , vl , md+1 , r , a*2+1);
}
valt[a] = {std::min(valt[a*2].fi , valt[a*2+1].fi) , std::max(valt[a*2].sec , valt[a*2+1].sec)};
}
llll que(ll l , ll r , ll nl = 0 , ll nr = n-1 , ll a = 1){
if(nl > r || nr < l){
return{limit , -limit};
}
if(l <= nl && r >= nr){
return valt[a];
}
ll md=(nl + nr)/2;
llll lf = que(l , r , nl , md , a*2);
llll rg = que(l , r , md+1 , nr , a*2+1);
return {std::min(lf.fi , rg.fi) , std::max(lf.sec , rg.sec)};
}
/**/
void solve(){
std::cin >> n >> k;k--;
valt.resize(4 * n + 5);
ll pl = std::min(n , 10ll);
ar.resize(n);
for(ll i = 0;n>i;i++){
std::cin >> ar[i].fi;
ar[i].sec = i;
if(i == k){
ar[i].fi = 0;
}
upd(i , ar[i].fi);
}
std::sort(all(ar) , std::greater<llll>());
for(ll i=0;pl>i;i++){
gt[i] = ar[i];
}
ll q;std::cin >> q;
while(q--){
std::string h;ll x;std::cin >> h >> x;x--;
if(h == "E"){
ll y;std::cin >> y;
y--;
if(x == k){
continue;
}
ll kd = 0;
for(ll i = 0;pl>i;i++){
if(gt[i].sec == x){
kd = 1;
}
if(kd){
gt[i] = gt[i+1];
}
}
/*for(ll i = 0;pl>i;i++){
std::cout << gt[i].fi << " " << gt[i].sec << "\n";
}*/
//std::cout << "\n\n";
for(ll i = pl;i >= y;i--){
gt[i+1] = gt[i];
}
gt[y].sec = x;
for(ll i = 0;y>=i;i++){
gt[i].fi++;
upd(gt[i].sec , gt[i].fi);
}
/*for(ll i = 0;pl>i;i++){
std::cout << gt[i].fi << " " << gt[i].sec << "\n";
}*/
}
else{
if(k > x){
llll o = que(x , k);
//std::cout << o.fi << " " << o.sec << "\n";
ll l = k , r = n-1;
while(r > l){
ll md = (l + r + 1)/2;
llll sl = que(k , md);
//std::cout << k << " " << md << " " << sl.fi << " " << sl.sec << "\n";
if(o.sec < sl.sec){
r = md-1;
}
else{
l = md;
}
}
std::cout << l - k + k - x << "\n";
}
else if(k < x){
llll o = que(k , x);
ll l = 0 , r = k;
while(r > l){
ll md = (l + r)/2;
llll sl = que(md , k);
if(o.sec < sl.sec){
l = md + 1;
}
else{
r = md;
}
}
std::cout << k - l + x - k << "\n";
}
else{
std::cout << "0\n";
}
}
}
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 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
2 ms |
340 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
453 ms |
5608 KB |
Execution killed with signal 11 |
2 |
Runtime error |
346 ms |
5444 KB |
Execution killed with signal 11 |
3 |
Runtime error |
377 ms |
5444 KB |
Execution killed with signal 11 |
4 |
Correct |
314 ms |
5432 KB |
Output is correct |
5 |
Runtime error |
476 ms |
6828 KB |
Execution killed with signal 11 |
6 |
Runtime error |
441 ms |
7244 KB |
Execution killed with signal 11 |
7 |
Runtime error |
423 ms |
7108 KB |
Execution killed with signal 11 |
8 |
Correct |
333 ms |
7244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
629 ms |
10020 KB |
Execution killed with signal 11 |
2 |
Runtime error |
453 ms |
9920 KB |
Execution killed with signal 11 |
3 |
Runtime error |
421 ms |
9832 KB |
Execution killed with signal 11 |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Runtime error |
625 ms |
22944 KB |
Execution killed with signal 11 |
6 |
Runtime error |
734 ms |
22928 KB |
Execution killed with signal 11 |
7 |
Incorrect |
658 ms |
22952 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
116 ms |
972 KB |
Execution killed with signal 11 |
2 |
Runtime error |
115 ms |
1104 KB |
Execution killed with signal 11 |
3 |
Runtime error |
272 ms |
5348 KB |
Execution killed with signal 11 |
4 |
Runtime error |
237 ms |
5336 KB |
Execution killed with signal 11 |
5 |
Runtime error |
307 ms |
2152 KB |
Execution killed with signal 11 |
6 |
Runtime error |
478 ms |
7616 KB |
Execution killed with signal 11 |
7 |
Runtime error |
452 ms |
3184 KB |
Execution killed with signal 11 |
8 |
Runtime error |
239 ms |
10560 KB |
Execution killed with signal 11 |
9 |
Runtime error |
1862 ms |
27812 KB |
Execution killed with signal 11 |
10 |
Runtime error |
981 ms |
5520 KB |
Execution killed with signal 11 |
11 |
Runtime error |
1237 ms |
7456 KB |
Execution killed with signal 11 |
12 |
Runtime error |
1653 ms |
23492 KB |
Execution killed with signal 11 |
13 |
Runtime error |
1895 ms |
27848 KB |
Execution killed with signal 11 |