結果

問題 No.1786 Maximum Suffix Median (Online)
ユーザー 沙耶花沙耶花
提出日時 2021-12-15 01:40:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,794 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 210,512 KB
実行使用メモリ 54,176 KB
最終ジャッジ日時 2023-10-01 02:19:21
合計ジャッジ時間 39,030 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1,979 ms
52,640 KB
testcase_09 AC 1,284 ms
28,312 KB
testcase_10 AC 1,441 ms
29,956 KB
testcase_11 AC 1,108 ms
28,344 KB
testcase_12 TLE -
testcase_13 AC 1,368 ms
53,732 KB
testcase_14 AC 1,014 ms
28,520 KB
testcase_15 AC 1,155 ms
28,848 KB
testcase_16 AC 1,206 ms
52,796 KB
testcase_17 AC 994 ms
28,864 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 1,027 ms
53,348 KB
testcase_24 AC 736 ms
28,776 KB
testcase_25 AC 1,196 ms
52,624 KB
testcase_26 AC 1,271 ms
53,152 KB
testcase_27 AC 1,150 ms
28,828 KB
testcase_28 AC 1,361 ms
54,164 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1,269 ms
10,176 KB
testcase_32 AC 966 ms
10,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001

template <class S, S (*op)(S, S), S (*e)()> struct dynamic_segtree {
	struct node{
		int nxt[2];
		S v;
		node(){
			nxt[0] = -1;
			nxt[1] = -1;
			v = e();
		}
	};
	
	vector<node> nodes;
	
	dynamic_segtree() : dynamic_segtree(0) {}
	dynamic_segtree(long long n){
		log = 0;
		while((1LL<<log) < n){
			log++;
		}
		_n = n;
		nodes.resize(1,node());
	}
	
	bool exists(int cur,int ind){
		if(nodes[cur].nxt[ind]==-1){
			return false;
		}
		return true;
	}
	
	int get_node(int cur,int ind){
		if(nodes[cur].nxt[ind]==-1){
			nodes[cur].nxt[ind] = nodes.size();
			nodes.push_back(node());
		}
		return nodes[cur].nxt[ind];
	}
	
	void set(long long p, S x) {
        assert(0 <= p && p < _n);
		vector<int> t(1,0);
        for(int i=log-1;i>=0;i--){
			t.push_back(get_node(t.back(),(p>>i)&1));
		}
		reverse(t.begin(),t.end());
		rep(i,t.size()){
			if(i==0)nodes[t[i]].v = x;
			else{
				update(t[i]);
			}
		}
    }
	
	S get(long long p) {
        assert(0 <= p && p < _n);
		int cur = 0;
        for(int i=log-1;i>=0;i--){
			if(!exists(cur,(p>>i)&1))return e();
			cur = get_node(cur,(p>>i)&1);
		}
		return nodes[cur].v;
    }
	
	S prod(long long l,long long r,int cur,int depth){
		if(cur==-1||r-l==0)return e();
		if(r-l==(1LL<<depth))return nodes[cur].v;
		r--;
		if((l>>(depth-1))&1){
			l ^= 1LL<<(depth-1);
			r ^= 1LL<<(depth-1);
			return prod(l,r+1,nodes[cur].nxt[1],depth-1);
		}
		if(((r>>(depth-1))&1)==0){
			return prod(l,r+1,nodes[cur].nxt[0],depth-1);
		}

		r ^= 1LL<<(depth-1);
		return op(prod(l,1LL<<(depth-1),nodes[cur].nxt[0],depth-1),prod(0,r+1,nodes[cur].nxt[1],depth-1));
	}
	
	S prod(long long l, long long r) {
        assert(0 <= l && l <= r && r <= _n);
        return prod(l,r,0,log);
    }

	S all_prod() { return nodes[0].v; }

	void update(int k){
		nodes[k].v = e();
		rep(i,2){
			if(nodes[k].nxt[i]==-1)continue;
			nodes[k].v = op(nodes[k].v,nodes[nodes[k].nxt[i]].v);
		}
	}
	
	long long _n,log,size;
	
};

int op(int a,int b){
	return a+b;
}

int e(){
	return 0;
}

int main(){
	
	int last = 0;
	
	dynamic_segtree<int,op,e> seg((1<<30)+5);
	
	
	int N;
	scanf("%d",&N);
	
	rep(i,N){
		int A;
		scanf("%d",&A);
		A ^= last;
		seg.set(0,seg.get(0)+1);
		seg.set(A+1,seg.get(A+1)-1);
		int ok = A,ng = (1<<30)+1;
		while(ng-ok>1){
			int mid = (ok+ng)/2;
			//cout<<mid<<endl;
			if(seg.prod(0,mid+1)==0)ng = mid;
			else ok = mid;
		}
		//cout<<ok<<endl;
		seg.set(A+1,seg.get(A+1)-1);
		seg.set(ok+1,seg.get(ok+1)+1);
		
		ok = 0,ng = (1<<30)+1;
		while(ng-ok>1){
			int mid = (ok+ng)/2;
			//cout<<mid<<endl;
			if(seg.prod(0,mid+1)==0)ng = mid;
			else ok = mid;
		}
		printf("%d\n",ok);
		last = ok;
	}
	
	
	return 0;
}
0