이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
int i, j, n, m;
long long pref;
map<long long, int> mp;
int stab[mxn][LOG];
int pw[LOG];
int main() {
#ifdef LOCAL
auto start = chrono::high_resolution_clock::now();
#endif
cin.tie(0)->sync_with_stdio(0);
cin >> n;
mp[0] = 0;
for(int i = 1; i <= n + 3; i++)
stab[i][0] = n + 1;
for(i = 1; i <= n; i++) {
cin >> j;
pref += j;
auto it = mp.find(pref);
if(it != mp.end()) {
stab[it->ss + 1][0] = i;
}
mp[pref] = i;
}
mp.clear();
for(i = n; i > 0; i--) {
stab[i][0] = min(stab[i][0], stab[i + 1][0]);
}
int cur, b;
for(j = 1; j < LOG; j++) {
for(int i = 1; i <= n + 3; i++)
stab[i][j] = n + 1;
for(i = 1; i <= n; i++) {
cur = stab[i][j - 1];
for(b = 1; b < base; b++)
cur = stab[cur + 1][j - 1];
stab[i][j] = cur;
}
}
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--) {
for(int b = 1; b < base; b++)
if(stab[l][j] <= r) {
l = stab[l][j] + 1;
ans += pw[j];
}
}
cout << ans << endl;
}
#ifdef LOCAL
auto end = chrono::high_resolution_clock::now();
for(int i = 0; i <= 20; ++i) cout << '-';
cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |