Submission #1119932

#TimeUsernameProblemLanguageResultExecution timeMemory
1119932NintsiChkhaidzeSum Zero (RMI20_sumzero)C++17
100 / 100
209 ms19056 KiB
#include<bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("avx2") #define LL long long using namespace std; const int N = 4e5 + 1; int ans[N] , lst[N] , e[N]; pair<int , int> s[N]; unordered_map<LL , int> nt; int main(){ cin.tie(0)->sync_with_stdio(0); int n; cin >> n; LL sum = 0; nt[0] = 0; lst[0] = -1; for(int i = 1;i <= n;i ++){ int x; cin >> x; sum += x; if(nt.find(sum) != nt.end()){ lst[i] = nt[sum]; }else{ lst[i] = -1; } lst[i] = max(lst[i] , lst[i - 1]); nt[sum] = i; } int q; cin >> q; memset(ans , 0 , sizeof(ans)); for(int i = 0;i < q;i ++){ cin >> s[i].first >> s[i].second; } for(int bit = 18;bit >= 0;bit --){ for(int i = 0;i <= n;i ++){ e[i] = lst[i]; } for(int c = 0;c < bit;c ++){ for(int i = n;i >= 0;i --){ e[i] = (e[i] > -1 ? e[e[i]] : -1); } } for(int i = 0;i < q;i ++){ if(s[i].first - 1 <= e[s[i].second]){ ans[i] += 1 << bit; s[i].second = e[s[i].second]; } } } for(int i = 0;i < q;i ++){ cout << ans[i] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...