Submission #891558

#TimeUsernameProblemLanguageResultExecution timeMemory
891558fanwenSum Zero (RMI20_sumzero)C++17
22 / 100
53 ms20040 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[10][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 < 10; ++i) { for (int u = 1; u <= n; ++u) f[i][u] = (f[i - 1][u] == -1 ? -1 : f[i - 1][f[i - 1][u]]); } cin >> q; while(q--) { int l, r; cin >> l >> r; int ans = 0; for (int i = 9; i >= 0; --i) if(r >= l - 1 && 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("sum0"); 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.

Compilation message (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:5: note: in expansion of macro 'file'
   51 |     file("sum0");
      |     ^~~~
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:5: note: in expansion of macro 'file'
   51 |     file("sum0");
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...