Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit 88ca774

Browse files
author
ZhangZisu
committed
2018-12-22
1 parent 146c464 commit 88ca774

File tree

3 files changed

+198
-2
lines changed

3 files changed

+198
-2
lines changed

.vscode/tasks.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"-o",
1212
"${fileDirname}/${fileBasenameNoExtension}",
1313
"-Wall",
14-
"-DDEBUG",
15-
"-Wl,--stack=536870912"
14+
"-DDEBUG"
1615
],
1716
"group": {
1817
"kind": "build",

SPOJ/tsum.cpp

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#include <algorithm>
2+
#include <cctype>
3+
#include <cstdio>
4+
#include <cstdlib>
5+
#include <cstring>
6+
class IO {
7+
protected:
8+
static const int BSIZE = 65536;
9+
int is;
10+
char ib[BSIZE], ob[BSIZE], *ip, *op;
11+
FILE *in, *out;
12+
13+
public:
14+
inline IO(FILE *in = stdin, FILE *out = stdout) {
15+
ip = ib + BSIZE, op = ob, is = 0;
16+
this->in = in;
17+
this->out = out;
18+
}
19+
inline ~IO() {
20+
fwrite(ob, 1, op - ob, out);
21+
}
22+
inline char getchar() {
23+
if (ip == ib + BSIZE) is = fread(ib, 1, BSIZE, in), ip = ib;
24+
return ip == ib + is ? 0 : *ip++;
25+
}
26+
inline void putchar(char c) {
27+
if (op == ob + BSIZE) fwrite(ob, 1, BSIZE, out), op = ob;
28+
*op++ = c;
29+
}
30+
};
31+
class IOX : public IO {
32+
protected:
33+
int tmp[64];
34+
35+
public:
36+
inline IOX(FILE *in = stdin, FILE *out = stdout) : IO(in, out) {}
37+
inline int getdigit() {
38+
register char ch = getchar();
39+
while (!isdigit(ch)) ch = getchar();
40+
return ch ^ 48;
41+
}
42+
inline char getalpha() {
43+
register char ch = getchar();
44+
while (!isalpha(ch)) ch = getchar();
45+
return ch;
46+
}
47+
inline int getint() {
48+
register int x = 0, f = 0;
49+
register char ch = getchar();
50+
for (; !isdigit(ch); ch = getchar()) f ^= ch == 45;
51+
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
52+
return f ? -x : x;
53+
}
54+
inline unsigned getuint() {
55+
register unsigned x = 0;
56+
register char ch = getchar();
57+
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
58+
return x;
59+
}
60+
inline long long getint64() {
61+
register long long x = 0, f = 0;
62+
register char ch = getchar();
63+
for (; !isdigit(ch); ch = getchar()) f ^= ch == 45;
64+
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
65+
return f ? -x : x;
66+
}
67+
inline unsigned long long getuint64() {
68+
register unsigned long long x = 0;
69+
register char ch = getchar();
70+
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
71+
return x;
72+
}
73+
inline void putint(int x) {
74+
if (!x) return putchar('0');
75+
if (x < 0) putchar(45), x = -x;
76+
register int _6;
77+
for (_6 = 0; x; x /= 10) tmp[++_6] = (x % 10) ^ 48;
78+
while (_6) putchar(tmp[_6--]);
79+
}
80+
inline void putint64(long long x) {
81+
if (!x) return putchar('0');
82+
if (x < 0) putchar(45), x = -x;
83+
register int _6;
84+
for (_6 = 0; x; x /= 10) tmp[++_6] = (x % 10) ^ 48;
85+
while (_6) putchar(tmp[_6--]);
86+
}
87+
inline void puts(const char *s) {
88+
for (; *s; s++) putchar(*s);
89+
putchar(10);
90+
}
91+
};
92+
#define MAXN 40000
93+
const int INF = 0x3F3F3F3F;
94+
const int N = 17;
95+
struct complex{
96+
double real, image;
97+
inline complex(double real = 0, double image = 0):real(real), image(image){}
98+
inline complex friend operator + (complex a, complex b) const {
99+
return complex(a.real + b.real, a.image, b.image);
100+
}
101+
inline complex friend operator - (complex a, complex b) const {
102+
return complex(a.real - b.real, a.image - b.image);
103+
}
104+
inline complex friend operator
105+
};
106+
int n, min = INF, s[MAXN];
107+
int main() {
108+
IOX io;
109+
n = io.getint();
110+
for(int i = 1;i <= n;i++)min = std::min(min, s[i] = io.getint());
111+
for(int i = 1;i <= n;i++){
112+
s[i] -= min;
113+
114+
}
115+
return 0;
116+
}

_local/WC2018Train/33.cpp

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include <algorithm>
2+
#include <cstdio>
3+
#include <cstdlib>
4+
#include <cstring>
5+
#include <vector>
6+
struct MathUtils {
7+
int MOD;
8+
inline MathUtils(int MOD) : MOD(MOD) {}
9+
inline void trim(int &x) const {
10+
if (x >= MOD) x -= MOD;
11+
}
12+
inline void up(int &x, int y) const { trim(x += y); }
13+
inline int pow(int x, int y) const {
14+
int z = 1;
15+
for (; y; y >>= 1) {
16+
if (y & 1) z = 1LL * z * x % MOD;
17+
x = 1LL * x * x % MOD;
18+
}
19+
return z;
20+
}
21+
};
22+
struct PolyUtils : public MathUtils {
23+
int G;
24+
inline PolyUtils(int MOD, int G) : MathUtils(MOD), G(G) {}
25+
inline void NTT(int *a, int n) const {
26+
for (int i = 1, j = 0; i < n - 1; i++) {
27+
for (int t = n; ~j & t; j ^= t) t >>= 1;
28+
if (i < j) std::swap(a[i], a[j]);
29+
}
30+
for (int i = 1; i < n; i <<= 1) {
31+
int t = i << 1, wn = pow(G, (MOD - 1) / t);
32+
for (int j = 0; j < n; j += t) {
33+
for (int k = 0, w = 1; k < i; k++, w = 1LL * w * wn % MOD) {
34+
int x = a[j + k], y = 1LL * w * a[j + k + i] % MOD;
35+
trim(a[j + k] = x + y);
36+
trim(a[j + k + i] = x - y + MOD);
37+
}
38+
}
39+
}
40+
}
41+
inline void IDFT(int *a, int n) const {
42+
NTT(a, n);
43+
std::reverse(a + 1, a + n);
44+
for (int i = 0, inv = pow(n, MOD - 2); i < n; i++) a[i] = 1LL * a[i] * inv % MOD;
45+
}
46+
} common(1004535809, 3);
47+
inline int getG(int p) {
48+
MathUtils math(p);
49+
if (p == 2) return 1;
50+
std::vector<int> fac;
51+
for (int i = 2; i < p - 1; i++) {
52+
if ((p - 1) % i) continue;
53+
fac.push_back(i);
54+
}
55+
for (int i = 2;; i++) {
56+
if (std::all_of(fac.begin(), fac.end(), [i, p, math](int v) { return math.pow(i, v) != 1; })) return i;
57+
}
58+
}
59+
const int N = 14;
60+
const int len = 1 << N;
61+
int n, m, x, s, a[len], id[len], f[len], h[len];
62+
int main() {
63+
scanf("%d%d%d%d", &n, &m, &x, &s);
64+
for (int g = getG(m), i = 0, v = 1; i < m - 1; i++, v = 1LL * v * g % m) id[v] = i;
65+
for (int x; s; s--) scanf("%d", &x) && x && (f[id[x]] = 1);
66+
memcpy(h, f, sizeof(h));
67+
for (m--, n--; n; n >>= 1) {
68+
common.NTT(f, len);
69+
if (n & 1) {
70+
common.NTT(h, len);
71+
for (int i = 0; i < len; i++) h[i] = 1LL * h[i] * f[i] % common.MOD;
72+
common.IDFT(h, len);
73+
for (int i = m; i < m + m; i++) common.up(h[i - m], h[i]), h[i] = 0;
74+
}
75+
for (int i = 0; i < len; i++) f[i] = 1LL * f[i] * f[i] % common.MOD;
76+
common.IDFT(f, len);
77+
for (int i = m; i < m + m; i++) common.up(f[i - m], f[i]), f[i] = 0;
78+
}
79+
printf("%d\n", h[id[x]]);
80+
return 0;
81+
}

0 commit comments

Comments
 (0)