Submission #65921

# Submission time Handle Problem Language Result Execution time Memory
65921 2018-08-09T06:04:09 Z ikura355 Cake (CEOI14_cake) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;

const int maxn = 250000 + 5;

int n,st,q;
int a[maxn];
int pos[maxn];
int seg[2][maxn*4];

void update(int tt, int pos, int l, int r, int x, int val) {
    if(l>r || x>y || r<x || x<l) return ;
    if(l==r) {
        seg[tt][pos] = val;
        return ;
    }
    int mid = (l+r)/2;
    update(tt,pos<<1,l,mid,x,val); update(tt,pos<<1|1,mid+1,r,x,val);
    seg[tt][pos] = max(seg[tt][pos<<1], seg[tt][pos<<1|1]);
}

int query(int tt, int pos, int l, int r, int x, int y) {
    if(l>r || x>y || r<x || y<l) return 0;
    if(x<=l && r<=y) return seg[tt][pos];
    int mid = (l+r)/2;
    return max(query(tt,pos<<1,l,mid,x,y), query(tt,pos<<1|1,mid+1,r,x,y));
}

void modify(int x, int val) {
    update(0,1,1,st-1,x,val);
    update(1,1,st+1,n,x,val);
}

int ask(int l, int r) {
    return max(query(0,1,1,st-1,l,min(r,st-1)), query(1,1,st+1,n,max(l,st+1),r));
}

int getposL(int pos, int l, int r, int val) {
    if(seg[0][pos]<=val) return l;
    if(l==r) return st;
    int mid = (l+r)/2;
    if(seg[0][pos<<1|1]<=val) return min(mid+1, getposL(pos<<1,l,mid,val));
    return getposL(pos<<1|1,mid+1,r,val);
}

int getposR(int pos, int l, int r, int val) {
    if(seg[1][pos]<=val) return r;
    if(l==r) return st;
    int mid = (l+r)/2;
    if(seg[1][pos<<1]<=val) return max(mid, getposR(pos<<1|1,mid+1,r,val));
    return getposR(pos<<1,l,mid,val);
}

int main() {
	scanf("%d%d",&n,&st);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) {
        pos[n-a[i]+1] = i;
        if(i<st) update(0,1,1,st-1,i,a[i]);
        if(i>st) update(1,1,st+1,n,i,a[i]);
	}
	scanf("%d",&q);
	while(q--) {
		char type; scanf(" %c",&type);
//        for(int i=1;i<=n;i++) printf("%d ",query(1,1,n,i,i));
//        printf("\n");
		if(type=='F') {
			int x; scanf("%d",&x);
			if(x==st) printf("0\n");
			else if(x>st) {
				int mx = ask(st+1,x);
				int res = getposL(1,1,st-1,mx);
				printf("%d\n",x-res);
			}
			else {
				int mx = ask(x,st-1);
				int res = getposR(1,st+1,n,mx);
				printf("%d\n",res-x);
			}
		}
		else {
			int x,ra; scanf("%d%d",&x,&ra);
			for(int i=ra-1;i>=1;i--) {
                modify(pos[i],ask(pos[i],pos[i])+1);
			}
			modify(x,ask(pos[ra],pos[ra])+1);
			int hey = 15;
			for(int i=1;i<=15;i++) if(pos[i]==x) hey = i;
			for(int i=hey;i>=ra;i--) pos[i] = pos[i-1];
			pos[ra] = x;
//			for(int i=1;i<=n;i++) printf("%d ",pos[i]);
//			printf("\n");
		}
	}
}

Compilation message

cake.cpp: In function 'void update(int, int, int, int, int, int)':
cake.cpp:12:17: error: 'y' was not declared in this scope
     if(l>r || x>y || r<x || x<l) return ;
                 ^
cake.cpp: In function 'int main()':
cake.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&st);
  ~~~~~^~~~~~~~~~~~~~~
cake.cpp:56:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
                        ~~~~~^~~~~~~~~~~~
cake.cpp:62:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&q);
  ~~~~~^~~~~~~~~
cake.cpp:64:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   char type; scanf(" %c",&type);
              ~~~~~^~~~~~~~~~~~~
cake.cpp:68:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int x; scanf("%d",&x);
           ~~~~~^~~~~~~~~
cake.cpp:82:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int x,ra; scanf("%d%d",&x,&ra);
              ~~~~~^~~~~~~~~~~~~~~