Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define f first
  3. #define s second
  4. #define mp make_pair
  5. #define pb push_back
  6. #define lp(i,a,n) for(int i=a;i<=n;++i)
  7. #define lpd(i,a,n) for(int i=a;i>=n;--i)
  8. #define mem(a,b) memset(a,b,sizeof a)
  9. #define all(v) v.begin(),v.end()
  10. #define println(a) cout <<(a) <<endl
  11. #define sz(x) ((int)(x).size())
  12. #define readi(x) scanf("%d",&x)
  13. #define read2i(x,y) scanf("%d%d",&x,&y)
  14. #define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
  15. #define mod 1000000007
  16. #define eps 1e-8
  17. #define infi 1000000000
  18. #define infll 1000000000000000000ll
  19. using namespace std;
  20. typedef long long ll;
  21. typedef pair<int,int> pii;
  22. typedef pair<ll,ll> pll;
  23. typedef vector<int> vi;
  24. typedef vector<vi> vvi;
  25. typedef vector<ll> vll;
  26. typedef set<int> si;
  27. typedef map<int,int> mii;
  28.  
  29. const int N = 400002, M = 1000003;
  30. int n,a,b,c,row[N],col[N];
  31. ll aPow[N],bPow[N],ans;
  32. ll fact[N],revFact[N];
  33. ll poly1[N],poly2[N],poly3[N];
  34.  
  35. ll power(ll x, ll y){
  36. if(!y) return 1;
  37. ll sq = power(x, y/2);
  38. sq = sq * sq % M;
  39. if(y&1) sq = sq * x % M;
  40. return sq;
  41. }
  42.  
  43. void init(){
  44. aPow[0] = bPow[0] = 1;
  45. lp(i,1,n){
  46. aPow[i] = aPow[i-1] * a % M;
  47. bPow[i] = bPow[i-1] * b % M;
  48. }
  49.  
  50. fact[0] = revFact[0] = 1;
  51. lp(i,1,N-1){
  52. fact[i] = fact[i-1] * i % M;
  53. revFact[i] = power(fact[i], M-2);
  54. }
  55. }
  56.  
  57. ll comb(ll x, ll y){
  58. if(x < y) return 0;
  59. return fact[x] * revFact[y] % M * revFact[x - y] % M;
  60. }
  61.  
  62. typedef complex<double> CD;
  63.  
  64. const double PI = acos(-1.);
  65.  
  66. inline void dft(CD out[], int n, int oper) {
  67. for (int i = 1, j = 0; i < n - 1; i++) {
  68. for (int s = n; j ^= s >>= 1, ~j & s;);
  69. if (i < j)
  70. swap(out[i], out[j]);
  71. }
  72. for (int d = 0; (1 << d) < n; d++) {
  73. int m = 1 << d, m2 = m << 1;
  74. double theta = PI / m * oper;
  75. CD u0 = CD(cos(theta), sin(theta));
  76. for (int i = 0; i < n; i += m2) {
  77. CD u = 1.;
  78. for (int j = i; j < i + m; j++) {
  79. CD p1 = out[j] + u * out[j + m];
  80. CD p2 = out[j] - u * out[j + m];
  81. out[j] = p1;
  82. out[j + m] = p2;
  83. u *= u0;
  84. }
  85. }
  86. }
  87. }
  88.  
  89. inline void conv(ll a[], ll b[], ll c[], int n) {
  90. while (n & (n - 1))
  91. n++;
  92. n *= 2;
  93. CD _a[n + 5], _b[n + 5], _c[n + 5];
  94. for (int i = 0; i < n; i++) {
  95. _a[i] = CD(a[i], 0);
  96. _b[i] = CD(b[i], 0);
  97. }
  98. dft(_a, n, 1);
  99. dft(_b, n, 1);
  100. for (int i = 0; i < n; i++)
  101. _c[i] = _a[i] * _b[i];
  102. dft(_c, n, -1);
  103. for (int i = 0; i < n; i++)
  104. c[i] = (ll) (_c[i].real() / n + .5);
  105. }
  106.  
  107. void addC(){
  108. lp(i,1,n-2){
  109. poly1[i] = aPow[i] * revFact[i] % M;
  110. poly2[i] = bPow[i] * revFact[i] % M;
  111. }
  112.  
  113. lpd(i,n,2){
  114. ans = (ans + c * aPow[n-i] % M) % M;
  115. if(i < n)
  116. ans = (ans + c * bPow[n-i] % M) % M;
  117. }
  118.  
  119. conv(poly1, poly2, poly3, n-1);
  120.  
  121. lp(i,2,2*(n-2)){
  122. poly3[i] = poly3[i] % M * fact[i] % M;
  123. ans = (ans + c * poly3[i] % M) % M;
  124. }
  125. }
  126.  
  127. int main(){
  128. cin >>n >>a >>b >>c;
  129. lp(i,1,n) readi(col[i]);
  130. lp(i,1,n) readi(row[i]);
  131.  
  132. init();
  133.  
  134. lp(i,2,n){
  135. ans = (ans + row[i] * aPow[n - i] % M * bPow[n - 1] % M * comb(n-i + n-2, n-2) % M) % M;
  136. ans = (ans + col[i] * aPow[n - 1] % M * bPow[n - i] % M * comb(n-i + n-2, n-2) % M) % M;
  137. }
  138.  
  139. addC();
  140.  
  141. cout <<ans;
  142. }
  143.  
  144. /*
  145. freopen("input.txt","r",stdin);
  146. freopen("output.txt","w",stdout);
  147. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement