結果

問題 No.1170 Never Want to Walk
ユーザー zelosacezelosace
提出日時 2020-10-18 17:10:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,633 bytes
コンパイル時間 2,653 ms
コンパイル使用メモリ 229,300 KB
実行使用メモリ 19,888 KB
最終ジャッジ日時 2023-09-28 11:55:21
合計ジャッジ時間 12,771 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 WA -
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 5 ms
4,380 KB
testcase_27 AC 584 ms
17,852 KB
testcase_28 AC 574 ms
17,464 KB
testcase_29 WA -
testcase_30 AC 594 ms
18,120 KB
testcase_31 AC 578 ms
17,828 KB
testcase_32 AC 657 ms
16,488 KB
testcase_33 AC 653 ms
16,460 KB
testcase_34 AC 659 ms
17,020 KB
testcase_35 AC 666 ms
16,780 KB
testcase_36 AC 652 ms
16,668 KB
testcase_37 AC 639 ms
16,452 KB
testcase_38 AC 647 ms
17,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

class RangeUpdate{
public:
	virtual ll fa(ll x,ll m)=0;
	virtual ll fm(ll m1,ll m2)=0;
	ll em;
};

class RangeUpdateChange:public RangeUpdate{
public:
	RangeUpdateChange(){em = numeric_limits<ll>::max();}
	ll fa(ll x,ll m){return m;}
	ll fm(ll m1,ll m2){return m2;}
};

class RangeQuery{
public:
	virtual ll fx(ll x1,ll x2)=0;
	virtual ll fp(ll m,ll n)=0;
	ll ex;
};

class RangeQueryMin:public RangeQuery{
public:
	RangeQueryMin(){ex = numeric_limits<ll>::max();}
	ll fx(ll x1,ll x2){return min(x1,x2);}
	ll fp(ll m,ll n){return m;}
};

class SegmentTree{
	unique_ptr<RangeUpdate> range_update;
	unique_ptr<RangeQuery> range_query;

	/* lazy eval */
	void Eval(int k,int len){
		if(lazy[k]==range_update->em) return;  // 更新するものが無ければ終了
		if(k<size-1){            // 葉でなければ子に伝搬
			lazy[k*2+1] = range_update->fm(lazy[k*2+1],lazy[k]);
			lazy[k*2+2] = range_update->fm(lazy[k*2+2],lazy[k]);
		}
		// 自身を更新
		dat[k] = range_update->fa(dat[k],range_query->fp(lazy[k],len));
		lazy[k] = range_update->em;
	}

	ll Query(ll a, ll b, ll k, ll l, ll r){
		Eval(k,r-l);
		if(r<=a || b<=l){  // 完全に外側の時
			return range_query->ex;
		}
		else if(a <= l && r <= b){  // 完全に内側の時
			return dat[k];
		}
		else{  // 一部区間が被る時
			ll vl = Query(a,b,k*2+1,l,(l+r)/2);
			ll vr = Query(a,b,k*2+2,(l+r)/2,r);
			return range_query->fx(vl,vr);
		}
	}

	void Update(ll a, ll b, ll x, ll k, ll l, ll r) {
		Eval(k,r-l);
		if(a<=l && r<=b){  // 完全に内側の時
			lazy[k] = range_update->fm(lazy[k],x);
			Eval(k,r-l);
		}
		else if(a<r && l<b){                     // 一部区間が被る時
			Update(a,b,x,k*2+1,l,(l+r)/2);  // 左の子
			Update(a,b,x,k*2+2,(l+r)/2,r);  // 右の子
			dat[k] = range_query->fx(dat[k*2+1],dat[k*2+2]);
		}
	}
public:
	ll size;
	vector<ll> dat;
	vector<ll> lazy;
	SegmentTree(ll N, unique_ptr<RangeUpdate> rup,unique_ptr<RangeQuery> rqp)
		: range_update(std::move(rup)), range_query(std::move(rqp)){
		dat.resize(max(4*N,4ll),range_query->ex);
		lazy.resize(max(4*N,4ll),range_update->em);
		ll x = 1;
		while(N>x) x *= 2;
		size = x;
	}
	void Set(int i,ll x){dat[i+size-1]=x;}
	ll Get(int i){return dat[i+size-1];}
	void Build(){
		for(ll k=size-2ll;k>=0;k--) dat[k] = range_query->fx(dat[2*k+1],dat[2*k+2]);
	}

	void Update(ll a, ll b, ll x){Update(a, b, x, 0, 0, size);}
	ll Query(int a, int b){return Query(a, b, 0, 0, size);}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto N=in(),A=in(),B=in();
	auto X=vecin(N);

	SegmentTree seg_tree(N,make_unique<RangeUpdateChange>(),make_unique<RangeQueryMin>());
	REP(i,N){
		seg_tree.Set(i,X[i]);
	}
	seg_tree.Build();

	map<ll,ll> C;
	REP(i,N){
		ll L=X[i]+A,R=X[i]+B;
		auto resL = lower_bound(ALL(X),L);
		auto resR = upper_bound(ALL(X),R);

		ll n = distance(resL,resR);
		ll d = distance(X.begin(),resL)-i;

		//if(!n) continue;

		ll self = seg_tree.Query(i,i+1);
		ll to = seg_tree.Query(i+d,i+d+n);
		seg_tree.Update(i+d,i+d+n,to);
		if(self<to){
			C[to] = self;
			seg_tree.Update(i+d,i+d+n,self);
		}
		else{
			C[self] = to;
			seg_tree.Update(i,i+1,to);
		}
	}
	
	map<ll,ll> M;
	REP(i,N){
		ll V = seg_tree.Get(i);
		auto res = C.find(V);
		while(res!=C.end()){
			seg_tree.Set(i,C[V]);
			if(V==C[V]) break;
			V = C[V];
			res = C.find(V);
		}
		M[seg_tree.Get(i)]++;
	}
	REP(i,N){
		out(M[seg_tree.Get(i)]);
	}
	
	return 0;
}
0