structedge { int frm, to; }e[maxm]; int n, m; int mtr[maxn][maxn], bas[maxn][maxn]; int gp[maxn][maxn], dgr[maxn][maxn];
inlineintsolve(int N){ int tg = 1, ret = 1; for (int i = 1; i <= N; ++i) { // int cur = i; for (int j = i + 1; j <= N; ++j) { int a = i, b = j; while (mtr[b][i]) { int fac = mtr[a][i] / mtr[b][i]; for (int k = i; k <= N; ++k) mtr[a][k] = (mtr[a][k] - mtr[b][k] * fac % mod + mod) % mod; swap(a, b); } if (a != i) { for (int k = 1; k <= N; ++k) swap(mtr[i][k], mtr[a][k]); tg *= -1; } } ret = (ret * mtr[i][i]) % mod; } if (tg > 0) return ret % mod; elsereturn (mod - ret) % mod; }
intmain(){ scanf("%d", &n); scanf("%d", &m); int a, b; for (int i = 1; i <= m; ++i) { scanf("%d%d", &a, &b); e[i] = (edge){b, a}; dgr[a][a]++; gp[b][a]++; } for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) bas[i][j] = dgr[i][j] - gp[i][j]; for (int i = 2; i <= n; ++i) for (int j = 2; j <= n; ++j) mtr[i - 1][j - 1] = (bas[i][j] + mod) % mod; int ret = solve(n - 1); printf("%d\n", ret); return0; }
publicclassMain{ publicstatic BigInteger QuickPower(BigInteger base, int index){ BigInteger ret = new BigInteger(Integer.toString(1)); while (index > 0) { if ((index & 1) > 0) ret = ret.multiply(base); index >>= 1; base = base.multiply(base); } return ret; } publicstaticvoidmain(String args[])throws Exception { Scanner cin = new Scanner(System.in); int m = cin.nextInt(); for (int i = 0; i < m; ++i) { int n = cin.nextInt(); if ((n & 1) > 0) { BigInteger Thr = new BigInteger(Integer.toString(3)); BigInteger Bin = new BigInteger(Integer.toString(2)); BigInteger One = new BigInteger(Integer.toString(1)); BigInteger Res = QuickPower(Bin, n + 1); Res = Res.subtract(One); Res = Res.divide(Thr); System.out.println(Res.toString()); } else { BigInteger Thr = new BigInteger(Integer.toString(3)); BigInteger Bin = new BigInteger(Integer.toString(2)); BigInteger Res = QuickPower(Bin, n + 1); Res = Res.subtract(Bin); Res = Res.divide(Thr); System.out.println(Res.toString()); } } } }
int bkt[maxn], a[maxn], bel[maxn], tagl, tagr; int n, m, k, blo, ans[maxn], res; int sum[maxn], L, R; structquestion { int l, r, id; inlinebooloperator<(const question &rhs) const { return bel[l] == bel[rhs.l] ? r < rhs.r : bel[l] < bel[rhs.l]; } }q[maxn];
inlineintrd(){ registerint x = 0, c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); return x; } inlinevoidaddr(constint &x){ bkt[sum[x]]++; res += bkt[sum[x] ^ k]; if ((sum[x] ^ k) == sum[L - 1]) res++; } inlinevoidaddl(constint &x){ bkt[sum[x]]++; res += bkt[sum[x - 1] ^ k]; } inlinevoiddelr(constint &x){ res -= bkt[sum[x] ^ k]; bkt[sum[x]]--; if ((sum[x] ^ k) == sum[L - 1]) res--; } inlinevoiddell(constint &x){ res -= bkt[sum[x - 1] ^ k]; bkt[sum[x]]--; }
intmain(){ n = rd(); m = rd(); k = rd(); blo = sqrt(n); for (int i = 1; i <= n; ++i) a[i] = rd(), bel[i] = (i - 1) / blo + 1, sum[i] = sum[i - 1] ^ a[i]; for (int i = 1; i <= m; ++i) { q[i].l = rd(); q[i].r = rd(); q[i].id = i; } sort(q + 1, q + 1 + m); L = 1, R = 0; for (int i = 1; i <= m; ++i) { while (R < q[i].r) addr(++R); while (L > q[i].l) addl(--L); while (R > q[i].r) delr(R--); while (L < q[i].l) dell(L++); ans[q[i].id] = res; } for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]); return0; }