제출 #875128

#제출 시각아이디문제언어결과실행 시간메모리
875128Ahmed57Sum Zero (RMI20_sumzero)C++17
61 / 100
765 ms28112 KiB
#include <bits/stdc++.h> using namespace std; int P[400001][8];int vl[8]; int xd = 8; int main(){ ios_base::sync_with_stdio(false);cin.tie(0); vl[0] = 1; for(int i = 1;i<xd;i++){ vl[i] = 3*vl[i-1]; } int n,l,r,ans; cin>>n; long long arr[n]; map<long long,int> mp; long long sum = 0; mp[0] = 1; for(int i = 0;i<n;i++){ cin>>arr[i]; sum+=arr[i]; if(mp[sum]>0){ P[mp[sum]-1][0] = i+1; } mp[sum] = i+2; } for(int i = 0;i<=n;i++){ if(P[i][0]==0)P[i][0] = n; else P[i][0]--; } for(int i = n;i>=0;i--){ if(i<n)P[i][0] = min(P[i][0],P[i+1][0]); for(int j = 1;j<xd;j++){ P[i][j] = P[min(n,P[min(n,P[i][j-1]+1)][j-1]+1)][j-1]; } } int q;cin>>q; while(q--){ cin>>l>>r;l--;r--; ans = 0; int e = xd-1; while(e>=0){ while(P[l][e]<=r){ l = P[l][e]+1; ans+=vl[e]; } e--; } cout<<ans<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...