제출 #646152

#제출 시각아이디문제언어결과실행 시간메모리
646152borgar02Sum Zero (RMI20_sumzero)C++17
61 / 100
499 ms46752 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][19]; 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]; 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 j = 1; j < 19; j++) { dp[n + 1][j] = n + 1; for(int i = n; i >= 0; i--) dp[i][j] = dp[dp[i][j - 1]][j - 1]; } cin >> q; for(int i = 1, l, r; i <= q; i++) { cin >> l >> r; l--; int res = 0; for(int j = 18; j >= 0; j--) if(dp[l][j] <= r) res |= (1 << j), l = dp[l][j]; cout << res << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...