제출 #942623

#제출 시각아이디문제언어결과실행 시간메모리
942623LOLOLOSum Zero (RMI20_sumzero)C++14
100 / 100
635 ms20216 KiB
#include <bits/stdc++.h> typedef long long ll; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (int32_t)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) using namespace std; const int N = 4e5 + 10; int c[N], sp[N][5], p[10]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); p[0] = 1; for (int i = 1; i < 10; i++) p[i] = p[i - 1] * 4; int n; cin >> n; for (int i = 1; i <= n + 2; i++) { for (int j = 0; j < 5; j++) sp[i][j] = n + 2; } ll sum = 0; vector < pair <ll, int>> all; all.pb({0, 1}); for (int i = 1; i <= n; i++) { cin >> c[i]; sum += c[i]; all.pb({sum, i + 1}); } sort(all(all)); for (int i = 0; i < sz(all) - 1; i++) { if (all[i].f == all[i + 1].f) { sp[all[i].s][0] = all[i + 1].s; } } all.clear(); for (int i = n + 1; i >= 1; i--) { sp[i][0] = min(sp[i + 1][0], sp[i][0]); for (int j = 1; j < 5; j++) { int x = i; for (int k = 0; k < 4; k++) { x = sp[x][j - 1]; } sp[i][j] = x; } } int q; cin >> q; while (q--) { int l, r; cin >> l >> r; int id = 4, cnt = 0; while (id >= 0) { if (sp[l][id] <= r + 1) { l = sp[l][id]; cnt += p[id]; } else { id--; } } cout << cnt << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...