제출 #891537

#제출 시각아이디문제언어결과실행 시간메모리
891537fanwenSum Zero (RMI20_sumzero)C++17
0 / 100
6 ms31836 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define ll long long #define file(name) \ if(fopen(name".inp", "r")) \ freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout); const int MAX = 4e5 + 5; int n, a[MAX], q, f[20][MAX]; void you_make_it(void) { long long pref = 0; map <long long, int> dd; cin >> n; memset(f, -1, sizeof f); dd[0] = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; pref += a[i]; if(dd.count(pref)) f[0][i] = dd[pref]; f[0][i] = max(f[0][i - 1], f[0][i]); dd[pref] = i; // cout << f[0][i] << " \n"[i == n]; } for (int i = 1; i < 20; ++i) { for (int u = 1; u <= n; ++u) f[i][u] = f[i - 1][f[i - 1][u]]; } cin >> q; while(q--) { int l, r; cin >> l >> r; int ans = 0; for (int i = 19; i >= 0; --i) if(f[i][r] >= l - 1) { ans |= (1 << i); r = f[i][r]; } cout << ans << '\n'; } } signed main() { #ifdef LOCAL freopen("TASK.inp", "r", stdin); freopen("TASK.out", "w", stdout); #endif file("sumzero"); auto start_time = chrono::steady_clock::now(); cin.tie(0), cout.tie(0) -> sync_with_stdio(0); you_make_it(); auto end_time = chrono::steady_clock::now(); cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl; return (0 ^ 0); } // Dream it. Wish it. Do it.

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

sumzero.cpp: In function 'int main()':
sumzero.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sumzero.cpp:51:4: note: in expansion of macro 'file'
   51 |    file("sumzero");
      |    ^~~~
sumzero.cpp:10:49: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
      |                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sumzero.cpp:51:4: note: in expansion of macro 'file'
   51 |    file("sumzero");
      |    ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...