Submission #1225675

#TimeUsernameProblemLanguageResultExecution timeMemory
1225675Sir_Ahmed_ImranSum Zero (RMI20_sumzero)C++17
61 / 100
860 ms22776 KiB
// 01001100 01001111 01010100 01000001 \\ // \\ // ╦ ╔═╗╔╦╗╔═╗ \\ // ║ ║ ║ ║ ╠═╣ \\ // ╩═╝╚═╝ ╩ ╩ ╩ \\ // \\ // 01001100 01001111 01010100 01000001 \\ #include <bits/stdc++.h> using namespace std; #define N 400001 #define K 9 #define nl '\n' #define ff first #define ss second #define add insert #define ll long long #define ld long double #define terminator main #define pll pair<ll,ll> #define append push_back #define pii pair<int,int> #define all(x) (x).begin(),(x).end() #define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) int x[N][K]; void solve(){ ll a; int n, m, q, l, r, ans; cin >> n; vector<pair<ll, int>> v {{0, 1}}; a = 0; for(int i = 1; i <= n; i++){ cin >> m; a += m; x[i][0] = n + 2; v.append({a, i + 1}); } sort(all(v)); for(int i = 1; i < v.size(); i++) if(v[i - 1].ff == v[i].ff) x[v[i - 1].ss][0] = v[i].ss; v.clear(); for(int i = n - 1; i > 0; i--) x[i][0] = min(x[i][0], x[i + 1][0]); for(int j = 0; j < K; j++) x[n + 1][j] = x[n + 2][j] = n + 2; for(int j = 0; j < K - 1; j++) for(int i = 1; i <= n; i++) x[i][j + 1] = x[x[i][j]][j]; cin >> q; while(q--){ cin >> l >> r; r++; ans = 0; for(int i = K - 1; i >= 0; i--){ while(x[l][i] <= r){ ans += (1 << i); l = x[l][i]; } } cout << ans << nl; } } int terminator(){ L0TA; solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...