# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
170365 |
2019-12-24T22:17:55 Z |
rzbt |
케이크 (CEOI14_cake) |
C++14 |
|
1573 ms |
44564 KB |
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define MAXN 250005
#define F first
#define S second
using namespace std;
typedef long long ll;
ll n,a;
ll niz[MAXN];
ll seg[4*MAXN];
ll lazy[4*MAXN];
set<pair<ll,ll> > svi;
void dodaj(ll l,ll d,ll p,ll x,ll k){
if(l==d){
seg[k]=x;
return;
}
ll mid=(l+d)/2;
if(p<=mid)return dodaj(l,mid,p,x,k+k);
else dodaj(mid+1,d,p,x,k+k+1);
seg[k]=max(seg[k+k],seg[k+k+1]);
}
ll dobij(ll l,ll d,ll tl,ll td,ll k){
if(l>td || d<tl)return 0;
if(l>=tl && d<=td)return seg[k];
ll mid=(l+d)/2;
return max(dobij(l,mid,tl,td,k+k),dobij(mid+1,d,tl,td,k+k+1));
}
void izgradi(ll l,ll d,ll k){
if(l==d){
seg[k]=niz[l];
return;
}
ll mid=(l+d)/2;
izgradi(l,mid,k+k);
izgradi(mid+1,d,k+k+1);
seg[k]=max(seg[k+k],seg[k+k+1]);
}
bool nadjen;
ll nadjiL(ll l,ll d,ll tl,ll td,ll k,ll x){
//printf(" %lld %lld %lld %lld\n",l,d,tl,td);
if(nadjen)return -1;
if(l>td || d<tl)return -1;
ll mid=(l+d)/2;
if(l>=tl && d<=td){
if(l==d ){
if(seg[k]>x)nadjen=true;
return (seg[k]>x?l:-1);
}
if(seg[k+k+1]>x)return nadjiL(mid+1,d,tl,td,k+k+1,x);
return nadjiL(l,mid,tl,td,k+k,x);
}
ll tren=nadjiL(mid+1,d,tl,td,k+k+1,x);
if(tren!=-1)return tren;
return nadjiL(l,mid,tl,td,k+k,x);
}
ll nadjiD(ll l,ll d,ll tl,ll td,ll k,ll x){
//printf(" %lld %lld %lld %lld\n",l,d,tl,td);
if(nadjen)return -1;
if(l>td || d<tl)return -1;
ll mid=(l+d)/2;
if(l>=tl && d<=td){
if(l==d ){
//printf(" %lld %lld\n",seg[k],x);
if(seg[k]>x)nadjen=true;
return (seg[k]>x?l:-1);
}
//printf(" %lld %lld\n",seg[k+k],x);
if(seg[k+k]>x)return nadjiD(l,mid,tl,td,k+k,x);
return nadjiD(mid+1,d,tl,td,k+k+1,x);
}
ll tren=nadjiD(l,mid,tl,td,k+k,x);
if(tren!=-1)return tren;
return nadjiD(mid+1,d,tl,td,k+k+1,x);
}
int main()///PROMENI U LONG LONG
{
scanf("%lld %lld", &n, &a);
for(ll i=1;i<=n;i++){
scanf("%lld",niz+i);
niz[i]*=500005;
svi.insert(mp(niz[i],i));
}
izgradi(1,n,1);
ll qq;
scanf("%lld", &qq);
while(qq--){
char qt[5];
scanf("%s", qt);
if(qt[0]=='E'){
ll koji,postaje;
scanf("%lld %lld", &koji, &postaje);
svi.erase(mp(niz[koji],koji));
//printf(" poz %lld brisem %lld ",koji,niz[koji]);
auto it=svi.end();
for(ll i=1;i<postaje;i++){
it--;
auto tp=*it;
tp.F++;
svi.erase(it);
it=svi.insert(tp).F;
dodaj(1,n,tp.second,tp.first,1);
printf("%lld ",tp.S);
}
it--;
niz[koji]=(it->first)+1;
//printf(" stavljam %lld",niz[koji]);
svi.insert(mp(niz[koji],koji));
dodaj(1,n,koji,niz[koji],1);
//printf(" sada %lld\n",dobij(1,n,koji,koji,1));
}else{
ll koji;
scanf("%lld", &koji);
if(koji==a){
printf("0\n");
continue;
}
if(koji<a){
ll najv=dobij(1,n,koji,a-1,1);
nadjen=false;
ll tn=nadjiD(1,n,a+1,n,1,najv);
if(tn==-1)tn=n+1;
printf("%lld\n",tn-koji-1);
}else{
ll najv=dobij(1,n,a+1,koji,1);
nadjen=false;
ll tn=nadjiL(1,n,1,a-1,1,najv);
if(tn==-1)tn=0;
printf("%lld\n",koji-tn-1);
}
}
}
return 0;
}
Compilation message
cake.cpp: In function 'int main()':
cake.cpp:91:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &n, &a);
~~~~~^~~~~~~~~~~~~~~~~~~~~
cake.cpp:93:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",niz+i);
~~~~~^~~~~~~~~~~~~~
cake.cpp:99:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &qq);
~~~~~^~~~~~~~~~~~~
cake.cpp:102:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", qt);
~~~~~^~~~~~~~~~
cake.cpp:105:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &koji, &postaje);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cake.cpp:127:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &koji);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
866 ms |
28496 KB |
Output isn't correct |
2 |
Incorrect |
424 ms |
9112 KB |
Output isn't correct |
3 |
Incorrect |
550 ms |
15224 KB |
Output isn't correct |
4 |
Correct |
303 ms |
5752 KB |
Output is correct |
5 |
Incorrect |
922 ms |
30200 KB |
Output isn't correct |
6 |
Incorrect |
759 ms |
27764 KB |
Output isn't correct |
7 |
Incorrect |
608 ms |
16888 KB |
Output isn't correct |
8 |
Correct |
367 ms |
7816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
170 ms |
11444 KB |
Output isn't correct |
2 |
Incorrect |
121 ms |
11356 KB |
Output isn't correct |
3 |
Incorrect |
122 ms |
11192 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Incorrect |
345 ms |
25204 KB |
Output isn't correct |
6 |
Incorrect |
345 ms |
25296 KB |
Output isn't correct |
7 |
Incorrect |
210 ms |
25168 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
82 ms |
2552 KB |
Output isn't correct |
2 |
Incorrect |
56 ms |
1840 KB |
Output isn't correct |
3 |
Incorrect |
142 ms |
6496 KB |
Output isn't correct |
4 |
Incorrect |
181 ms |
7640 KB |
Output isn't correct |
5 |
Incorrect |
232 ms |
6392 KB |
Output isn't correct |
6 |
Incorrect |
277 ms |
9248 KB |
Output isn't correct |
7 |
Incorrect |
225 ms |
5612 KB |
Output isn't correct |
8 |
Incorrect |
428 ms |
15992 KB |
Output isn't correct |
9 |
Incorrect |
1573 ms |
41336 KB |
Output isn't correct |
10 |
Incorrect |
785 ms |
20160 KB |
Output isn't correct |
11 |
Incorrect |
999 ms |
23708 KB |
Output isn't correct |
12 |
Incorrect |
1520 ms |
38388 KB |
Output isn't correct |
13 |
Incorrect |
1176 ms |
44564 KB |
Output isn't correct |