제출 #857066

#제출 시각아이디문제언어결과실행 시간메모리
857066chanhchuong123Sum Zero (RMI20_sumzero)C++14
100 / 100
907 ms16212 KiB
#include <bits/stdc++.h> using namespace std; #define task "" const int MAX = 400002; const int base = 128; int n, q; int pw[2]; int c[MAX]; int sf = 0; int jump[2][MAX]; map<int, 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 + 1; ++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]]; if (jump[j][i] == n + 2) break; } } } 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:35:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   35 |         if (last[sf] > 0) jump[0][i] = min(jump[0][i], last[sf]); last[sf] = i;
      |         ^~
sumzero.cpp:35:67: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   35 |         if (last[sf] > 0) jump[0][i] = min(jump[0][i], last[sf]); last[sf] = i;
      |                                                                   ^~~~
sumzero.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...