제출 #1110464

#제출 시각아이디문제언어결과실행 시간메모리
1110464Zero_OPSum Zero (RMI20_sumzero)C++14
61 / 100
320 ms43008 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, l, r) for(int i = (l); i < (r); ++i) #define sz(v) (int)v.size() #define dbg(x) "[" #x " = " << (x) << "]" #define all(v) begin(v), end(v) #define compact(v) v.erase(unique(all(v)), end(v)) #define file(name) if(fopen(name".inp", "r")){ freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } template<typename T> bool minimize(T& a, const T& b){ if(a > b){ return a = b, true; } return false; } template<typename T> bool maximize(T& a, const T& b){ if(a < b){ return a = b, true; } return false; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); using ll = long long; using ld = long double; using ull = unsigned long long; using vi = vector<int>; using vl = vector<ll>; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); file("task"); int N; cin >> N; vector<int> a(N + 1); vector<long long> pref(N + 1); vector<long long> v = {0}; for(int i = 1; i <= N; ++i){ cin >> a[i]; pref[i] = pref[i - 1] + a[i]; v.push_back(pref[i]); } sort(all(v)); compact(v); const int inf = 1e9 + 9; vector<int> last(sz(v), inf - 1); int L = 32 - __builtin_clz(N); vector<vector<int>> lift(L, vector<int>(N + 2, inf)); vector<int> pos(N + 1); for(int i = 0; i <= N; ++i) pos[i] = lower_bound(all(v), pref[i]) - v.begin(); for(int i = N; i >= 0; --i){ //select smallest j such sum [i...j) = 0 if(i < N) lift[0][i + 1] = last[pos[i]] + 1; last[pos[i]] = i; } for(int i = N - 1; i >= 1; --i){ minimize(lift[0][i], lift[0][i + 1]); } for(int i = 1; i < L; ++i){ for(int j = 1; j <= N; ++j){ if(lift[i - 1][j] == inf) lift[i][j] = inf; else{ lift[i][j] = lift[i - 1][lift[i - 1][j]]; } } } int Q; cin >> Q; while(Q--){ int l, r; cin >> l >> r; ++r; int ans = 0; for(int i = L - 1; i >= 0; --i){ if(lift[i][l] <= r){ ans += (1 << i); l = lift[i][l]; } } cout << ans << '\n'; } return 0; }

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

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