제출 #647025

#제출 시각아이디문제언어결과실행 시간메모리
647025borgar02Sum Zero (RMI20_sumzero)C++17
61 / 100
388 ms22156 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]; ll dp[N]; 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] = n + 1; for(int i = n; i >= 0; i--) { dp[i] = (m.count(c[i]) ? min(m[c[i]], (int)dp[i + 1]) : dp[i + 1]); m[c[i]] = i; } m.clear(); for(ll i = 1, l, r; i <= q; i++) { cin >> l >> r; l--; c[i] = (l | (r << 20)); } dp[n + 1] = (n + 1) * (1 + (1 << 20) + (1ll << 40)); for(int k = 9; k >= 1; k--) { int kk = 2 * (k - 1); for(int i = 0; i <= n; i++) { dp[i] &= ~P2; int from = dp[i] & P1; dp[i] |= ll(dp[from] & P1) << 20; } for(int i = 0; i <= n; i++) { dp[i] &= ~P3; int from = (dp[i] & P2) >> 20; dp[i] |= ll(dp[from] & P2) << 20; } for(int j = 2; j <= k; j++) { for(int i = 0; i <= n; i++) { dp[i] &= ~P2; int from = (dp[i] & P3) >> 40; dp[i] |= ll(dp[from] & P3) >> 20; } for(int i = 0; i <= n; i++) { dp[i] &= ~P3; int from = (dp[i] & P2) >> 20; dp[i] |= ll(dp[from] & P2) << 20; } } for(ll i = 1, l, r, res; i <= q; i++) { l = c[i] & P1; r = (c[i] & P2) >> 20; res = (c[i] & P3) >> 40; if(((dp[l] & P3) >> 40) <= r) res |= (1 << (kk + 2)), l = (dp[l] & P3) >> 40; if(((dp[l] & P2) >> 20) <= r) res |= (1 << (kk + 1)), l = (dp[l] & P2) >> 20; if(k == 1 && (dp[l] & P1) <= r) res |= (1 << kk), l = dp[l] & P1; 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...