제출 #539007

#제출 시각아이디문제언어결과실행 시간메모리
539007BlundergodSum Zero (RMI20_sumzero)C++17
0 / 100
1080 ms824 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) { unordered_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() { 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...