A、夹娃娃
签到题,前缀和的模板题,没什么坑点,极限都不炸
#pragma GCC target("avx,sse2,sse3,sse4,popcnt") #pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math") #include <bits/stdc++.h> using namespace std; #define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) #define all(vv) vv.begin(), vv.end() #define endl "\n" typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll MOD = 1e9 + 7; inline ll read() { ll s = 0, w = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') w = -1; for (; isdigit(ch); ch = getchar()) s = (s << 1) + (s << 3) + (ch ^ 48); return s * w; } inline void write(ll x) { if (!x) { putchar('0'); return; } char F[40]; ll tmp = x > 0 ? x : -x; if (x < 0)putchar('-'); int cnt = 0; while (tmp > 0) { F[cnt++] = tmp % 10 + '0'; tmp /= 10; } while (cnt > 0)putchar(F[--cnt]); } inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll qpow(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans *= a; b >>= 1; a *= a; } return ans; } ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; } inline int lowbit(int x) { return x & (-x); } const int N = 1e5 + 7; ll a[N]; int main() { int n = read(), m = read(); for (int i = 1; i <= n; ++i) { a[i] = read(); a[i] += a[i - 1]; } while (m--) { int l = read(), r = read(); write(a[r] - a[l - 1]), putchar(10); } return 0; }
B、莫的难题
进制转换,稍微列举一下前面的一些数你就会发现,第1位的是之下,第2位的之下,第3位的之下,把熟悉的10进制改成五进制了!不过有个坑点五进制开始是1,而不是0,记得计算进制减掉一个1,最后放进一个栈里面去输出即可,非常优秀的题目阿。就是题目表示的有点不明确,求第小的数。线性求下阶乘和逆元就行了。
1 2 3 5 9 //5个数 11 12 13 15 19 21 22 23 25 29 31 32 33 35 39 ... 91 92 93 95 99 //5*5+5个数 111 ... // 5^3+5^2+5个数
#pragma GCC target("avx,sse2,sse3,sse4,popcnt") #pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math") #include <bits/stdc++.h> using namespace std; #define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) #define all(vv) vv.begin(), vv.end() #define endl "\n" typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll MOD = 1e9 + 7; inline ll read() { ll s = 0, w = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') w = -1; for (; isdigit(ch); ch = getchar()) s = (s << 1) + (s << 3) + (ch ^ 48); return s * w; } inline void write(ll x) { if (!x) { putchar('0'); return; } char F[40]; ll tmp = x > 0 ? x : -x; if (x < 0)putchar('-'); int cnt = 0; while (tmp > 0) { F[cnt++] = tmp % 10 + '0'; tmp /= 10; } while (cnt > 0)putchar(F[--cnt]); } inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll qpow(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans *= a; b >>= 1; a *= a; } return ans; } ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; } inline int lowbit(int x) { return x & (-x); } const int N = 100 + 7; string s = "12359"; ll jc[N], inv[N]; int ans[N]; ll C(int n, int m) { return jc[n] * inv[n - m] % MOD * inv[m] % MOD; } int main() { jc[0] = 1; for (int i = 1; i < N; ++i) jc[i] = jc[i - 1] * i % MOD; inv[N - 1] = qpow(jc[N - 1], MOD - 2, MOD); for (int i = N - 2; ~i; --i) inv[i] = inv[i + 1] * (i + 1) % MOD; int T = read(); while (T--) { int n = read(), m = read(); int c = C(n, m); stack<int> st; while (c > 0) { --c; st.push(c % 5); c /= 5; } while (st.size()) printf("%c", s[st.top()]), st.pop(); putchar(10); } return 0; }
C、不平衡数组
我写的code有点问题,先放着,等我去康康正解再码正确的代码把。
待补
D、数列统计
写个暴力dfs应该很好写吧,IOI先拿10分,再看看能不能找到规律)没办法菜鸡数论不厉害,只能这样解题了
ll ans; int n, l; void dfs(int maxi, int len) { if (!len) { ++ans; return; } for (int i = maxi; i; --i) dfs(i, len - 1); } int main() { int T = read(); while (T--) { n = read(), l = read(); ans = 0; dfs(n, l - 1); write(ans), putchar(10); } return 0; } /* 1 1: 1 1 2: 1 1 3: 1 1 4: 1 2 2: 2 2 3: 3 2 4: 4 3 3: 6 3 4: 10 4 4: 20 10 10: 48620 */
打表出来,你会发现,n,l交换顺序答案是不变的,还有一点是n,l相等的时候是中心二项式的系数。那居然看到了二项式肯定往组合数猜,而且题目给的所以计算必须快,dp肯定是走不通的,这时候一位队友奇迹般地推出的公式救了我们,直接得到答案就是,zqf大佬天下无双!!
#pragma GCC target("avx,sse2,sse3,sse4,popcnt") #pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math") #include <bits/stdc++.h> using namespace std; #define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) #define all(vv) vv.begin(), vv.end() #define endl "\n" typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll MOD = 911451407; inline ll read() { ll s = 0, w = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') w = -1; for (; isdigit(ch); ch = getchar()) s = (s << 1) + (s << 3) + (ch ^ 48); return s * w; } inline void write(ll x) { if (!x) { putchar('0'); return; } char F[40]; ll tmp = x > 0 ? x : -x; if (x < 0)putchar('-'); int cnt = 0; while (tmp > 0) { F[cnt++] = tmp % 10 + '0'; tmp /= 10; } while (cnt > 0)putchar(F[--cnt]); } inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll qpow(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans *= a; b >>= 1; a *= a; } return ans; } ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; } inline int lowbit(int x) { return x & (-x); } const int N = 2e6 + 7; ll jc[N], inv[N]; ll C(int n, int m) { return jc[n] * inv[n - m] % MOD * inv[m] % MOD; } int main() { jc[0] = 1; for (int i = 1; i < N; ++i) jc[i] = jc[i - 1] * i % MOD; inv[N - 1] = qpow(jc[N - 1], MOD - 2, MOD); for (int i = N - 2; i; --i) inv[i] = inv[i + 1] * (i + 1) % MOD; int t = read(); while (t--) { ll l = read(), x = read(); ll ans = jc[x + l - 2] * inv[x - 1] % MOD * inv[l - 1] % MOD; write(ans), putchar(10); } }