1 条题解
-
0
数学计算(Math Calculation) 题解
思路分析
按题目要求使用对应数据结构与算法模拟/递推求解,注意数据范围边界与时间复杂度。
参考代码
#include <iostream> #include <vector> using namespace std; void solve() { int Q; long long M; cin >> Q >> M; int B = 1; while (B < Q) B <<= 1; vector<long long> tree(2 * B, 1 % M); auto update = [&](int pos, long long val) { int p = B + pos - 1; tree[p] = val % M; for (p >>= 1; p >= 1; p >>= 1) { tree[p] = (tree[p << 1] * tree[p << 1 | 1]) % M; } }; for (int i = 1; i <= Q; ++i) { int op; long long x; cin >> op >> x; if (op == 1) update(i, x); else update((int)x, 1); cout << tree[1] << "\n"; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; if (!(cin >> t)) return 0; while (t--) solve(); return 0; }
- 1
信息
- ID
- 8656
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者