#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<vector> #include<queue> #include<stack> #include<bitset> #include<set> usingnamespace std; #define int long long typedeflonglong ll; #define MAXN 400006 #define pb push_back #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define inf 0x3f3f3f3f #define cmx( a , b ) a = max( a , b ) #define cmn( a , b ) a = min( a , b ) #define upd( a , b ) ( a = ( a + b ) % P ) //#define P 1000000007
voidread( signed& x ){ scanf("%d",&x); } voidread( ll& x ){ scanf("%lld",&x); } int n; int A[MAXN]; int p[MAXN], po[MAXN], val[MAXN], ok[MAXN], ans[MAXN], ress[2][MAXN];
namespace orzjk { int book[MAXN]; priority_queue<int> q; set<int> s; voidwork(int l, int r, int t){ if( t ) { for (int i = r; i >= l; i--) { s.insert( p[i] ); while (*s.rbegin() > po[i]) s.erase(*s.rbegin()); book[i] = *s.rbegin(); } for (int i = r, cur = r; i >= l; i--) { while (cur >= l && book[cur] >= p[i]) q.push(val[po[cur]]), cur--; ok[i] = q.top(), q.pop(); } } else { for (int i = l; i <= r; i++) { s.insert( p[i] ); while (*s.begin() < po[i]) s.erase(s.begin()); book[i] = *s.begin(); } for (int i = l, cur = l; i <= r; i++) { while (cur <= r && book[cur] <= p[i]) q.push(-val[po[cur]]), cur++; ok[i] = -q.top(), q.pop(); } } } }
intdoit(int tp){ int ct = 0; int res = 0; for (int i = 1; i <= n; i++) if (A[i]) ct++, p[ct] = 2 * ct - 1 + tp, po[ct] = i, res += abs(p[ct] - po[ct]); if (p[ct] > n) return0x3f3f3f3f3f3f3f3f; for (int i = 1, r; i <= ct; i = r + 1) { r = i; if (po[i] == p[i]) { ans[po[i]] = val[po[i]]; continue; } int t = p[i] < po[i]; while (r < ct && po[r + 1] != p[r + 1] && t == (p[r + 1] < po[r + 1])) ++ r; orzjk::work(i, r, t); for (int j = i; j <= r; j++) ans[p[j]] = ok[j]; } return res; }
intrua(int tp){ int res = 0; for (int i = 1; i <= n; i++) A[i] = val[i] & 1; res += doit(tp); for (int i = 1; i <= n; i++) A[i] ^= 1; res += doit(tp ^ 1); return res; }
signedmain(){ read( n ); for (int i = 1; i <= n; i++) read( val[i] ); int t1 = rua( 0 ); memcpy(ress[0], ans, sizeof(ans)); int t2 = rua( 1 ); memcpy(ress[1], ans, sizeof(ans)); if (t1 > t2) swap(ress[0], ress[1]); for (int i = 1; i <= n; i++) printf("%lld ", ress[0][i]); }
#pragma GCC optimize( 3 ) #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<vector> #include<queue> #include<stack> #include<bitset> usingnamespace std; #define int long long typedeflonglong ll; #define MAXN 1000006 #define pb push_back #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define sz size #define inf 0x3f3f3f3f #define cmx( a , b ) a = max( a , b ) #define cmn( a , b ) a = min( a , b ) #define upd( a , b ) ( a = ( a + b ) % P ) #define P 998244353 int n , m; int a , b , p; int A[MAXN];
voidread( signed& x ){ scanf("%d",&x); } voidread( ll& x ){ scanf("%lld",&x); }
intpower( int x , int a ){ int cur = x % P , ans = 1; while( a ) { if( a & 1 ) ans *= cur , ans %= P; cur *= cur , cur %= P , a >>= 1; } return ans; } int k; int J[MAXN]; signedmain(){ read( n ) , read( a ) , read( b ); p = power( b , P - 2 ) * a % P; int cur = 1 , x = 1 , ans = 0; if( p == 499122177 ) { J[0] = 1; for( int i = 1 ; i <= n ; ++ i ) J[i] = J[i - 1] * i % P; for( int m = 1 ; m < n ; ++ m ) { cur = ( J[n] * power( J[m] * J[n - m] % P , P - 2 ) % P * power( power( 2 , m * ( n - m ) ) , P - 2 )) % P; ans += x * cur , ans %= P; x = x * x % P + 2 , x %= P; } cout << ans << endl; return0; } for( int i = 1 ; i < n ; ++ i ) { cur *= ( ( power( 1 - p + P , n - i + 1 ) - power( p , n - i + 1 ) + P ) % P * ( power( power( 1 - p + P , i ) - power( p , i ) + P , P - 2 ) % P ) ) % P; cur %= P; ans = ( ans + x * cur ) % P; x = x * x % P + 2 , x %= P; } cout << ans << endl; }