제출 #539004

#제출 시각아이디문제언어결과실행 시간메모리
539004BlundergodSum Zero (RMI20_sumzero)C++17
0 / 100
2 ms340 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; void solve() { int n; cin >> n; vector<long long>x(n + 1, 0); for (int i = 1; i <= n; i++) { cin >> x[i]; } vector<long long>p(n + 1, 0); for (int i = 1; i <= n; i++) { p[i] = x[i] + p[i - 1]; } auto solveQuery = [&](int l, int r) { map<long long, long long>PrevSum; for (int i = l; i <= r; i++) { PrevSum[p[i]] = -1e9; } PrevSum[p[l - 1]] = 0; long long sum = 0; vector<long long>dp(n + 1, 0); for (int i = l; i <= r; i++) { sum = p[i]; dp[i] = dp[i - 1]; dp[i] = max(dp[i], 1 + PrevSum[sum]); PrevSum[sum] = max(PrevSum[sum], dp[i]); } cout << dp[r] << endl; }; int q; cin >> q; for (int i = 0; i < q; i++) { int l, r; cin >> l >> r; solveQuery(l, r) ; } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int T; T = 1; //cin >> T; while (T--) { solve(); } }

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

sumzero.cpp: In function 'int main()':
sumzero.cpp:50:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |  freopen("input.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sumzero.cpp:51:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |  freopen("output.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...