mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-08-21 18:52:07 +00:00
update
This commit is contained in:
parent
5b1e8bdc14
commit
5505498421
@ -84,7 +84,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ll ans = (e1 + emax) % MOD;
|
ll ans = (e1 + emax) % MOD;
|
||||||
cout << ((ans^1)|ans) << endl;
|
cout << ans << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -1,26 +1,23 @@
|
|||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using ll = int64_t;
|
using ll = long long;
|
||||||
static inline constexpr ll MOD = 1e9+7;
|
|
||||||
|
|
||||||
static inline constexpr ll fpow(ll b, ll e, ll mod) {
|
constexpr inline static ll mod = 1e9+7;
|
||||||
|
|
||||||
|
constexpr inline static ll fpow(ll base, ll exp, ll m) {
|
||||||
|
base %= m;
|
||||||
ll res = 1;
|
ll res = 1;
|
||||||
b %= mod;
|
while (exp) {
|
||||||
while (e) {
|
if (exp & 1) res = (res * base) % m;
|
||||||
if (e & 1)
|
base = (base * base) % m;
|
||||||
res = (res * b) % mod;
|
exp >>= 1;
|
||||||
b = (b * b) % mod;
|
|
||||||
e >>= 1;
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
ios_base::sync_with_stdio(false);
|
ios::sync_with_stdio(false);
|
||||||
cin.tie(nullptr);
|
cin.tie(nullptr);
|
||||||
int T;
|
int T;
|
||||||
cin >> T;
|
cin >> T;
|
||||||
@ -28,69 +25,38 @@ int main() {
|
|||||||
string s;
|
string s;
|
||||||
ll p;
|
ll p;
|
||||||
cin >> s >> p;
|
cin >> s >> p;
|
||||||
int n = s.size();
|
ll n = s.size();
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
cout << "1\n";
|
cout << "1\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
ll inv10 = fpow(10, p-2, p);
|
||||||
|
unordered_map<ll, ll> cnt, cnt1;
|
||||||
|
cnt[0] = 1;
|
||||||
|
cnt1[0] = 1;
|
||||||
|
ll total = 1;
|
||||||
|
ll h = 0;
|
||||||
|
ll cur_inv = 1;
|
||||||
|
ll ans = 0;
|
||||||
|
|
||||||
vector<ll> p10(n+1);
|
for (int i = 0; i < n; i++) {
|
||||||
p10[0] = 1;
|
ll d = s[i] - '0';
|
||||||
for (int i = 1; i <= n; i++) {
|
cur_inv = (cur_inv * inv10) % p;
|
||||||
p10[i] = (p10[i-1] * 10) % p;
|
h = (h + d * cur_inv) % p;
|
||||||
|
// if (h < 0) h += p;
|
||||||
|
|
||||||
|
ll dp1_cur = cnt[h];
|
||||||
|
ll dp0_cur = (total - cnt1[h] + mod) % mod;
|
||||||
|
|
||||||
|
if (i == n-1) {
|
||||||
|
ans = (dp0_cur + dp1_cur) % mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
ll inv10b = fpow(10, p-2, p);
|
cnt[h] = (cnt[h] + dp0_cur + dp1_cur) % mod;
|
||||||
|
cnt1[h] = (cnt1[h] + dp1_cur) % mod;
|
||||||
vector<ll> inv10(n+1);
|
total = (total + dp1_cur) % mod;
|
||||||
inv10[0] = 1;
|
|
||||||
for (int i = 1; i <= n; i++) {
|
|
||||||
inv10[i] = (inv10[i-1] * inv10b) % p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<ll> pre(n+1, 0);
|
|
||||||
for (int i = 1; i <= n; i++) {
|
|
||||||
pre[i] = (pre[i-1] * 10 + (s[i-1] - '0')) % p;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<ll> val(n+1);
|
|
||||||
for (int i = 0; i <= n; i++) {
|
|
||||||
val[i] = pre[i] * inv10[i] % p; //
|
|
||||||
if (val[i] < 0) val[i] += p;
|
|
||||||
}
|
|
||||||
|
|
||||||
unordered_map<ll, pair<ll, ll>> dic;
|
|
||||||
ll tot1 = 1;
|
|
||||||
dic[val[0]] = make_pair(1, 1);
|
|
||||||
|
|
||||||
ll ndp0 = 0, ndp1 = 0;
|
|
||||||
for (int i = 1; i <= n; i++) {
|
|
||||||
ll v = val[i];
|
|
||||||
ll s01 = 0, s1 = 0;
|
|
||||||
auto it = dic.find(v);
|
|
||||||
if (it != dic.end()) {
|
|
||||||
s01 = it->second.first;
|
|
||||||
s1 = it->second.second;
|
|
||||||
}
|
|
||||||
|
|
||||||
ndp1 = s01 % MOD;
|
|
||||||
ndp0 = (tot1 - s1) % MOD;
|
|
||||||
if (ndp0 < 0)
|
|
||||||
ndp0 += MOD;
|
|
||||||
|
|
||||||
tot1 = (tot1 + ndp1) % MOD;
|
|
||||||
|
|
||||||
ll add01 = (ndp0 + ndp1) % MOD;
|
|
||||||
ll add1 = ndp1 % MOD;
|
|
||||||
if (dic.find(v) != dic.end()) {
|
|
||||||
dic[v].first = (dic[v].first + add01) % MOD;
|
|
||||||
dic[v].second = (dic[v].second + add1) % MOD;
|
|
||||||
} else {
|
|
||||||
dic[v] = make_pair(add01, add1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ll ans = (ndp0 + ndp1) % MOD;
|
|
||||||
cout << ans << '\n';
|
cout << ans << '\n';
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
97
src/7/30/U281313d.cpp
Normal file
97
src/7/30/U281313d.cpp
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
#include <cstdint>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using ll = int64_t;
|
||||||
|
static inline constexpr ll MOD = 1e9+7;
|
||||||
|
|
||||||
|
static inline constexpr ll fpow(ll b, ll e, ll mod) {
|
||||||
|
ll res = 1;
|
||||||
|
b %= mod;
|
||||||
|
while (e) {
|
||||||
|
if (e & 1)
|
||||||
|
res = (res * b) % mod;
|
||||||
|
b = (b * b) % mod;
|
||||||
|
e >>= 1;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
ios_base::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
int T;
|
||||||
|
cin >> T;
|
||||||
|
while (T--) {
|
||||||
|
string s;
|
||||||
|
ll p;
|
||||||
|
cin >> s >> p;
|
||||||
|
int n = s.size();
|
||||||
|
if (n == 0) {
|
||||||
|
cout << "1\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<ll> p10(n+1);
|
||||||
|
p10[0] = 1;
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
p10[i] = (p10[i-1] * 10) % p;
|
||||||
|
}
|
||||||
|
|
||||||
|
ll inv10b = fpow(10, p-2, p);
|
||||||
|
|
||||||
|
vector<ll> inv10(n+1);
|
||||||
|
inv10[0] = 1;
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
inv10[i] = (inv10[i-1] * inv10b) % p;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<ll> pre(n+1, 0);
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
pre[i] = (pre[i-1] * 10 + (s[i-1] - '0')) % p;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<ll> val(n+1);
|
||||||
|
for (int i = 0; i <= n; i++) {
|
||||||
|
val[i] = pre[i] * inv10[i] % p; //
|
||||||
|
if (val[i] < 0) val[i] += p;
|
||||||
|
}
|
||||||
|
|
||||||
|
unordered_map<ll, pair<ll, ll>> dic;
|
||||||
|
ll tot1 = 1;
|
||||||
|
dic[val[0]] = make_pair(1, 1);
|
||||||
|
|
||||||
|
ll ndp0 = 0, ndp1 = 0;
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
ll v = val[i];
|
||||||
|
ll s01 = 0, s1 = 0;
|
||||||
|
auto it = dic.find(v);
|
||||||
|
if (it != dic.end()) {
|
||||||
|
s01 = it->second.first;
|
||||||
|
s1 = it->second.second;
|
||||||
|
}
|
||||||
|
|
||||||
|
ndp1 = s01 % MOD;
|
||||||
|
ndp0 = (tot1 - s1) % MOD;
|
||||||
|
if (ndp0 < 0)
|
||||||
|
ndp0 += MOD;
|
||||||
|
|
||||||
|
tot1 = (tot1 + ndp1) % MOD;
|
||||||
|
|
||||||
|
ll add01 = (ndp0 + ndp1) % MOD;
|
||||||
|
ll add1 = ndp1 % MOD;
|
||||||
|
if (dic.find(v) != dic.end()) {
|
||||||
|
dic[v].first = (dic[v].first + add01) % MOD;
|
||||||
|
dic[v].second = (dic[v].second + add1) % MOD;
|
||||||
|
} else {
|
||||||
|
dic[v] = make_pair(add01, add1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ll ans = (ndp0 + ndp1) % MOD;
|
||||||
|
cout << ans << '\n';
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user