結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
zelosace
|
| 提出日時 | 2020-10-18 17:08:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 4,611 bytes |
| コンパイル時間 | 2,309 ms |
| コンパイル使用メモリ | 223,080 KB |
| 最終ジャッジ日時 | 2025-01-15 11:35:53 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 TLE * 32 |
ソースコード
#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]);
V = C[V];
res = C.find(V);
}
M[seg_tree.Get(i)]++;
}
REP(i,N){
out(M[seg_tree.Get(i)]);
}
return 0;
}
zelosace