제출 #646476

#제출 시각아이디문제언어결과실행 시간메모리
646476borgar02Sum Zero (RMI20_sumzero)C++17
61 / 100
320 ms22332 KiB
#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][3]; const ll P1 = (1ll << 20) - 1, P2 = ((1ll << 20) - 1) << 20, P3 = ((1ll << 20) - 1) << 40; 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; } m.clear(); for(ll i = 1, l, r; i <= q; i++) { cin >> l >> r; l--; c[i] = (l | (r << 20)); } 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 k = 9; k >= 1; k--) { int kk = 2 * (k - 1); for(int j = 1; j <= 2; j++) { dp[n + 1][j] = n + 1; precalc(j, j - 1); } for(int j = 2; j <= k; j++) { precalc(1, 2); precalc(2, 1); } for(ll i = 1, l, r, res; i <= q; i++) { l = c[i] & P1; r = (c[i] & P2) >> 20; res = (c[i] & P3) >> 40; for(int j = 2; j >= (k != 1); j--) if(dp[l][j] <= r) res |= (1 << (kk + j)), l = dp[l][j]; c[i] = (l | (r << 20) | (res << 40)); if(k == 1) cout << res << "\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...