結果
| 問題 | No.3439 [Cherry 8th Tune] どの頂点にいた頃に戻りたいのか? |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-23 23:38:45 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 4,502 bytes |
| 記録 | |
| コンパイル時間 | 3,919 ms |
| コンパイル使用メモリ | 348,676 KB |
| 実行使用メモリ | 813,756 KB |
| 最終ジャッジ日時 | 2026-01-23 23:38:53 |
| 合計ジャッジ時間 | 8,530 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | MLE * 1 -- * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
#ifdef Doludu
template <typename T>
ostream& operator << (ostream &o, vector <T> vec) {
o << "{"; int f = 0;
for (T i : vec) o << (f++ ? " " : "") << i;
return o << "}";
}
void bug__(int c, auto ...a) {
cerr << "\e[1;" << c << "m";
(..., (cerr << a << " "));
cerr << "\e[0m" << endl;
}
#define bug_(c, x...) bug__(c, __LINE__, "[" + string(#x) + "]", x)
#define bug(x...) bug_(32, x)
#define bugv(x...) bug_(36, vector(x))
#define safe bug_(33, "safe")
#else
#define bug(x...) void(0)
#define bugv(x...) void(0)
#define safe void(0)
#endif
const int mod = 998244353, N = 1 << 20, G = 3;
int add(int a, int b) { a += b; if (a >= mod) a -= mod; return a; }
int sub(int a, int b) { a -= b; if (a < 0) a += mod; return a; }
int mul(int a, int b) { return 1ll * a * b % mod; }
int Pow(int a, int b) { int ans = 1; for (; b; b >>= 1, a = mul(a, a)) if (b & 1) ans = mul(ans, a); return ans; }
// mul, add, sub, Pow
struct NTT {
int w[N];
NTT() {
int dw = Pow(G, (mod - 1) / N);
w[0] = 1;
for (int i = 1; i < N; ++i)
w[i] = mul(w[i - 1], dw);
} // 0 <= a[i] < P
void operator()(vector<int>& a, bool inv = false) {
int n = sz(a);
for (int j = 1, x = 0; j < n - 1; ++j) {
for (int k = n >> 1; (x ^= k) < k; k >>= 1);
if (j < x) swap(a[x], a[j]);
}
for (int L = 2; L <= n; L <<= 1) {
int dx = N / L, dl = L >> 1;
for (int i = 0; i < n; i += L) {
for (int j = i, x = 0; j < i + dl; ++j, x += dx) {
int tmp = mul(a[j + dl], w[x]);
a[j + dl] = sub(a[j], tmp);
a[j] = add(a[j], tmp);
}
}
}
if (inv) {
reverse(1 + all(a));
int invn = Pow(n, mod - 2);
for (int i = 0; i < n; ++i)
a[i] = mul(a[i], invn);
}
}
} ntt;
typedef vector<int> Poly;
Poly Mul(Poly a, Poly b, int bound = N) {
int m = sz(a) + sz(b) - 1, n = 1;
while (n < m) n <<= 1;
a.resize(n), b.resize(n);
ntt(a), ntt(b);
for (int i = 0; i < n; ++i) a[i] = mul(a[i], b[i]);
ntt(a, true), a.resize(min(m, bound));
return a;
} // 8e2e8b
Poly calc2(int l, int r, vector <Poly> &p) {
if (r - l == 1) return p[l];
return Mul(calc2(l, l + r >> 1, p), calc2(l + r >> 1, r, p));
}
Poly calc(vector <Poly> p) {
return calc2(0, sz(p), p);
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, q;
cin >> n >> q;
string s;
cin >> s;
s = "#" + s;
vector <int> w(n + 1);
for (int i = 0; i <= n; ++i) cin >> w[i];
while (q--) {
int op; cin >> op;
if (op == 1) {
int l, r;
cin >> l >> r, ++r;
for (int i = l; i < r; ++i) s[i] ^= 'G' ^ 'B';
} else if (op == 2) {
int l, r, x; cin >> l >> r >> x, ++r;
for (int i = l; i < r; ++i) w[i] += x;
} else {
int v, k; cin >> v >> k;
vector <int> a(k);
for (int i = 0; i < k; ++i) cin >> a[i];
int down = 0, up = 0;
for (int i = 0; i < v; ++i) {
down += w[i];
}
int st = v;
while (st <= n) {
up += w[st];
if (s[st] == 'B') break;
st++;
}
int prob = mul(up, Pow(up + down, mod - 2));
int base = 0;
for (int x : a) if (x >= v) {
if (x <= st) base++;
}
vector <Poly> res;
vector <int> tmp(n + 1), has(n + 1);
for (int x : a) has[x] = 1;
for (int i = st + 1, j = st; i <= n; ++i) {
if (has[i]) tmp[j]++;
if (s[i] == 'B') j = i;
}
bug(up, down);
bug(base);
for (int i = 1; i <= n; ++i) {
if (tmp[i]) {
bug(tmp[i]);
Poly tmp2(tmp[i] + 1);
tmp2.back() = prob;
tmp2[0] = sub(1, prob);
res.pb(tmp2);
}
}
auto ans = calc(res);
for (int i = 0; i <= k; ++i) {
if (i < base) cout << 0 << " \n"[i == k];
else if (i - base < sz(ans)) cout << ans[i - base] << " \n"[i == k];
else cout << 0 << " \n"[i == k];
}
}
}
}