Submission #1297451

#TimeUsernameProblemLanguageResultExecution timeMemory
1297451MisterReaperSum Zero (RMI20_sumzero)C++20
22 / 100
1096 ms4972 KiB
// 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); std::vector<int> prv(N + 1); std::map<i64, int> lst; lst[0] = 0; prv[0] = -1; for (int i = 1; i <= N; ++i) { if (lst.count(pre[i])) { prv[i] = std::max(lst[pre[i]], prv[i - 1]); } else { prv[i] = prv[i - 1]; } lst[pre[i]] = i; } debug(prv); int Q; std::cin >> Q; for (int i = 0; i < Q; ++i) { int L, R; std::cin >> L >> R; --L; int ans = 0; while (prv[R] >= L) { R = prv[R]; ans += 1; } std::cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...