답안 #65922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
65922 2018-08-09T06:04:37 Z ikura355 케이크 (CEOI14_cake) C++14
20 / 100
1110 ms 7476 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 || 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 '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);
              ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 770 ms 612 KB Output isn't correct
2 Correct 347 ms 828 KB Output is correct
3 Incorrect 494 ms 828 KB Output isn't correct
4 Correct 282 ms 828 KB Output is correct
5 Incorrect 738 ms 964 KB Output isn't correct
6 Correct 548 ms 964 KB Output is correct
7 Incorrect 556 ms 1124 KB Output isn't correct
8 Correct 320 ms 1124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 2968 KB Output is correct
2 Correct 93 ms 2968 KB Output is correct
3 Correct 86 ms 2968 KB Output is correct
4 Correct 2 ms 2968 KB Output is correct
5 Correct 176 ms 5236 KB Output is correct
6 Correct 178 ms 5288 KB Output is correct
7 Correct 166 ms 5288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 67 ms 5288 KB Output isn't correct
2 Incorrect 64 ms 5288 KB Output isn't correct
3 Incorrect 98 ms 5288 KB Output isn't correct
4 Incorrect 134 ms 5288 KB Output isn't correct
5 Incorrect 224 ms 5288 KB Output isn't correct
6 Correct 230 ms 5288 KB Output is correct
7 Incorrect 179 ms 5288 KB Output isn't correct
8 Correct 302 ms 5288 KB Output is correct
9 Correct 1110 ms 6232 KB Output is correct
10 Incorrect 613 ms 6232 KB Output isn't correct
11 Incorrect 822 ms 6232 KB Output isn't correct
12 Correct 1070 ms 6232 KB Output is correct
13 Correct 873 ms 7476 KB Output is correct