結果

問題 No.828 全方位神童数
ユーザー mtsdmtsd
提出日時 2019-05-04 00:05:21
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,611 bytes
コンパイル時間 547 ms
コンパイル使用メモリ 83,200 KB
最終ジャッジ日時 2024-06-10 07:36:28
合計ジャッジ時間 1,909 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In constructor ‘segtree<T>::segtree(std::vector<_Tp>&)’:
main.cpp:62:26: error: ‘numeric_limits’ was not declared in this scope
   62 |         node.resize(2*n, numeric_limits<T>::min());
      |                          ^~~~~~~~~~~~~~
main.cpp:62:42: error: expected primary-expression before ‘>’ token
   62 |         node.resize(2*n, numeric_limits<T>::min());
      |                                          ^
main.cpp:62:48: error: no matching function for call to ‘min()’
   62 |         node.resize(2*n, numeric_limits<T>::min());
      |                                           ~~~~~^~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from main.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:230:5: note: candidate: ‘template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)’
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
main.cpp:62:48: note:   candidate expects 2 arguments, 0 provided
   62 |         node.resize(2*n, numeric_limits<T>::min());
      |                                           ~~~~~^~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from main.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:278:5: note: candidate: ‘template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)’
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
main.cpp:62:48: note:   candid

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

vector<vector<int> > g;
vector<int> s;
int p[200010][2];
int id = 0;
void dfs(int a,int pre){
    s[id] = a;
    p[a][0] = id;
    id++;
    for(auto x:g[a]){
        if(x==pre)continue;
        dfs(x,a);
    }
    s[id] = a;
    p[a][1] = id;
    id++;
}


template<typename T> class segtree {
private:
    int n,sz,h; vector<T> node, lazy, lazyFlag;
    void eval(int k) {
        if(lazyFlag[k]){
            node[k] = lazy[k];
            if(k < n) {
                lazy[k*2] = lazy[k*2+1] = lazy[k]; lazyFlag[k*2] = lazyFlag[k*2+1] = true;
            }
            lazyFlag[k] = false;
        }
    }

public:
    segtree(vector<T>& v) : sz((int)v.size()), h(0){
        n = 1;
        while(n < sz) n *= 2, h++;
        node.resize(2*n, numeric_limits<T>::min());
        lazy.resize(2*n); lazyFlag.resize(2*n, false);
        for(int i = 0; i < sz; i++) node[i+n] = v[i];
        for(int i = n - 1; i >= 1; i--) node[i] = max(node[i*2],node[i*2+1]);
    }
    void range(int a, int b, T x) {
        a += n, b += n - 1;
        for(int i = h; i > 0; i--){
            eval(a >> i), eval(b >> i);
        }
        int ta = a, tb = b++;
        while(a < b){
            if(a & 1) lazy[a] = x, lazyFlag[a++] = true;
            if(b & 1) lazy[--b] = x, lazyFlag[b] = true;
            a >>= 1, b >>= 1;
        }
        while(ta >>= 1, tb >>= 1, ta){
            if(!lazyFlag[ta]){
                eval(2*ta), eval(2*ta+1), node[ta] = max(node[2*ta], node[2*ta+1]);
            }
            if(!lazyFlag[tb]){
                eval(2*tb), eval(2*tb+1), node[tb] = max(node[2*tb], node[2*tb+1]);
            }
        }
    }
    T query(int a, int b) {
        if(a>=b)return 0;
        a += n, b += n - 1;
        for(int i = h; i > 0; i--) eval(a >> i), eval(b >> i);
        b++;
        T res1 = numeric_limits<T>::min(), res2 = numeric_limits<T>::min();
        while(a < b) {
            if(a & 1) eval(a), res1 = max(res1, node[a++]);
            if(b & 1) eval(--b), res2 = max(res2, node[b]);
            a >>= 1, b >>= 1;
        }
        return max(res1, res2);
    }
    void print(){for(int i = 0; i < sz; i++) cout<<query(i,i+1)<< " ";cout<<endl;}
};
vector<ll>res;
void calc(int l,int r,segtree<int> &sg,int sm){
    int k = sg.query(l,r);
    //cerr << l << " " << r << " " << k << endl;
    if(k==0)return;
    res[k-1] = sm+1;
    int id = p[k][0];
    while(s[id+1]!=k){
        id++;
        int q = s[id];
        calc(p[q][0],p[q][1]+1,sg,sm+1);
        id = p[q][1];
    }
    sg.range(p[k][0],p[k][1]+1,0);
    calc(l,r,sg,sm+1);
}


int main(){
    int n;
    cin >> n;
    s.resize(2*n);
    vector<ll> r(n);
    res.resize(n);
    rep(i,n) cin >> r[i];
    g.resize(n+1);
    rep(i,n-1){
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1,1);
    // rep(i,2*n){
    //     cerr << s[i] << " " ;
    // }
    // cerr << endl;
    segtree<int> sg(s);
    calc(0,2*n,sg,0);
    ll ans = 1;
    for(int i=0;i<n;i++){
        ans *=(r[i]+res[i]);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}
0