voidsolve(){ int _; cin >> _; for (int tss = 0; tss < _; ++tss) { int a, b, c; cin >> a >> b >> c; int m = min(a - 1, b + c); cout << m * 2 + 1 << endl; } }
voidsolve(){ int _; cin >> _; for (int tss = 0; tss < _; ++tss) { int n, k; cin >> n >> k; map<int, vector<int>> res; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; tmp %= k; res[tmp].push_back(i); } auto zero = res[0]; for (auto i : zero) cout << i + 1 << ' '; for (auto iter = res.rbegin(); iter != res.rend(); ++iter) { if (iter->first == 0) continue; for (auto i : iter->second) cout << i + 1 << ' '; } cout << endl; } }
set<pair<int, int>> res; for (int i = 0; i < k; ++i) { int l, r; cin >> l >> r;
int ls, rs; { int left = b1[l - 1] % mod; int right = (b1[n] - b1[r] + mod) % mod; int one = a[r] - a[l - 1]; int zero = r - l + 1 - one; int from = l + zero, to = r; int mid = (pw1[to] - pw1[from - 1] + mod) % mod; ls = (left + right + mid) % mod; } { int left = b2[l - 1] % mod; int right = (b2[n] - b2[r] + mod) % mod; int one = a[r] - a[l - 1]; int zero = r - l + 1 - one; int from = l + zero, to = r; int mid = (pw2[to] - pw2[from - 1] + mod) % mod; rs = (left + right + mid) % mod; } res.insert({ls, rs}); }
voidsolve(){ int n; cin >> n; vector<int> data(n); vector<bool> vis(n, false); int res = 0; for (int i = 0; i < n; ++i) cin >> data[i];
// 先处理 2 的情况 for (int i = 0; i < n; ++i) { if (vis[i] || data[i] != 2) continue; res++; vis[i] = true; for (int j = i - 1; j >= 0; --j) { if (!vis[j]) { vis[j] = true; if (data[j] == 0) break; } elsebreak; } for (; i < n; ++i) { vis[i] = true; if (data[i] == 0) break; } }
// 再处理 1 的情况 int last = -1; int zero = 0; int oneP = 0; for (int i = 0; i < n; ++i) { if (vis[i]) { res += max(oneP, zero); zero = 0; oneP = 0; last = -1; } elseif (data[i] == 0) { zero++; last = 0; } elseif (last != 1) { last = 1; oneP++; } } res += max(oneP, zero);