제출 #1054983

#제출 시각아이디문제언어결과실행 시간메모리
1054983pokmui9909Sum Zero (RMI20_sumzero)C++17
0 / 100
8 ms62040 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define x first #define y second ll N, Q, F[20][400005]; pair<ll, ll> B[400005]; int main(){ cin.tie(0) -> sync_with_stdio(0); cin >> N; fill(F[0], F[19] + N + 3, N + 2); for(ll i = 1; i <= N; i++){ ll v; cin >> v; B[i] = {B[i - 1].x + v, i}; } sort(B, B + N + 1); for(ll i = 1; i <= N; i++){ if(B[i - 1].x == B[i].x){ F[0][B[i - 1].y + 1] = B[i].y + 1; } } for(ll i = N; i >= 1; i--){ F[0][i] = min(F[0][i], F[0][i + 1]); } for(ll j = 1; j < 20; j++){ for(ll i = 1; i <= N; i++){ F[j][i] = F[j - 1][F[j - 1][i]]; } } cin >> Q; while(Q--){ ll L, R; cin >> L >> R; ll t = 0, u = L; for(ll j = 19; j >= 0; j--){ if(F[j][u] > R + 1 || F[j][u] == 0) continue; u = F[j][u], t |= (1LL << j); } cout << t << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...