Submission #1297469

#TimeUsernameProblemLanguageResultExecution timeMemory
1297469MisterReaperSum Zero (RMI20_sumzero)C++20
0 / 100
2 ms568 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> dep(N + 1); std::vector<int> prv(N + 1); std::map<i64, int> lst; lst[0] = 0; prv[0] = -1; dep[0] = 0; 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]; } dep[i] = prv[i] == -1 ? 0 : dep[prv[i]] + 1; lst[pre[i]] = i; } debug(prv); debug(dep); int Q; std::cin >> Q; for (int i = 0; i < Q; ++i) { int L, R; std::cin >> L >> R; --L; int p = std::lower_bound(prv.begin() + L, prv.begin() + R, L) - prv.begin(); p = prv[p]; int ans = dep[R] - dep[p]; std::cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...