제출 #1054987

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