제출 #946101

#제출 시각아이디문제언어결과실행 시간메모리
946101dubabubaSum Zero (RMI20_sumzero)C++14
61 / 100
1051 ms19028 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") #pragma GCC optimize("O3,no-stack-protector,conserve-stack") #pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt") typedef pair<int, int> pii; #define ff first #define ss second #define MP make_pair const int LOG = 3; const int base = 74; const int mxn = 4e5 + 10; const int inf = 1e9 + 10; int i, j, n, m; long long pref; vector<pii> range; map<long long, int> mp; int stab[mxn][LOG]; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; mp[0] = 0; for(i = 1; i <= n; i++) { cin >> j; pref += j; auto it = mp.find(pref); if(it != mp.end()) range.push_back(MP((*it).ss + 1, i)); mp[pref] = i; } mp.clear(); j = 0; for(i = 1; i <= n; i++) { while(j < (int)range.size() && range[j].ff < i) j++; if(i <= range[j].ff) stab[i][0] = range[j].ss; } int cur, b; for(j = 1; j < LOG; j++) for(i = 1; i <= n; i++) { cur = stab[i][j - 1]; for(b = 1; b < base; b++) { if(cur > 0 && cur + 1 <= n) cur = stab[cur + 1][j - 1]; else { cur = 0; break; } } stab[i][j] = cur; } int pw[LOG]; pw[0] = 1; for(int i = 1; i < LOG; i++) pw[i] = pw[i - 1] * base; cin >> m; int l, r, ans; while(m--) { cin >> l >> r; ans = 0; for(j = LOG - 1; j >= 0; j--) { while(stab[l][j] > 0 && stab[l][j] <= r) { l = stab[l][j] + 1; ans += pw[j]; // cout << j << ' '; } } cout << ans << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...