Submission #931300

#TimeUsernameProblemLanguageResultExecution timeMemory
931300LOLOLOSum Zero (RMI20_sumzero)C++17
61 / 100
379 ms50036 KiB
#include <bits/stdc++.h> typedef long long ll; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (int32_t)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) using namespace std; const int N = 4e5 + 100; int c[N], sp[N][19]; ll solve() { int n; cin >> n; for (int i = 1; i <= n + 2; i++) { for (int j = 0; j < 19; j++) sp[i][j] = n + 2; } map <ll, int> mp; ll sum = 0; mp[0] = 1; for (int i = 1; i <= n; i++) { cin >> c[i]; sum += c[i]; if (mp[sum]) { sp[mp[sum]][0] = min(sp[mp[sum]][0], i + 1); } mp[sum] = i + 1; } for (int i = n + 1; i >= 1; i--) { sp[i][0] = min(sp[i + 1][0], sp[i][0]); for (int j = 1; j < 19; j++) { sp[i][j] = sp[sp[i][j - 1]][j - 1]; } } int q; cin >> q; while (q--) { int l, r, ans = 0; cin >> l >> r; for (int j = 18; j >= 0; j--) { if (sp[l][j] <= r + 1) { ans += (1 << j); l = sp[l][j]; } } cout << ans << '\n'; } return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while (t--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...