update ucpc2026

This commit is contained in:
2026-07-11 09:38:32 +09:00
parent 7176febe54
commit 0b8c2864ae
20 changed files with 329 additions and 163 deletions
+8 -18
View File
@@ -1,32 +1,26 @@
namespace GMS {
template<ll mod>
ll pow(ll a, ll b) {
a %= mod;
ll ret = 1;
ll ret = 1; a %= mod;
while(b != 0) {
if(b&1) ret = ret*a%mod;
a = a*a%mod; b>>=1;
a = a*a%mod, b/=2;
}
return ret;
}
template<ll mod, ll w>
void ntt(vector<ll> &a, bool inv = false) {
void ntt(vl& a, bool inv = false) {
static_assert(mod <= (ll)2e9, "mod should be less than 2e9");
int n = a.size(), j = 0;
assert((n & -n) == n && (mod-1)%n == 0);
for(int i=1; i<n; i++) {
int bit = (n >> 1);
while(j >= bit) {
j -= bit;
bit >>= 1;
}
j += bit;
if(i < j) swap(a[i], a[j]);
int bit = n/2;
while(j >= bit) {j -= bit; bit >>= 1;}
j += bit; if(i < j) swap(a[i], a[j]);
}
static vector<ll> root[30], iroot[30];
static vl root[30], iroot[30];
for(int st=1; (1<<st) <= n; st++) {
if(root[st].empty()) {
ll t = pow<mod>(w, (mod-1)/(1<<st));
@@ -46,7 +40,6 @@ void ntt(vector<ll> &a, bool inv = false) {
}
vector<ll>* r = (inv?root:iroot);
for(int st = 1; (1<<st) <= n; st++) {
int i = 1<<st; //int step = n / i;
for(int j=0; j<n; j+=i) {
@@ -70,12 +63,9 @@ vl conv(vl A, vl B) {
A.resize(t); B.resize(t);
ntt<mod, w>(A); ntt<mod, w>(B);
fors(i, 0, t-1) A[i] = A[i]*B[i]%mod;
ntt<mod, w>(A, true);
A.resize(n+m-1);
return A;
return A.resize(n+m-1), A;
}
} // namespace GMS