Submission #597235

#TimeUsernameProblemLanguageResultExecution timeMemory
597235Hacv16Sum Zero (RMI20_sumzero)C++17
22 / 100
1086 ms3204 KiB
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("fma,sse,sse2,sse3,avx") #pragma GCC optimize("unroll-loops") typedef long long ll; typedef pair<int, int> pii; const int MAX = 2e6 + 15; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; #define pb push_back #define sz(x) (int) x.size() #define fr first #define sc second #define mp make_pair #define all(x) x.begin(), x.end() #define dbg(x) cout << #x << ": " << "[ " << x << " ]\n" int n, v[MAX], dp[MAX], m[MAX], q; int query(int l, int r){ for(int i = l; i <= r; i++) m[i] = -1, dp[i] = 0; unordered_map<int, int> sums; sums[0] = l - 1, dp[l - 1] = 0; for(int i = l, s = 0; i <= r; i++){ s += v[i]; if(sums.find(s) != sums.end()) m[i] = sums[s]; sums[s] = i; } for(int i = l; i <= r; i++){ if(m[i] == -1) dp[i] = dp[i - 1]; else dp[i] = max(dp[i - 1], dp[m[i]] + 1); } return dp[r]; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 1; i <= n; i++) cin >> v[i]; cin >> q; while(q--){ int l, r; cin >> l >> r; cout << query(l, r) << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...