제출 #857057

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