#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; #define MAXN 500006 #define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedeflonglong ll; int n , m; int A[MAXN]; structtcurts { int l , r , val; } S[MAXN] ; boolcmp( tcurts a , tcurts b ){ return a.l != b.l ? a.l < b.l : a.r > b.r; }
vi G[MAXN]; vector<pii> stk;
int mxd[MAXN] , hea[MAXN]; voidafs( int u , int f ){ mxd[u] = 1; for( int v : G[u] ) if( v != f ) { afs( v , u ); if( mxd[v] + 1 > mxd[u] ) { mxd[u] = mxd[v] + 1; hea[u] = v; } } }
voiddfs( int u , int f , multiset<int,greater<int>>& Q ){ if( !hea[u] ) { Q.insert( A[u] ); return; } multiset<int,greater<int>> q; dfs( hea[u] , u , Q ); // if( u == 1 ) { for( int x : Q ) printf("%d ",x); puts(""); } for( int v : G[u] ) if( v != f && v != hea[u] ) { q.clear(); dfs( v , u , q ); auto itq = q.begin() , itQ = Q.begin(); int cur = 0 , tt = 0; vi qwq; while( itq != q.end() ) { tt = (*itQ) + (*itq); qwq.pb( tt ); ++ itQ , ++ itq; } Q.erase( Q.begin() , itQ ); for( int t : qwq ) Q.insert( t ); } // if( u == 1 ) { for( int x : Q ) printf("%d ",x); puts(""); } if( u ) Q.insert( A[u] ); }
voidsolve(){ cin >> n; rep( i , 1 , n ) { scanf("%lld%lld%lld",&S[i].l,&S[i].r,&S[i].val); } sort( S + 1 , S + 1 + n , cmp ); int cur = 1 , las = 1; stk.eb( mp( 11451419 , 0 ) ); rep( i , 1 , n ) { while( stk.back().fi <= S[i].l ) stk.pop_back(); // cout << stk.back().se << ' ' << i << endl; G[stk.back().se].pb( i ) , A[i] = S[i].val; stk.eb( mp( S[i].r , i ) ); } afs( 0 , 0 ); multiset<int,greater<int>> Q; dfs( 0 , 0 , Q ); int ans = 0; for( auto v : Q ) { // cout << v << endl; ans += v; printf("%lld ",ans); } rep( i , Q.size() + 1 , n ) printf("%lld ",ans); }
#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; #define MAXN 1000006 //#define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedeflonglong ll; int n , m , a , b; vector<pii> G[MAXN]; int vis[MAXN]; int wi[MAXN]; int pt , ed; voidafs( int u , int ef ){ vis[u] = 2; for( auto& t : G[u] ) if( t.se != ef ) { int v = t.fi; if( vis[v] == 2 ) pt = v , ed = t.se; elseif( !vis[v] ) afs( v , t.se ); } vis[u] = 3; } voiddfs( int u , int ef ){ vis[u] = 1; for( auto& t : G[u] ) if( t.se != ef ) { int v = t.fi; if( vis[v] == 3 ) wi[t.se] = v , dfs( v , t.se ); } } voidsolve(){ while( cin >> n >> m >> a >> b ) { rep( i , 1 , n * 2 ) vis[i] = 0 , G[i].clear(); rep( i , 1 , m ) wi[i] = 0; vis[a + n] = vis[b] = 1; rep( i , 1 , m ) { staticint u , v; scanf("%d%d",&u,&v); G[u].eb( mp( v + n , i ) ) , G[v + n].eb( mp( u , i ) ); } int flg = 0; rep( i , 1 , n << 1 ) if( !vis[i] ) { pt = ed = 0; afs( i , 0 ); if( !pt ) { puts("NO"); flg = 1; break; } wi[ed] = pt; dfs( pt , ed ); } if( flg ) continue; vi A , B; rep( i , 1 , m ) if( wi[i] ) if( wi[i] > n ) A.pb( i ); else B.pb( i ); puts("YES"); for( int t : A ) printf("%d ",t); puts(""); for( int t : B ) printf("%d ",t); puts(""); } } signedmain(){ // int T;cin >> T;while( T-- ) solve(); solve(); }
#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; #define MAXN 5006 //#define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) #define P 1000000007 typedeflonglong ll; int n , r , h , pl , a , b; int A[MAXN]; intPow( int x , int a ){ int ret = 1; while( a ) { if( a & 1 ) ret = ret * 1ll * x % P; x = x * 1ll * x % P , a >>= 1; } return ret; } int dpl[MAXN][MAXN] , dpr[MAXN][MAXN]; char S[MAXN]; intwork( int dp[MAXN][MAXN] , char* S , int x ){ dp[0][x] = 1; rep( i , 1 , n ) { if( S[i] == 'H' ) rep( j , 0 , n ) dp[i][j] = dp[i - 1][j + 1]; else rep( j , 0 , n ) dp[i][j] = ( j >= 1 ? ( pl * 1ll * dp[i][j - 1] + ( 1 - pl + P ) * 1ll * dp[i - 1][j] ) % P : 0 ); } } voidsolve(){ cin >> n >> r >> h; scanf("%s",S + 1); cin >> a >> b; swap( a , b ); pl = h * 1ll * Pow( r + h , P - 2 ) % P; work( dpl , S , a ); reverse( S + 1 , S + 1 + n ); rep( i , 1 , n ) S[i] = ( S[i] == 'H' ? 'R' : 'H' ); pl = r * 1ll * Pow( r + h , P - 2 ) % P; work( dpr , S , b ); int res = 0; rep( i , 0 , n ) res = ( res + dpl[i][0] * 1ll * dpr[n - i][0] % P ) % P; cout << res << endl; } signedmain(){ // int T;cin >> T;while( T-- ) solve(); solve(); }
The Jump from Height of Self-importance to Height of IQ Level