diff --git a/.vscode/acm.code-snippets b/.vscode/acm.code-snippets index 28f1b5b..432e271 100644 --- a/.vscode/acm.code-snippets +++ b/.vscode/acm.code-snippets @@ -36,6 +36,8 @@ "#define IFD if (_DEBUG)", "typedef int64_t ll, i64;", "typedef uint64_t ull, u64;", + "template ", + "using comtype = typename common_type::type;", "template ", "using enable_if_arithmetic = typename enable_if::value>::type;", "template ", @@ -60,8 +62,20 @@ "}", "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)", + "template >", + "inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min(v1, v2); }", + "template >", + "inline TResult mmin(CRP(T, v), const Args &... args) { return min(v, mmin(args...)); }", + "template >", + "inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max(v1, v2); }", + "template >", + "inline TResult mmax(CRP(T, v), const Args &... args) { return max(v, mmax(args...)); }", + "inline ll gcd(ll a, ll b)", + "{", + " for (; b; swap(a, b)) a = a % b;", + " return a;", + "}", + "inline ll fpow(ll a, ll b, ll m)", "{", " ll r = 1;", " for (; b; b >>= 1, a = a * a % m)", @@ -74,7 +88,7 @@ "{", " $0", " return 0;", - "}" + "}", ] } } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a625c37 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "chrono": "cpp", + "type_traits": "cpp" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index d1bd675..586c074 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -5,6 +5,7 @@ "label": "g++.exe build active file", "command": "D:\\Programs\\MSYS2\\mingw64\\bin\\g++.exe", "args": [ + "-H", "-Wall", "-Winvalid-pch", "-I${workspaceFolder}\\.vscode", diff --git a/Codeforces/Problemset/1215D.cpp b/Codeforces/Problemset/1215D.cpp new file mode 100644 index 0000000..7480ab9 --- /dev/null +++ b/Codeforces/Problemset/1215D.cpp @@ -0,0 +1,76 @@ +#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 comtype = typename common_type::type; +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) + buf; + 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; + else if (ch == '-') + f = 0; + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + return x = f ? x : -x, true; +} +template > +inline bool read(T &x, Args &... args) { return read(x) && read(args...); } +template > +inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min(v1, v2); } +template > +inline TResult mmin(CRP(T, v), const Args &... args) { return min(v, mmin(args...)); } +template > +inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max(v1, v2); } +template > +inline TResult mmax(CRP(T, v), const Args &... args) { return max(v, mmax(args...)); } +inline ll gcd(ll a, ll b) +{ + for (; b; swap(a, b)) a = a % b; + return a; +} +inline 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 = 2e5 + 50; +char s[N]; +int main() +{ + int n, dif = 0; + scanf("%d%s", &n, s); + for (int i = 0, sp = n / 2; i < sp; i++) dif += s[i] == '?' ? 9 : (s[i] - '0') << 1; + for (int i = n / 2; i < n; i++) dif -= s[i] == '?' ? 9 : (s[i] - '0') << 1; + puts(dif ? "Monocarp" : "Bicarp"); + return 0; +} \ No newline at end of file diff --git a/Codeforces/Problemset/1217B.cpp b/Codeforces/Problemset/1217B.cpp new file mode 100644 index 0000000..2839b75 --- /dev/null +++ b/Codeforces/Problemset/1217B.cpp @@ -0,0 +1,86 @@ +#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 comtype = typename common_type::type; +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) + buf; + 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; + else if (ch == '-') + f = 0; + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + return x = f ? x : -x, true; +} +template > +inline bool read(T &x, Args &... args) { return read(x) && read(args...); } +template > +inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min(v1, v2); } +template > +inline TResult mmin(CRP(T, v), const Args &... args) { return min(v, mmin(args...)); } +template > +inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max(v1, v2); } +template > +inline TResult mmax(CRP(T, v), const Args &... args) { return max(v, mmax(args...)); } +inline ll gcd(ll a, ll b) +{ + for (; b; swap(a, b)) a = a % b; + return a; +} +inline 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; } +pair a[105]; +int main() +{ + int t, n, x; + read(t); + while (t--) + { + read(n, x); + for (int i = 0; i < n; i++) read(a[i].first, a[i].second); + x -= max_element(a, a + n)->first; + for (int i = 0; i < n; i++) a[i].first -= a[i].second; + int mx = max_element(a, a + n)->first; + if (x <= 0) + puts("1"); + else if (mx <= 0) + puts("-1"); + else + printf("%d\n", max(0, (x + mx - 1) / mx) + 1); + } + return 0; +} \ No newline at end of file diff --git a/Codeforces/Problemset/1217C.cpp b/Codeforces/Problemset/1217C.cpp new file mode 100644 index 0000000..0068f73 --- /dev/null +++ b/Codeforces/Problemset/1217C.cpp @@ -0,0 +1,82 @@ +#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 comtype = typename common_type::type; +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) + buf; + 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; + else if (ch == '-') + f = 0; + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + return x = f ? x : -x, true; +} +template > +inline bool read(T &x, Args &... args) { return read(x) && read(args...); } +template > +inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min(v1, v2); } +template > +inline TResult mmin(CRP(T, v), const Args &... args) { return min(v, mmin(args...)); } +template > +inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max(v1, v2); } +template > +inline TResult mmax(CRP(T, v), const Args &... args) { return max(v, mmax(args...)); } +inline ll gcd(ll a, ll b) +{ + for (; b; swap(a, b)) a = a % b; + return a; +} +inline 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 = 2e5 + 50; +char s[N]; +int main() +{ + int t; + read(t); + while (t--) + { + scanf("%s", s); + int n = strlen(s), ans = 0; + for (int l = 0; l < n; l++) + for (int r = l, cur = 0; r < l + 20 && r < n; r++) + if ((cur = cur << 1 | (s[r] - '0')) == r - l + 1) ans++; + printf("%d\n", ans); + } + return 0; +} \ No newline at end of file diff --git a/Codeforces/Problemset/1219C.cpp b/Codeforces/Problemset/1219C.cpp new file mode 100644 index 0000000..ab20713 --- /dev/null +++ b/Codeforces/Problemset/1219C.cpp @@ -0,0 +1,96 @@ +#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 comtype = typename common_type::type; +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) + buf; + 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; + else if (ch == '-') + f = 0; + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + return x = f ? x : -x, true; +} +template > +inline bool read(T &x, Args &... args) { return read(x) && read(args...); } +template > +inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min(v1, v2); } +template > +inline TResult mmin(CRP(T, v), const Args &... args) { return min(v, mmin(args...)); } +template > +inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max(v1, v2); } +template > +inline TResult mmax(CRP(T, v), const Args &... args) { return max(v, mmax(args...)); } +inline ll gcd(ll a, ll b) +{ + for (; b; swap(a, b)) a = a % b; + return a; +} +inline 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; +char s[N], ans[N]; +int main() +{ + int l; + scanf("%d%s", &l, s); + int n = strlen(s); + if (n % l) + for (int i = (n + l - 1) / l; i; i--) + for (int j = (putchar('1'), l - 1); j; j--) putchar('0'); + else if (count(s, s + n, '9') == n) + for (int i = n / l + 1; i; i--) + for (int j = (putchar('1'), l - 1); j; j--) putchar('0'); + else + { + memcpy(ans, s, l); + int flg = 0; + for (int sp = 0; sp < n && flg == 0; sp += l) + flg = memcmp(ans, s + sp, l); + if (flg <= 0) + { + ans[l - 1]++; + for (int i = l - 1; i; i--) + if (ans[i] > '9') + ans[i] -= 10, ans[i - 1]++; + } + for (int i = n / l; i; i--) + printf("%s", ans); + } + return 0; +} \ No newline at end of file diff --git a/Codeforces/Problemset/1221D.cpp b/Codeforces/Problemset/1221D.cpp new file mode 100644 index 0000000..c224dce --- /dev/null +++ b/Codeforces/Problemset/1221D.cpp @@ -0,0 +1,84 @@ +#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 comtype = typename common_type::type; +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) + buf; + 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; + else if (ch == '-') + f = 0; + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + return x = f ? x : -x, true; +} +template > +inline bool read(T &x, Args &... args) { return read(x) && read(args...); } +template > +inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min(v1, v2); } +template > +inline TResult mmin(CRP(T, v), const Args &... args) { return min(v, mmin(args...)); } +template > +inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max(v1, v2); } +template > +inline TResult mmax(CRP(T, v), const Args &... args) { return max(v, mmax(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 = 3e5 + 50; +ll a[N], b[N], dp[N][3]; +int main() +{ + int q, n; + read(q); + while (q--) + { + read(n); + for (int i = 0; i < n; i++) read(a[i]), read(b[i]); + memset(dp, 0x3f, sizeof(ll) * 3 * (n + 10)); + dp[0][0] = 0; + dp[0][1] = b[0]; + dp[0][2] = b[0] << 1; + for (int i = 1; i < n; i++) + for (int j = 0; j < 3; j++) + for (int k = 0; k < 3; k++) + if (a[i - 1] + j != a[i] + k) + dp[i][k] = min(dp[i][k], dp[i - 1][j] + k * b[i]); + printf("%lld\n", mmin(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])); + } + return 0; +} \ No newline at end of file diff --git a/Codeforces/Problemset/1223C.cpp b/Codeforces/Problemset/1223C.cpp new file mode 100644 index 0000000..279f31d --- /dev/null +++ b/Codeforces/Problemset/1223C.cpp @@ -0,0 +1,106 @@ +#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) + buf; + 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; + else if (ch == '-') + f = 0; + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + return x = f ? x : -x, 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 = 2e5 + 50; +int p[N]; +ll Q, n, X, A, Y, B, K; +ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } +bool check(int len) +{ + if (len <= 0) return true; + int ccnt = len / lcm(A, B); + int acnt = len / A - ccnt; + int bcnt = len / B - ccnt; + ll ans = -1, tmp = 0; + len = min(len, ccnt + acnt + bcnt); + for (int i = 0; i < len; i++) + { + if (i < ccnt) + tmp += p[i] * (X + Y); + else if (i < ccnt + acnt) + tmp += p[i] * X; + else if (i < ccnt + acnt + bcnt) + tmp += p[i] * Y; + if (tmp >= K) + { + ans = i + 1; + break; + } + } + return ans == -1; +} +int main() +{ + read(Q); + while (Q--) + { + read(n); + for (int i = 0; i < n; i++) read(p[i]), p[i] /= 100; + read(X, A, Y, B, K); + if (X < Y) swap(A, B), swap(X, Y); + sort(p, p + n, greater()); + if (check(n)) + puts("-1"); + else + { + int L = 0, R = n + 1, M; + while (R - L > 1) + if (check(M = (L + R) >> 1)) + L = M; + else + R = M; + M = L; + if (check(M)) M = R; + printf("%d\n", M); + } + } + return 0; +} \ No newline at end of file diff --git a/Codeforces/Problemset/1225C.cpp b/Codeforces/Problemset/1225C.cpp new file mode 100644 index 0000000..4b28558 --- /dev/null +++ b/Codeforces/Problemset/1225C.cpp @@ -0,0 +1,60 @@ +#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) + buf; + 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; + else if (ch == '-') + f = 0; + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + return x = f ? x : -x, 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; } +int main() +{ + int n, p; + read(n, p); + for (int i = 1; i < 32; i++) + if (i <= n - p * i && __builtin_popcount(n - p * i) <= i) + return printf("%d", i), 0; + return puts("-1"), 0; +} \ No newline at end of file diff --git a/Codeforces/Problemset/1228C.cpp b/Codeforces/Problemset/1228C.cpp new file mode 100644 index 0000000..3ca31e0 --- /dev/null +++ b/Codeforces/Problemset/1228C.cpp @@ -0,0 +1,76 @@ +#define _CRT_SECURE_NO_WARNINGS +#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING +#include +using namespace std; +#define CRP(t, x) const t &x +#define OPL(t, x) bool operator<(CRP(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 long long ll, i64; +const int N = 1e5 + 50, mod = 1e9 + 7; +bool notPrime[N]; +int primes[N], pcnt; +ll g(ll x, ll p) +{ + ll xx = x; + if (p == 1) return 1; + ll r = 1; + while (x % r == 0) r = r * p % mod; + if (r / p > 1) printf("g(%lld, %lld)\n", xx, p); + return r / p; +} +ll f(ll x, ll y) +{ + ll r = 1; + for (int i = 0; i < pcnt && x >= primes[pcnt]; i++) + if (x % primes[i] == 0) + { + r = r * g(y, primes[i]) % mod; + while (x % primes[i] == 0) x /= primes[i]; + } + if (x != 1) r = r * g(y, x) % mod; + return r; +} +ll fpow(ll a, ll b) +{ + ll r = 1; + for (; b; b >>= 1, a = a * a % mod) + if (b & 1) + r = r * a % mod; + return r; +} +int main() +{ + for (ll i = 2; i < N; i++) + if (!notPrime[i]) + for (ll j = (primes[pcnt++] = i, i * i); j < N; j += i) + notPrime[j] = true; + ll x, n; + cin >> x >> n; + ll xx = x; + vector v; + for (int i = 0; i < pcnt && x >= primes[pcnt]; i++) + if (x % primes[i] == 0) + { + v.push_back(primes[i]); + while (x % primes[i] == 0) x /= primes[i]; + } + if (x != 1) v.push_back(x); + x = xx; + ll ans = 1; + for (ll p : v) + { + ll cur = 1, tmp = 1; + while (n / p >= cur) + cur = cur * p, tmp = fpow(p, n / cur) * tmp % mod; + ans = ans * tmp % mod; + } + cout << ans; + return 0; +} \ No newline at end of file diff --git a/Codeforces/Problemset/1234D.cpp b/Codeforces/Problemset/1234D.cpp new file mode 100644 index 0000000..4cc419e --- /dev/null +++ b/Codeforces/Problemset/1234D.cpp @@ -0,0 +1,85 @@ +#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) + buf; + 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; + else if (ch == '-') + f = 0; + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + return x = f ? x : -x, 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; +char s[N]; +set ss[26]; +int main() +{ + scanf("%s", s+1); + int n = strlen(s+1); + for (int i = 1; i <= n; i++) ss[s[i] - 'a'].insert(i); + read(n); + for (int op, x, y; n--;) + { + read(op); + if (op == 1) + { + read(x); + scanf("%s", &y); + ss[s[x] - 'a'].erase(x); + s[x] = y; + ss[s[x] - 'a'].insert(x); + } + if (op == 2) + { + read(x, y); + int cnt = 0; + for (const auto &s : ss) + { + auto it = s.lower_bound(x); + if (it != s.end() && *it <= y) cnt++; + } + printf("%d\n", cnt); + } + } + return 0; +} \ No newline at end of file diff --git a/Codeforces/Problemset/1237C1.cpp b/Codeforces/Problemset/1237C1.cpp new file mode 100644 index 0000000..e0668c9 --- /dev/null +++ b/Codeforces/Problemset/1237C1.cpp @@ -0,0 +1,77 @@ +#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) + buf; + 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; + else if (ch == '-') + f = 0; + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + return x = f ? x : -x, 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; } +struct P +{ + ll x, y, z; + bool vis; + ll dis(CRP(P, rhs)) const { return (x - rhs.x) * (x - rhs.x) + (y - rhs.y) * (y - rhs.y) + (z - rhs.z) * (z - rhs.z); } +} ps[2050]; +int main() +{ + int n; + read(n); + for (int i = 1; i <= n; i++) read(ps[i].x, ps[i].y, ps[i].z); + for (;;) + { + int fst = 0; + for (int i = 1; i <= n && !fst; i++) + if (!ps[i].vis) fst = i; + if (!fst) break; + int sec = fst + 1; + while (ps[sec].vis) sec++; + for (int i = sec + 1; i <= n; i++) + if (!ps[i].vis && ps[fst].dis(ps[sec]) > ps[fst].dis(ps[i])) sec = i; + printf("%d %d\n", fst, sec); + ps[fst].vis = ps[sec].vis = true; + } + return 0; +} \ No newline at end of file diff --git a/Codeforces/Problemset/1238C.cpp b/Codeforces/Problemset/1238C.cpp new file mode 100644 index 0000000..0a5373c --- /dev/null +++ b/Codeforces/Problemset/1238C.cpp @@ -0,0 +1,70 @@ +#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) + buf; + 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; + else if (ch == '-') + f = 0; + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + return x = f ? x : -x, 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 = 2e5 + 50; +int p[N]; +int main() +{ + int q, h, n; + read(q); + while (q--) + { + read(h, n); + for (int i = 0; i < n; i++) read(p[i]); + int ans = 0, lf = 0; + for (int i = 0; i < n; i++) + if (i > 0 && p[i - 1] > p[i] + 1) + ans += (i - lf) & 1 ^ (lf == 0), lf = i; + if (p[n - 1] > 1) ans += (n - lf) & 1 ^ (lf == 0); + printf("%d\n", ans); + } + return 0; +} \ No newline at end of file diff --git a/cf1228/C.cpp b/cf1228/C.cpp index e7661f7..3ca31e0 100644 --- a/cf1228/C.cpp +++ b/cf1228/C.cpp @@ -63,9 +63,6 @@ int main() } if (x != 1) v.push_back(x); x = xx; - /*ll ansp = 1; - for (ll i = 1; i <= n; i++) ansp = ansp * f(x, i) % mod; - cout << ansp << endl;*/ ll ans = 1; for (ll p : v) { diff --git a/tmpl.cpp b/tmpl.cpp index 6775efa..777489d 100644 --- a/tmpl.cpp +++ b/tmpl.cpp @@ -15,6 +15,8 @@ using namespace std; #define IFD if (_DEBUG) typedef int64_t ll, i64; typedef uint64_t ull, u64; +template +using comtype = typename common_type::type; template using enable_if_arithmetic = typename enable_if::value>::type; template @@ -39,8 +41,20 @@ inline bool read(T &x) } 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) +template > +inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min(v1, v2); } +template > +inline TResult mmin(CRP(T, v), const Args &... args) { return min(v, mmin(args...)); } +template > +inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max(v1, v2); } +template > +inline TResult mmax(CRP(T, v), const Args &... args) { return max(v, mmax(args...)); } +inline ll gcd(ll a, ll b) +{ + for (; b; swap(a, b)) a = a % b; + return a; +} +inline ll fpow(ll a, ll b, ll m) { ll r = 1; for (; b; b >>= 1, a = a * a % m) @@ -51,6 +65,6 @@ constexpr double eps = 1e-8; inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; } int main() { - + $0 return 0; } \ No newline at end of file