제출 #597336

#제출 시각아이디문제언어결과실행 시간메모리
597336pedroslreySum Zero (RMI20_sumzero)C++17
61 / 100
422 ms41476 KiB
#include <bits/stdc++.h> using namespace std; using lli = long long; const int MAXN = 4e5 + 10; const int MAXK = 20; int ant[MAXN]; int dp[MAXN][MAXK]; int main() { int n; scanf("%d", &n); vector<pair<lli, int>> xs{{0, 0}}; lli sum = 0; for (int i = 1; i <= n; ++i) { int x; scanf("%d", &x); sum += x; xs.emplace_back(sum, i); } for (int i = 1; i <= n; ++i) ant[i] = -1; sort(xs.begin(), xs.end()); for (int i = 1; i <= n; ++i) if (xs[i].first == xs[i-1].first) ant[xs[i].second] = xs[i-1].second; for (int k = 0; k < MAXK; ++k) dp[0][k] = -1; for (int i = 1; i <= n; ++i) { if (ant[i] < dp[i-1][0]) dp[i][0] = dp[i-1][0]; else dp[i][0] = ant[i]; for (int k = 1; k < MAXK; ++k) if (dp[i][k-1] != -1) dp[i][k] = dp[dp[i][k-1]][k-1]; else dp[i][k] = -1; } int q; scanf("%d", &q); for (int i = 0; i < q; ++i) { int l, r; scanf("%d%d", &l, &r); int ans = 0; for (int k = MAXK - 1; k >= 0; --k) if (dp[r][k] >= l-1) { r = dp[r][k]; ans += 1 << k; } printf("%d\n", ans); } }

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

sumzero.cpp: In function 'int main()':
sumzero.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
sumzero.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   scanf("%d", &x);
      |   ~~~~~^~~~~~~~~~
sumzero.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
sumzero.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |   scanf("%d%d", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...