Recursive base time limit: 1 seconds space limit: 131072 KB score: 80
function f (n,m)
{
If N=1 or M=1 returns to A[n][m];
Returns f (N-1,m) Xor F (n,m-1);
}
Read in 2<=n,m<=100
For i=2->100 read in A[1][i]
For i=2->100 read in a[i][1]
Output f (n,m)
It is found that the program becomes unusually slow when the n,m is larger.
Small B After some thinking, soon solved the problem.
At this time small C appeared, I will n,m all increase 131072, you still can solve?
In contrast, I will read all the a[1][i] and a[i][1 in 2->131172).
Small b made a difficult, so come to you, can you help him?
Input
The first line reads in 131,171 positive integers, representing i=2->131172 's a[1][i] (1<=a[1][i]<=1000000000). The second line reads in 131,171 positive integers, representing i=2->131172 's a[i][1] (1<=a[i][1]<=1000000000). The third line reads a positive integer, Q (1<=q<=10000), indicating the number of queries. The next Q line, two numbers per line n,m (2<=n,m<=100), represents each group of queries.
Output
Q Line, per action F (n+131072,m+131072)
Input example
2 3 4 5 6 7 8 ... 131171 1311722 3 4 5 6 7 8 ... 131171 13117232 22) 32 4
Output example
00131072
Consider a point (0, 0) the number of contributions to a point (N, M) is C (c + M, n), so here in the calculation f (n, m), as long as you know the first row and the first column of each number of contributions is Kitchener number this or even several times, that is, calculate C (N+m, m) is odd or even, so long as 2 of the number g (n), then if there is g (n + M) = g (n) + g (m), at this point the number of combinations is even, otherwise odd.
Since f (n, m) = f (n-1, M) + f (n, m-1), just know that for F (131074, 131074...131172) and F (131074...131172, 131074) Each value is good (the others can be pushed over by these)
1 #pragmaComment (linker, "/stack:1677721600")2#include <map>3#include <Set>4#include <stack>5#include <queue>6#include <cmath>7#include <ctime>8#include <bitset>9#include <vector>Ten#include <cstdio> One#include <cctype> A#include <cstring> -#include <cstdlib> -#include <iostream> the#include <algorithm> - using namespacestd; - #defineINF 0x3f3f3f3f - #defineInf (-((LL) 1<<40)) + #defineLson k<<1, L, (L + R) >>1 - #defineRson k<<1|1, ((L + R) >>1) + 1, R + #defineMem0 (a) memset (A,0,sizeof (a)) A #defineMem1 (a) memset (A,-1,sizeof (a)) at #defineMem (A, B) memset (A, B, sizeof (a)) - #defineFIN freopen ("In.txt", "R", stdin) - #defineFOUT freopen ("OUT.txt", "w", stdout) - #defineRep (I, A, b) for (int i = A; I <= B; i + +) - #defineDec (i, A, b) for (int i = A; I >= b; i-) - in //typedef __int64 LL; -typedefLong LongLL; totypedef pair<int,int>Pair; + Const intMAXN =500000+Ten; - Const intMAXM =110000; the Const DoubleEPS = 1e- A; *LL MOD =1000000007; $ Panax Notoginseng Const intN =140000; - ConstLL mod =2; the + intf[410000]; A intans[ the][ the]; the intr[140000], c[140000]; + - voidInitintN) { $f[0] = f[1] =0; $Rep (I,2, N) { - intnum =0, x =i; - while(x%2==0) num++, x/=2; theF[i] = f[i-1] +num; - }Wuyi } the - intJudgeintNintm) { Wu returnF[n] = = F[m] + f[n-m]; - } About $ intCalcintNintm) { - intAns =0; -Rep (I,2, m) ans ^= c[i] * Judge (N-2+ M-i, M-i); -Rep (I,2, n) ans ^= r[i] * Judge (N-i + M-2, M-2); A returnans; + } the - intMain () $ { the //FIN; the //FOUT; theInit400000); theRep (I,2,131172) scanf ("%d", &c[i]); -Rep (I,2,131172) scanf ("%d", &r[i]); inRep (I,131074,131172) ans[2][i-131072] = Calc (131074, i); theRep (I,131074,131172) Ans[i-131072][2] = Calc (i,131074); theRep (I,3, -) { AboutRep (J,3, -) { theANS[I][J] = ans[i-1][J] ^ ans[i][j-1]; the } the } + intq, N, m; -CIN >>Q; the while(Q--) {Bayiscanf"%d%d", &n, &m); theprintf"%d\n", Ans[n][m]); the } - return 0; -}
51nod Algorithm Marathon 4 B recursion (YY)