Submission #1118063

#TimeUsernameProblemLanguageResultExecution timeMemory
1118063peraSum Zero (RMI20_sumzero)C++17
0 / 100
12 ms1104 KiB
#include<bits/stdc++.h> #define LL long long using namespace std; int main(){ int n; cin >> n; vector<LL> a(n + 1); for(int i = 1;i <= n;i ++){ cin >> a[i]; } map<LL , int> lst; LL s = 0; lst[s] = 0; const int LOG = 20; vector<vector<int>> up(n + 1 , vector<int>(LOG)); up[0][0] = -1; for(int i = 1;i <= n;i ++){ s += a[i]; if(lst.find(s) != lst.end()){ up[i][0] = lst[s]; } up[i][0] = max(up[i][0] , up[i - 1][0]); lst[s] = i; } for(int bit = 1;bit < LOG;bit ++){ for(int i = 0;i <= n;i ++){ up[i][bit] = (up[i][bit - 1] >= 0 ? up[up[i][bit - 1]][bit - 1] : -1); } } int q; cin >> q; while(q--){ int l , r; cin >> l >> r; int c = 0; for(int bit = LOG - 1;bit >= 0;bit --){ if(up[r][bit] >= l - 1){ c += 1 << bit; r = up[r][bit]; } } cout << c << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...