int ans = 0, cur = 0, one = 0; for (int i = 0; i < n; i++) { int x; cin >> x; if (x == 1) { cur += 1; one += 1; ans = max(ans, cur); } else { if (one == 0) { continue; } if (one & 1) { cur -= (one - ((one - 1) / 2 + 1)); one = 1; } else { cur -= (one - ((one - 2) / 2 + 2)); one = 2; } } } cout << ans << "\n"; }
vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end());
vector<int> dp(n); for (int i = n - 1; i >= 0; i--) { if (i == n - 1) { dp[i] = a[i].second; } else { dp[i] = max(dp[i + 1], a[i].second); } }
int ans = INT_MAX; set<int> st; for (int i = 0; i < n; i++) { int mx = -1; if (i + 1 < n) { mx = dp[i + 1]; ans = min(ans, abs(mx - a[i].first)); } auto it = st.lower_bound(a[i].first); if (it != st.end() and *it >= mx) { ans = min(ans, *it - a[i].first); } if (it != st.begin() andnot st.empty() and *prev(it) >= mx) { ans = min(ans, a[i].first - *prev(it)); } st.insert(a[i].second); } cout << ans << "\n"; }
voidupdate(int pos, int val){ for (int i = pos; i <= (int)bit.size(); i += i & (-i)) { bit[i] = max(bit[i], val); } }
voidclear(int pos){ for (int i = pos; i <= (int)bit.size(); i += i & (-i)) { bit[i] = 0; } }
intquery(int l, int r){ returnquery(r) - query(l - 1); }
intquery(int pos){ int res = 0; for (int i = pos; i >= 1; i -= i & (-i)) { res = max(res, bit[i]); } return res; } } F(2e5 + 10); // 也可以每次开 O(n) 的然后把所有值离散化
vector<vector<int>> a(n); for (int i = 0; i < n; i++) { int k; cin >> k; int pre = -1; for (int j = 0; j < k; j++) { int x; cin >> x; if (x > pre) { a[i].push_back(x); pre = x; } } } sort(a.begin(), a.end(), [](auto& x, auto& y) { return x.back() < y.back(); });
for (auto vec : a) { int mx = 0; for (int i = 0; i < (int)vec.size(); i++) { mx = max(mx, (int)vec.size() - i + F.query(vec[i] - 1)); } F.update(vec.back(), mx); }
cout << F.query(2e5 + 1) << "\n"; for (auto vec : a) { F.clear(vec.back()); } }