Submit Info #21869

Problem Lang User Status Time Memory
Queue Operate All Composite cpp (anonymous) AC 124 ms 4.84 MiB

ケース詳細
Name Status Time Memory
example_00 AC 2 ms 0.67 MiB
example_01 AC 1 ms 0.67 MiB
large_max_00 AC 114 ms 3.49 MiB
large_max_01 AC 115 ms 3.42 MiB
large_min_00 AC 124 ms 2.17 MiB
large_min_01 AC 124 ms 2.17 MiB
large_triangle_00 AC 123 ms 2.55 MiB
large_triangle_01 AC 123 ms 2.49 MiB
max_random_00 AC 105 ms 4.84 MiB
max_random_01 AC 105 ms 4.80 MiB
max_random_02 AC 106 ms 4.80 MiB
random_00 AC 95 ms 2.30 MiB
random_01 AC 111 ms 2.62 MiB
random_02 AC 12 ms 0.81 MiB
small_00 AC 1 ms 0.61 MiB
small_01 AC 0 ms 0.64 MiB
small_02 AC 1 ms 0.67 MiB
small_03 AC 1 ms 0.65 MiB
small_04 AC 1 ms 0.67 MiB

#pragma GCC optimization ("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4") #include <bits/stdc++.h> using namespace std; int main() { // freopen("input.txt", "r", stdin); int q; scanf("%d", &q); const int MOD = 998244353; function <int(int)> inv = [&](int x) { return x == 1 ? 1 : 1LL * (MOD - MOD / x) * inv(MOD % x) % MOD; }; queue < pair <int, int> > que; pair <int, int> cur = {1, 0}; int prod = 1; while (q--) { int type; scanf("%d", &type); if (type == 0) { int a, b; scanf("%d%d", &a, &b); que.push(make_pair(a, b)); cur.first = 1LL * cur.first * a % MOD; cur.second = (1LL * cur.second * a + b) % MOD; prod = 1LL * prod * a % MOD; } else if (type == 1) { int c = que.front().first, d = que.front().second; que.pop(); int ic = inv(c); prod = 1LL * prod * ic % MOD; cur.first = 1LL * cur.first * ic % MOD; if ((cur.second -= 1LL * d * prod % MOD) < 0) { cur.second += MOD; } } else { int x; scanf("%d", &x); printf("%d\n", (int)((1LL * cur.first * x + cur.second) % MOD)); } } return 0; }