Submission #1297449

#TimeUsernameProblemLanguageResultExecution timeMemory
1297449MisterReaperSum Zero (RMI20_sumzero)C++20
0 / 100
1094 ms712 KiB
// File A.cpp created on 01.12.2025 at 09:17:39 // File B.cpp created on 01.12.2025 at 09:17:41 #include <bits/stdc++.h> using i64 = long long; #ifdef DEBUG #include "/home/ahmetalp/Desktop/Workplace/debug.h" #else #define debug(...) void(23) #endif template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int N; std::cin >> N; std::vector<int> A(N); for (int i = 0; i < N; ++i) { std::cin >> A[i]; } std::vector<i64> pre(N + 1); for (int i = 0; i < N; ++i) { pre[i + 1] = pre[i] + A[i]; } debug(pre); int Q; std::cin >> Q; for (int i = 0; i < Q; ++i) { int L, R; std::cin >> L >> R; --L; std::map<i64, int> lst; std::vector<int> f(N + 1); f[L] = 0; lst[pre[L]] = L; for (int j = L + 1; j <= R; ++j) { f[j] = f[j - 1]; if (lst.count(pre[j])) { chmax(f[j], f[lst[pre[j]]] + 1); } lst[pre[j]] = j; } std::cout << f[R] << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...