結果

問題 No.618 labo-index
コンテスト
ユーザー 👑 tails
提出日時 2017-12-18 09:56:17
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 938 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 70 ms
コンパイル使用メモリ 27,804 KB
最終ジャッジ日時 2026-02-22 00:38:04
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.c:40:1: error: return type defaults to 'int' [-Wimplicit-int]
   40 | main(){
      | ^~~~
main.c: In function 'main':
main.c:43:9: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   43 |         scanf("%d",&x);
      |         ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | typedef long long ll;
main.c:43:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   43 |         scanf("%d",&x);
      |         ^~~~~
main.c:43:9: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:70:25: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   70 |                         printf("%d\n",l);
      |                         ^~~~~~
main.c:70:25: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:70:25: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:70:25: note: include '<stdio.h>' or provide a declaration of 'printf'

ソースコード

diff #
raw source code

typedef long long ll;

typedef struct {
	int c,l,r;
} Node;

Node ns[6000000];
int nn;

void add(int i,ll v,ll l,ll r,int inc){
	Node*p=ns+i;
	p->c+=inc;
	if(l<r-1){
		ll c=(l+r)/2;
		if(v<c){
			if(!p->l){
				p->l=++nn;
			}
			add(p->l,v,l,c,inc);
		}else{
			if(!p->r){
				p->r=++nn;
			}
			add(p->r,v,c,r,inc);
		}
	}
}

int count(int i,ll v,ll l,ll r){
	Node*p=ns+i;
	ll c=(l+r)/2;
	return v<c?
		(p->l?count(p->l,v,l,c):0)+(p->r?ns[p->r].c:0):
		(p->r?count(p->r,v,c,r):0);
}

ll a[100010];
int n;

main(){
	ll offset=1ll<<49;
	int t,x;
	scanf("%d",&x);

	for(;~scanf("%d%d",&t,&x);){
		if(t==1){
			ll y=x+offset;
			a[++n]=y;
			add(0,y,0,1ll<<50,1);
		}
		if(t==2){
			ll y=a[x];
			add(0,y,0,1ll<<50,-1);
		}
		if(t==3){
			offset-=x;
		}

		{
			int l=0;
			int r=ns[0].c+1;
			while(l<r-1){
				int c=(l+r)/2;
				if(count(0,c+offset-1,0,1ll<<50)>=c){
					l=c;
				}else{
					r=c;
				}
			}
			printf("%d\n",l);
		}
	}
}
0