제출 #857062

#제출 시각아이디문제언어결과실행 시간메모리
857062chanhchuong123Sum Zero (RMI20_sumzero)C++14
61 / 100
899 ms27956 KiB
#include <bits/stdc++.h> using namespace std; #define task "" const int MAX = 400004; const int base = 128; int n, q; int pw[2]; int c[MAX]; int ans[MAX]; long long sf = 0; int jump[2][MAX]; map<long long, int> last; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } cin >> n; for (int i = 1; i <= n; ++i) { cin >> c[i]; } for (int i = 1; i <= n + 2; ++i) { jump[0][i] = n + 2; jump[1][i] = n + 2; } last[0] = n + 1; for (int i = n; i >= 1; --i) { sf += c[i]; jump[0][i] = min(jump[0][i], jump[0][i + 1]); if (last[sf] > 0) jump[0][i] = min(jump[0][i], last[sf]); last[sf] = i; } pw[0] = 1; pw[1] = base; for (int j = 1; j <= 1; ++j) { for (int i = 1; i <= n + 1; ++i) { jump[j][i] = i; for (int k = 1; k <= base; ++k) jump[j][i] = jump[j - 1][jump[j][i]]; } } cin >> q; while (q--) { int l, r, res = 0; cin >> l >> r; for (int j = 1; j >= 0; --j) { while (jump[j][l] - 1 <= r) { l = jump[j][l]; res += pw[j]; } } cout << res << '\n'; } return 0; }

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

sumzero.cpp: In function 'int main()':
sumzero.cpp:36:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   36 |         if (last[sf] > 0) jump[0][i] = min(jump[0][i], last[sf]); last[sf] = i;
      |         ^~
sumzero.cpp:36:67: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   36 |         if (last[sf] > 0) jump[0][i] = min(jump[0][i], last[sf]); last[sf] = i;
      |                                                                   ^~~~
sumzero.cpp:20:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sumzero.cpp:21:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...