제출 #674589

#제출 시각아이디문제언어결과실행 시간메모리
674589x0rSum Zero (RMI20_sumzero)C++17
0 / 100
4 ms852 KiB
#include <bits/stdc++.h> #define name "" #define test "test" #define ll long long #define ld long double #define fi first #define se second #define pll pair < ll, ll > #define pii pair < int, int > #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sz(x) ((int)(x).size()) #define pb push_back #define mp make_pair using namespace std; const ld EPS = 1e-9; const int INF = 1e9 + 7; const ll LINF = 1E18; const int NMAX = 2e5; const ll MOD = 1e9 + 7; const ll BASE = 2309; ll n, s[400003]; int st[400003][20]; map < ll, int > f; int main() { fast; if(fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } //int t; cin >> t; while (t --) sol(); cin >> n; for (int i = 1; i <= n; i++) { ll x; cin >> x; s[i] = s[i - 1] + x; } st[n + 1][0] = st[n + 2][0] = n + 2; for (int i = n; i >= 1; i--) { st[i][0] = st[i + 1][0]; f[s[i]] = i; if (f.find(s[i - 1]) != f.end()) st[i][0] = min(st[i][0], f[s[i - 1]] + 1); } for (int j = 1; j <= 20; j++) { st[n + 1][j] = n + 2; st[n + 2][j] = n + 2; for (int i = n; i >= 1; i--) { st[i][j] = min(st[i + 1][j], st[st[i][j - 1]][j - 1]); } } int q; cin >> q; while (q--) { int l, r; cin >> l >> r; r++; int res = 0; for (int j = 20; j >= 0; j--) { if (st[l][j] <= r) { res += (1 << j); l = st[l][j]; } } cout << res << '\n'; } }

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

sumzero.cpp: In function 'int main()':
sumzero.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   freopen(name".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sumzero.cpp:35:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   freopen(name".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sumzero.cpp:52:16: warning: iteration 19 invokes undefined behavior [-Waggressive-loop-optimizations]
   52 |   st[n + 1][j] = n + 2;
      |   ~~~~~~~~~~~~~^~~~~~~
sumzero.cpp:51:20: note: within this loop
   51 |  for (int j = 1; j <= 20; j++) {
      |                  ~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...