版本比较
2025 XYD Summer Camp 7.31 容斥 P2
正文
增加 7 行删除 7 行
23 行未改动2425262728293031323334353637383940414243444546474849113 行未改动全部展开1631641651661671681691701711724 行未改动17717817918018118218318418538 行未改动23 行未改动int T; for (cin >> T; T --; ) {int n; cin >> n; vector<int> a(n); vector<ll> s(n);for (int &i : a) cin >> i;s[0] = a[0];for (int i = 1; i < n; i ++)s[i] = s[i - 1] + a[i];ll S = s[n - 1]; int ans = 0; ll add = 0;auto getseg = [&](ll x) -> pair<ll, ll> {return mk(-x, S - x);};for (int i = 0, j = 0; i < n; ) {if (0 <= s[i] + add && s[i] + add <= S) { i ++; continue; }ans ++;pair<ll, ll> seg = i == 0 ? mk(0ll, S) : getseg(s[i - 1] + add);for (j = i; j < n; j ++) {pair<ll, ll> seg1 = getseg(s[j] + add);if (seg1.second < seg.first || seg.second < seg1.first) break;chkmax(seg.first, seg1.first), chkmin(seg.second, seg1.second);} if (-add < seg.first) add += seg.first;else if (seg.second < -add) add += seg.second;else add += -add;i = j;} if (add != 0) ans ++;cout << ans + n << '\n';}return 0;113 行未改动全部展开#define rson mid + 1, r, rt << 1 | 1#define BCNT __builtin_popcount#define cost_time (1e3 * clock() / CLOCKS_PER_SEC) << "ms"#define cost_space (abs(&MemoryST - &MemoryED) / 1024.0 / 1024.0) << "MB"const int inf = 0x3f3f3f3f;const ll linf = 1e18;mt19937 rnd(random_device{}());template<typename T> void chkmax(T& x, T y) { x = max(x, y); }template<typename T> void chkmin(T& x, T y) { x = min(x, y); }template<typename T> T abs(T x) { return (x < 0) ? -x : x; }4 行未改动int qp(int x, int y) {int res = 1; for (; y; y >>= 1, multo(x, x))if (y & 1) multo(res, x);return res;} int divv(int x, int y) { return 1ll * x * qp(y, P - 2) % P; } void divto(int &x, int y) { x = divv(x, y); }int sub(int x, int y) { return (x + P - y) % P; } void subto(int &x, int y) { x = sub(x, y); }} using namespace ModOptions_normal;bool MemoryED; int main() {int n; cin >> n; vector<array<int, 3> > P(n);38 行未改动23 行未改动2425262728293031323334353637383940414243444546474849113 行未改动全部展开1631641651661671681691701711724 行未改动17717817918018118218318418538 行未改动23 行未改动int T; for (cin >> T; T --; ) {int n; cin >> n; vector<int> a(n); vector<ll> s(n);for (int &i : a) cin >> i;s[0] = a[0];for (int i = 1; i < n; i ++)s[i] = s[i - 1] + a[i];ll S = s[n - 1]; int ans = 0; ll add = 0;auto getseg = [&](ll x) -> pair<ll, ll> {return mk(-x, S - x);};for (int i = 0, j = 0; i < n; ) {if (0 <= s[i] + add && s[i] + add <= S) { i ++; continue; }ans ++;pair<ll, ll> seg = i == 0 ? mk(0ll, S) : getseg(s[i - 1] + add);for (j = i; j < n; j ++) {pair<ll, ll> seg1 = getseg(s[j] + add);if (seg1.second < seg.first || seg.second < seg1.first) break;chkmax(seg.first, seg1.first), chkmin(seg.second, seg1.second);} if (-add < seg.first) add += seg.first;else if (seg.second < -add) add += seg.second;else add += -add;i = j;} if (add != 0) ans ++;cout << ans + n << '\n';}return 0;113 行未改动全部展开#define rson mid + 1, r, rt << 1 | 1#define BCNT __builtin_popcount#define cost_time (1e3 * clock() / CLOCKS_PER_SEC) << "ms"#define cost_space (abs(&MemoryST - &MemoryED) / 1024.0 / 1024.0) << "MB"const int inf = 0x3f3f3f3f;const ll linf = 1e18;mt19937 rnd(random_device{}());template<typename T> void chkmax(T& x, T y) { x = max(x, y); }template<typename T> void chkmin(T& x, T y) { x = min(x, y); }template<typename T> T abs(T x) { return (x < 0) ? -x : x; }4 行未改动int qp(int x, int y) {int res = 1; for (; y; y >>= 1, multo(x, x))if (y & 1) multo(res, x);return res;} int divv(int x, int y) { return 1ll * x * qp(y, P - 2) % P; } void divto(int &x, int y) { x = divv(x, y); }int sub(int x, int y) { return (x + P - y) % P; } void subto(int &x, int y) { x = sub(x, y); }} using namespace ModOptions_normal;bool MemoryED; int main() {int n; cin >> n; vector<array<int, 3> > P(n);38 行未改动