Submission #65918

# Submission time Handle Problem Language Result Execution time Memory
65918 2018-08-09T06:02:17 Z ikura355 Cake (CEOI14_cake) C++14
20 / 100
1062 ms 7660 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 || 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 || 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 '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);
              ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 768 ms 616 KB Output isn't correct
2 Correct 335 ms 816 KB Output is correct
3 Incorrect 502 ms 896 KB Output isn't correct
4 Correct 408 ms 896 KB Output is correct
5 Incorrect 699 ms 1044 KB Output isn't correct
6 Correct 497 ms 1096 KB Output is correct
7 Incorrect 515 ms 1116 KB Output isn't correct
8 Correct 376 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 3180 KB Output is correct
2 Correct 93 ms 3180 KB Output is correct
3 Correct 95 ms 3180 KB Output is correct
4 Correct 2 ms 3180 KB Output is correct
5 Correct 166 ms 5308 KB Output is correct
6 Correct 177 ms 5308 KB Output is correct
7 Correct 142 ms 5308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 5308 KB Output isn't correct
2 Incorrect 44 ms 5308 KB Output isn't correct
3 Incorrect 104 ms 5308 KB Output isn't correct
4 Incorrect 137 ms 5308 KB Output isn't correct
5 Incorrect 181 ms 5308 KB Output isn't correct
6 Correct 185 ms 5308 KB Output is correct
7 Incorrect 214 ms 5308 KB Output isn't correct
8 Correct 272 ms 5308 KB Output is correct
9 Correct 1052 ms 6344 KB Output is correct
10 Incorrect 634 ms 6344 KB Output isn't correct
11 Incorrect 769 ms 6344 KB Output isn't correct
12 Correct 1062 ms 6344 KB Output is correct
13 Correct 899 ms 7660 KB Output is correct