結果

問題 No.1170 Never Want to Walk
ユーザー kappybarkappybar
提出日時 2020-08-15 13:10:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,743 bytes
コンパイル時間 2,613 ms
コンパイル使用メモリ 183,848 KB
実行使用メモリ 13,952 KB
最終ジャッジ日時 2024-04-19 00:55:08
合計ジャッジ時間 9,329 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;


struct range_path{
    int n; 
    int N;
    int V;
    vector<vector<pair<long long,int>>> Graph;
    range_path(int n):n(n){
        while(N<n) N*=2;
        Graph.resize(3*N-2);
        V=3*N-2;
        for(int i=0;i<N-1;++i){
            Graph[i].emplace_back(0,2*i+1);
            Graph[i].emplace_back(0,2*i+2);
            Graph[2*i+N-1].emplace_back(0,i+2*N-1);
            Graph[2*i+N].emplace_back(0,i+2*N-1);
        }
    }
    void add_edge_from(int k,int l,int r,int p,int q,int v){
        if(r <= p || q <= l) return;
        if(l <= p && q <= r) Graph[3*N-3-k].emplace_back(0LL,v);
        else{
            add_edge_from(2*k+2,l,r,p,(p+q)/2,v);
            add_edge_from(2*k+1,l,r,(p+q)/2,q,v);
        }
    }
    void add_edge_to(int k,int L,int R,int p,int q,int v){
        if(R <= p || q <= L) return;
        if(L <= p && q <= R) Graph[v].emplace_back(0LL,k);
        else{
            add_edge_to(2*k+1,L,R,p,(p+q)/2,v);
            add_edge_to(2*k+2,L,R,(p+q)/2,q,v);
        }
    }
    void add_edge(int l,int r,int L,int R,long long cost){
        if(l>=r||L>=R) return;
        Graph.emplace_back();
        Graph.emplace_back();
        V+=2;
        add_edge_from(0,l,r,0,N,V-2);
        add_edge_to(0,L,R,0,N,V-1);
        Graph[V-2].emplace_back(cost,V-1);
    }
};


int main(){
    int n,a,b;
    cin >> n >> a >> b;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    range_path G(n);
    rep(i,n){
        int l = lower_bound(x.begin(),x.end(),x[i]+a) - x.begin();
        int r = upper_bound(x.begin(),x.end(),x[i]+b) - x.begin();
        G.add_edge(i,i+1,l,r,0);
        G.add_edge(l,r,i,i+1,0);
    }
    vector<int> ans(10*G.N+3,-1);
    rep(i,n){
        if(ans[i+G.N-1]>=0) continue;
        int id = i+G.N-1;
        queue<int> q;
        vector<int> vv;
        q.push(id);
        vv.push_back(id);
        int res = 0;
        while(!q.empty()){
            int next = q.front();
            q.pop();
            if(ans[next]>=0) continue;
            ans[next]=0;
            vv.push_back(next);
            if(G.N-1<=next&&next<G.N-1+n) ++res;
            for(auto j:G.Graph[next]){
                if(ans[j.second]>=0) continue;
                q.push(j.second);
            }
        }
        cout << res << "  " ;
        for(int j:vv) {ans[j] = res; cout << j <<" " ;}
        cout << endl;
    }
    rep(i,n){
        cout << ans[i+G.N-1] << endl;
    }
    return 0;
}
0