제출 #636569

#제출 시각아이디문제언어결과실행 시간메모리
636569danikoynovSum Zero (RMI20_sumzero)C++14
100 / 100
748 ms20156 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; const int maxn = 4e5 + 10, maxlog = 3, base = 100; int n, dp[maxlog][maxn], q; void solve() { cin >> n; ll x, sum = 0; int cl = -1; unordered_map < ll, int > last; for (int i = 1; i <= n; i ++) { cin >> x; sum = sum + x; if (last[sum] != 0 || sum == 0) cl = max(cl, last[sum]); last[sum] = i; dp[0][i] = cl; } dp[0][0] = -1; for (int j = 1; j < maxlog; j ++) { dp[j][0] = -1; for (int i = 1; i <= n; i ++) { dp[j][i] = dp[j - 1][i]; for (int f = 1; f < base && dp[j][i] != -1; f ++) dp[j][i] = dp[j - 1][dp[j][i]]; } } /**for (int j = 0; j < 4; j ++, cout << endl) for (int i = 0; i <= n; i ++) cout << dp[i][j] << " ";*/ cin >> q; int l, r, jump, st, bit, f; for (int i = 1; i <= q; i ++) { cin >> l >> r; jump = 0, st = 1; for (bit = 1; bit < maxlog; bit ++) st = st * base; for ( bit = maxlog - 1; bit >= 0; bit --) { //cout << l << " " << jump << endl; while(dp[bit][r] >= l - 1) { jump += st; r = dp[bit][r]; } st /= base; } cout << jump << endl; } } void speed() { ios_base::sync_with_stdio((false)); cin.tie(NULL); cout.tie(NULL); } int main() { speed(); ///freopen("input.txt", "r", stdin); solve(); return 0; } /** */

컴파일 시 표준 에러 (stderr) 메시지

sumzero.cpp: In function 'void solve()':
sumzero.cpp:41:30: warning: unused variable 'f' [-Wunused-variable]
   41 |     int l, r, jump, st, bit, f;
      |                              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...