답안 #43425

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43425 2018-03-15T23:47:29 Z Hassoony 케이크 (CEOI14_cake) C++14
100 / 100
1208 ms 6628 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MX=250090;
int n,Q,st,a[MX],seg[MX*5],x,y,orig[MX];
vector<int>v;
string s;
char oo[MX];
void build(int node,int l,int r){
    if(l==r){
        seg[node]=a[l];
        return;
    }
    int mid=(l+r)/2;
    build(node*2,l,mid);
    build(node*2+1,mid+1,r);
    seg[node]=max(seg[node*2],seg[node*2+1]);
}
bool cmp(int x,int y){
    return a[x]>a[y];
}
void up(int node,int l,int r,int ind,int val){
    if(l>ind||r<ind)return;
    if(l==r){
        seg[node]=val;
        return;
    }
    int mid=(l+r)/2;
    up(node*2,l,mid,ind,val);
    up(node*2+1,mid+1,r,ind,val);
    seg[node]=max(seg[node*2],seg[node*2+1]);
}
int q(int node,int l,int r,int s,int e){
    if(l>e||r<s)return 0;
    if(l>=s&&r<=e)return seg[node];
    int mid=(l+r)/2;
    return max(q(node*2,l,mid,s,e),q(node*2+1,mid+1,r,s,e));
}
int q1(int node,int l,int r,int s,int e,int val){
	if(s>e)return 0;
	if(l>e||r<s)return 0;
	if(seg[node]<=val)return 0;
	int mid=(l+r)/2;
	if(l>=s&&r<=e){
		if(l==r)return r;
		if(seg[node*2+1]>val)return q1(node*2+1,mid+1,r,s,e,val);
		return q1(node*2,l,mid,s,e,val);
	}
	int ret=q1(node*2+1,mid+1,r,s,e,val);
	if(ret!=0)return ret;
	return q1(node*2,l,mid,s,e,val);
}
int q2(int node,int l,int r,int s,int e,int val){
	if(s>e)return n+1;
	if(l>e||r<s)return n+1;
	if(seg[node]<=val)return n+1;
	int mid=(l+r)/2;
	if(l>=s&&r<=e){
		if(l==r)return r;
		if(seg[node*2]>val)return q2(node*2,l,mid,s,e,val);
		return q2(node*2+1,mid+1,r,s,e,val);
	}
	int ret=q2(node*2,l,mid,s,e,val);
	if(ret!=n+1)return ret;
	return q2(node*2+1,mid+1,r,s,e,val);
}
int main(){
    memset(orig,-1,sizeof(orig));
    scanf("%d%d",&n,&st);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]>n-10)v.push_back(i);
    }
    sort(v.begin(),v.end(),cmp);
    for(int i=0;i<v.size();i++)orig[v[i]]=i;
    build(1,1,n);
    int val=n;
    scanf("%d",&Q);
    while(Q--){
        scanf("%s",&oo);s=oo;
        if(s=="E"){
            scanf("%d%d",&x,&y);
            int idx=orig[x];
			for(auto pp:v)orig[pp]=-1;
			if(idx==-1)idx=v.size()-1;
			for(int i=idx;i>=y;i--)v[i]=v[i-1];
			v[y-1]=x;
			val+=11;
			for(int i=0;i<v.size();i++){
				orig[v[i]]=i;
				up(1,1,n,v[i],val-i);
			}
        }
        else{
            scanf("%d",&x);
            if(x==st){
                puts("0");
                continue;
            }
            if(x<st){
                int mn=q(1,1,n,x,st-1);
                int ans=q2(1,1,n,st+1,n,mn);
                int res=ans-x-1;
                cout<<res<<endl;
            }
            else{
                int mn=q(1,1,n,st+1,x);
                int ans=q1(1,1,n,1,st-1,mn);
                int res=x-ans-1;
                cout<<res<<endl;
            }
        }
    }
}
/*
12 1
1 2 3 4 5 6 7 8 9 10 11 12
20
E 1 1
*/

Compilation message

cake.cpp: In function 'int main()':
cake.cpp:76:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.size();i++)orig[v[i]]=i;
                  ^
cake.cpp:81:23: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[250090]' [-Wformat=]
         scanf("%s",&oo);s=oo;
                       ^
cake.cpp:90:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0;i<v.size();i++){
                 ^
cake.cpp:70:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&st);
                         ^
cake.cpp:72:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
                          ^
cake.cpp:79:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&Q);
                   ^
cake.cpp:81:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",&oo);s=oo;
                        ^
cake.cpp:83:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d",&x,&y);
                                ^
cake.cpp:96:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
                           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1308 KB Output is correct
2 Correct 3 ms 1380 KB Output is correct
3 Correct 3 ms 1380 KB Output is correct
4 Correct 10 ms 1484 KB Output is correct
5 Correct 21 ms 1940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 762 ms 1940 KB Output is correct
2 Correct 698 ms 1940 KB Output is correct
3 Correct 743 ms 1940 KB Output is correct
4 Correct 661 ms 1940 KB Output is correct
5 Correct 850 ms 2060 KB Output is correct
6 Correct 813 ms 2060 KB Output is correct
7 Correct 823 ms 2060 KB Output is correct
8 Correct 736 ms 2060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 3848 KB Output is correct
2 Correct 212 ms 3848 KB Output is correct
3 Correct 201 ms 3848 KB Output is correct
4 Correct 3 ms 3848 KB Output is correct
5 Correct 255 ms 5464 KB Output is correct
6 Correct 244 ms 5612 KB Output is correct
7 Correct 236 ms 5612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 5612 KB Output is correct
2 Correct 107 ms 5612 KB Output is correct
3 Correct 161 ms 5612 KB Output is correct
4 Correct 157 ms 5612 KB Output is correct
5 Correct 252 ms 5612 KB Output is correct
6 Correct 318 ms 5612 KB Output is correct
7 Correct 346 ms 5612 KB Output is correct
8 Correct 393 ms 5612 KB Output is correct
9 Correct 1208 ms 6628 KB Output is correct
10 Correct 831 ms 6628 KB Output is correct
11 Correct 943 ms 6628 KB Output is correct
12 Correct 1141 ms 6628 KB Output is correct
13 Correct 1072 ms 6628 KB Output is correct