Submission #851557

#TimeUsernameProblemLanguageResultExecution timeMemory
851557heeheeheehaawSum Zero (RMI20_sumzero)C++17
61 / 100
616 ms28412 KiB
#include <iostream> #include <map> using namespace std; const int baza = 80, lg = 3; int v[400005], bl[400005][3]; int query(int u, int v) { int rez = 0, put = 80 * 80; for(int j = 2; j >= 0; j--) { for(int i = 1; i <= 79; i++) if(bl[u][j] <= v) { u = bl[u][j]; rez += put; } put /= 80; } return rez; } int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n, q; cin>>n; for(int i = 1; i <= n; i++) cin>>v[i]; long long mindr = n + 1, sum = 0; map<long long, int> mp; mp[0] = n + 1; for(int i = n; i >= 1; i--) { sum += v[i]; bl[i][0] = mindr; if(mp[sum] != 0) mindr = min(mindr, mp[sum] - 1LL); mp[sum] = i; } bl[0][0] = mindr; for(int j = 1; j < 3; j++) for(int i = 0; i <= n; i++) { int nod = i; for(int k = 1; k <= 80 && nod != n + 1; k++) nod = bl[nod][j - 1]; bl[i][j] = nod; } cin>>q; for(int i = 1; i <= q; i++) { int a, b; cin>>a>>b; cout<<query(a - 1, b)<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...