This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
unsigned seed = chrono :: system_clock :: now().time_since_epoch().count();
mt19937 rng(seed);
using ll = long long;
const int N = 4e5 + 5;
ll c[N];
int dp[N][4];
pair <int, int> que[N];
int main()
{
ios_base :: sync_with_stdio(false); cin.tie(0);
int n, q;
cin >> n;
for(int i = 1; i <= n; i++)
cin >> c[i];
cin >> q;
partial_sum(c + 1, c + n + 1, c + 1);
map <ll, int> m;
dp[n + 1][0] = n + 1;
for(int i = n; i >= 0; i--) {
dp[i][0] = (m.count(c[i]) ? min(m[c[i]], dp[i + 1][0]) : dp[i + 1][0]);
m[c[i]] = i;
}
for(int i = 1; i <= q; i++) {
cin >> que[i].first >> que[i].second;
que[i].first--;
}
m.clear();
auto precalc = [&](int to, int from) {
dp[n + 1][to] = n + 1;
for(int i = n; i >= 0; i--)
dp[i][to] = dp[dp[i][from]][from];
};
for(int i = 1; i <= q; i++) c[i] = 0;
for(int k = 6; k >= 1; k--) {
int kk = 3 * (k - 1);
for(int j = 1; j < 4; j++) {
dp[n + 1][j] = n + 1;
precalc(j, j - 1);
}
for(int j = 2; j <= k; j++) {
precalc(1, 3);
for(int j = 2; j < 4; j++)
precalc(j, j - 1);
}
for(int i = 1; i <= q; i++) {
for(int j = 3; j >= (k != 1); j--)
if(dp[que[i].first][j] <= que[i].second)
c[i] |= (1 << (kk + j)),
que[i].first = dp[que[i].first][j];
if(k == 1) cout << c[i] << "\n";
}
}
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... |