Submission #539005

#TimeUsernameProblemLanguageResultExecution timeMemory
539005BlundergodSum Zero (RMI20_sumzero)C++17
0 / 100
1064 ms600 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; void solve() { int n; cin >> n; vector<long long>x(n + 1, 0); for (int i = 1; i <= n; i++) { cin >> x[i]; } vector<long long>p(n + 1, 0); for (int i = 1; i <= n; i++) { p[i] = x[i] + p[i - 1]; } auto solveQuery = [&](int l, int r) { map<long long, long long>PrevSum; for (int i = l; i <= r; i++) { PrevSum[p[i]] = -1e9; } PrevSum[p[l - 1]] = 0; long long sum = 0; vector<long long>dp(n + 1, 0); for (int i = l; i <= r; i++) { sum = p[i]; dp[i] = dp[i - 1]; dp[i] = max(dp[i], 1 + PrevSum[sum]); PrevSum[sum] = max(PrevSum[sum], dp[i]); } cout << dp[r] << endl; }; int q; cin >> q; for (int i = 0; i < q; i++) { int l, r; cin >> l >> r; solveQuery(l, r) ; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int T; T = 1; //cin >> T; while (T--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...