diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1b4f259 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "g++.exe build and debug active file", + "type": "cppdbg", + "request": "launch", + "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "D:\\Programs\\MSYS2\\mingw64\\bin\\gdb.exe", + "setupCommands": [ + { + "description": "为 gdb 启用整齐打印", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "g++.exe build active file" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2421e38 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "files.exclude": { + "**/.classpath": true, + "**/.project": true, + "**/.settings": true, + "**/.factorypath": true + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..41b7999 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,19 @@ +{ + "tasks": [ + { + "type": "shell", + "label": "g++.exe build active file", + "command": "D:\\Programs\\MSYS2\\mingw64\\bin\\g++.exe", + "args": [ + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "D:\\Programs\\MSYS2\\mingw64\\bin" + } + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/C339575/I.cpp b/C339575/I.cpp index 5b5101b..01e1a61 100644 --- a/C339575/I.cpp +++ b/C339575/I.cpp @@ -3,7 +3,8 @@ #include using namespace std; #define CRP(t, x) const t &x -#define OPL(t, x) bool operator<(CRP(t, x)) const +#define OPX(op, t, x) operator op(CRP(t, x)) +#define OPL(t, x) bool OPX(<, t, x) const #define FIL(x, v) memset(x, v, sizeof(x)) #define CLR(x) FIL(x, 0) #define NE1(x) FIL(x, -1) @@ -14,27 +15,73 @@ using namespace std; #define IFD if (_DEBUG) typedef int64_t ll, i64; typedef uint64_t ull, u64; -const int N = 1005 * 1005; -const double eps = 1e-8; -int a[1605], x[45]; +template +using enable_if_arithmetic = typename enable_if::value>::type; +template +using enable_if_integral = typename enable_if::value>::type; +inline char getchar(int) +{ + static char buf[64 << 20], *S = buf, *T = buf; + if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + S; + return S == T ? EOF : *S++; +} +template > +inline bool read(T &x) +{ + int ch = x = 0, f = 1; + while (!isdigit(ch = getchar())) + { + if (ch == EOF) return false; + if (ch == '-') f = -1; + } + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + x *= f; + return true; +} +template > +inline bool read(T &x, Args &... args) { return read(x) && read(args...); } +ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } +ll fpow(ll a, ll b, ll m) +{ + ll r = 1; + for (; b; b >>= 1, a = a * a % m) + if (b & 1) r = r * a % m; + return r; +} +constexpr double eps = 1e-8; +inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; } +const int N = 1e5 + 50; +ull base[N], hs[N]; +inline ull get_hash(int l, int r) +{ + return hs[r] - hs[l] * base[r - l]; +} +char s[N]; int main() { - int T, n; - double p; - scanf("%d", &T); - while (T--) + for (int i = *base = 1; i < N; i++) base[i] = base[i - 1] * 131; + map M; + for (int m, l; ~scanf("%d%d%s", &m, &l, s);) { - scanf("%d%lf", &n, &p); - for (int i = 1; i <= n; i++) - cin >> x[i]; - a[0] = 0; - int co = 1; - for (int i = 0; i <= n; i++) - for (int j = i + 1; j <= n; j++) - a[co++] = x[i] + x[j]; - sort(a, a + co); - n = (1.0 - p < eps) ? n : (int)(p * pow(2, n)); - cout << a[n - 1] << endl; + int n = strlen(s); + for (int i = 1; s[i - 1]; i++) hs[i] = hs[i - 1] * 131 + s[i - 1]; + // for (int i = 0; i < n; i += 3) printf("%d\n", get_hash(i, i + 3)); + int ans = 0; + for (int i = 0; i < l && i + m * l < n; i++) + { + M.clear(); + for (int j = i; j < i + m * l; j += l) M[get_hash(j, j + l)]++; + if (M.size() == m) ans++; + for (int j = i + m * l; j + l <= n; j += l) + { + M[get_hash(j, j + l)]++; + ull x = get_hash(j - m * l, j - m * l + l); + M[x]--; + if (M[x] == 0) M.erase(x); + if (M.size() == m) ans++; + } + } + printf("%d\n", ans); } return 0; -} +} \ No newline at end of file diff --git a/hdu/1421.cpp b/hdu/1421.cpp new file mode 100644 index 0000000..42c34f9 --- /dev/null +++ b/hdu/1421.cpp @@ -0,0 +1,90 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPX(op, t, x) operator op(CRP(t, x)) +#define OPL(t, x) bool OPX(<, t, x) const +#define FIL(x, v) memset(x, v, sizeof(x)) +#define CLR(x) FIL(x, 0) +#define NE1(x) FIL(x, -1) +#define INF(x) FIL(x, 0x3f) +#ifndef _DEBUG +#define _DEBUG 0 +#endif // !_DEBUG +#define IFD if (_DEBUG) +typedef int64_t ll, i64; +typedef uint64_t ull, u64; +template +using enable_if_arithmetic = typename enable_if::value>::type; +template +using enable_if_integral = typename enable_if::value>::type; +inline char getchar(int) +{ + static char buf[64 << 20], *S = buf, *T = buf; + if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + S; + return S == T ? EOF : *S++; +} +template > +inline bool read(T &x) +{ + int ch = x = 0; + while (!isdigit(ch = getchar())) + if (ch == EOF) return false; + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + return true; +} +template > +inline bool read(T &x, Args &... args) { return read(x) && read(args...); } +ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } +ll fpow(ll a, ll b, ll m) +{ + ll r = 1; + for (; b; b >>= 1, a = a * a % m) + if (b & 1) r = r * a % m; + return r; +} +constexpr double eps = 1e-8; +inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; } +const int N = 2050; +ll a[N]; +int vis[N]; +struct pa +{ + int i, j; + ll v; + OPL(pa, rhs) + { + if (v > rhs.v) return true; + if (v < rhs.v) return false; + if (i > rhs.i) return true; + if (i < rhs.i) return false; + return j > rhs.j; + } +}; +ll sq(ll x) { return x * x; } +int main() +{ + for (int n, k, t = 1; read(n, k); t++) + { + for (int i = 0; i < n; i++) read(a[i]); + sort(a, a + n); + priority_queue H; + // for (int i = 0; i < n; i++) + // for (int j = 0; j < i; j++) + // H.push({i, j, sq(a[i] - a[j])}); + for (int i = 1; i < n; i++) + H.push({i - 1, i, sq(a[i - 1] - a[i])}); + ll ans = 0; + for (; k && !H.empty(); H.pop()) + { + auto x = H.top(); + if (vis[x.i] == t || vis[x.j] == t) continue; + ans += x.v; + vis[x.i] = vis[x.j] = t; + k--; + } + printf("%lld\n", ans); + } + return 0; +} \ No newline at end of file diff --git a/tmpl.cpp b/tmpl.cpp index 57ff51b..57a541f 100644 --- a/tmpl.cpp +++ b/tmpl.cpp @@ -13,7 +13,39 @@ using namespace std; #define _DEBUG 0 #endif // !_DEBUG #define IFD if (_DEBUG) -typedef long long ll, i64; +typedef int64_t ll, i64; +typedef uint64_t ull, u64; +template +using enable_if_arithmetic = typename enable_if::value>::type; +template +using enable_if_integral = typename enable_if::value>::type; +inline char getchar(int) +{ + static char buf[64 << 20], *S = buf, *T = buf; + if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + S; + return S == T ? EOF : *S++; +} +template > +inline void read(T &x) +{ + int ch = x = 0, f = 1; + while (!isdigit(ch = getchar())) + if (ch == '-') f = -1; + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + x *= f; +} +template > +inline void read(T &x, Args &... args) { read(x), read(args...); } +ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } +ll fpow(ll a, ll b, ll m) +{ + ll r = 1; + for (; b; b >>= 1, a = a * a % m) + if (b & 1) r = r * a % m; + return r; +} +constexpr double eps = 1e-8; +inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; } int main() {