voidapply(const Tag &t){ if (!t.need_apply) return; ll st = 0; if (!op_ls.empty() && !t.op_ls.empty()) { if (op_ls.back().type == t.op_ls[0].type) { op_ls.back().num += t.op_ls[0].num; st = 1; } } for (int i = st; i < t.op_ls.size(); ++i) { if (t.op_ls[i].type == BackOp) { op_ls.clear(); op_ls.push_back(t.op_ls[i]); } else { op_ls.push_back(t.op_ls[i]); } } need_apply = true; } voidclear(){ op_ls.clear(); need_apply=false; } };
structInfo { // 注意啊,这里除了 L 和 R 以外的所有你所添加的东西,你都要好好想一想其初值是什么。 // 不过我们其实改进了这个 query 函数,所以说如果说你给的这个数组当中所有的值都是所有的值都是有的话,其实不用考虑初值。 // 如果一定要赋初值的话,注意就是 sum 类的都不要赋 infinite 然后只有 max 和 min 的你要好好想想。 ll l = 0, r = 0, mn = 0, orgin_mn = 0;
// Lucas 定理递归求解,复用 CC 模板 inline ll lucas(ll a, ll b){ if (a < mod && b < mod) returnCC(a, b); returnCC(a % mod, b % mod) * lucas(a / mod, b / mod) % mod; }
voidsolve(){ ll a, b; cin >> a >> b >> mod; // 每次 mod 发生变化,必须重置初始化标记 initialized = false; cout << lucas(a, b) << '\n'; }
intmain(){ // 优化输入输出 ios::sync_with_stdio(false); cin.tie(nullptr); int n; if (cin >> n) { while (n--) { solve(); } } return0; }
// 首先按顺序分配给所有存在的“早段” for (int i = 1; i <= n; i++) { if (x[i] > 0) { early_val[i] = current_val++; } } // 然后按顺序分配给所有存在的“晚段” for (int i = 1; i <= n; i++) { longlong y = k - x[i]; if (y > 0) { late_val[i] = current_val++; } }
// 按要求输出 n*k 个序列数字 bool first = true; for (int i = 1; i <= n; i++) { // 输出早段的数字 for (int j = 0; j < x[i]; j++) { if (!first) cout << " "; cout << early_val[i]; first = false; } // 输出晚段的数字 longlong y = k - x[i]; for (int j = 0; j < y; j++) { if (!first) cout << " "; cout << late_val[i]; first = false; } } cout << "\n"; }
\begin{minted}{cpp} #include <iostream> #include <vector> #include <algorithm> using namespace std; void solve() { long long n, m, k; if (!(cin >> n >> m >> k)) return; // w 为获胜所需的最少场数 long long w = (1LL * k * k) / 2 + 1; // R 为推导出的常数界限 long long R = 1LL * k * k - w; vector<long long> x(n + 1); // 贪心确定 1 号骰子的最大早段容量 x[1] = k - (w + k - 1) / k; // 递推贪心确定后续骰子的最大早段容量 for (int i = 2; i <= n; i++) { long long denom = k - x[i - 1]; if (denom == 0) { x[i] = k; } else { x[i] = min((long long)k, R / denom); } } // current_val 用于按顺序分配递增的数值 long long current_val = 0; vector<long long> early_val(n + 1, -1); vector<long long> late_val(n + 1, -1); // 阶段一:按顺序给所有骰子的“早段”分配小数值 for (int i = 1; i <= n; i++) { if (x[i] > 0) { early_val[i] = current_val++; } } // 阶段二:按顺序给所有骰子的“晚段”分配大数值 for (int i = 1; i <= n; i++) { long long y = k - x[i]; if (y > 0) { late_val[i] = current_val++; } } // 按照 1 到 n 号骰子的顺序,格式化输出所有的面 bool first = true; for (int i = 1; i <= n; i++) { // 输出早段 for (int j = 0; j < x[i]; j++) { if (!first) cout << " "; cout << early_val[i]; first = false; } // 输出晚段 long long y = k - x[i]; for (int j = 0; j < y; j++) { if (!first) cout << " "; cout << late_val[i]; first = false; } } cout << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; if (cin >> t) { while (t--) solve(); } return 0; } \end{minted}