제출 #1203058

#제출 시각아이디문제언어결과실행 시간메모리
1203058al95ireyizSum Zero (RMI20_sumzero)C++20
0 / 100
4 ms3904 KiB
//*** Bismillah ***// #pragma GCC optimize("O3", "fast-math", "unroll-loops", "no-stack-protector") #include <bits/stdc++.h> using namespace std; #if !defined(ONLINE_JUDGE) and !defined(EVAL) #include "template/debug.h" #else #define d(x...) #endif #define fr first #define er erase #define sc second #define in insert #define ll long long #define pb push_back #define pll pair<ll,ll> #define len(x)(ll)x.size() #define all(x)x.begin(),x.end() const ll INF = 1e9; const ll INFL = 1e18; const ll MOD = 1e9+7; // const ll MOD = 998244353; const ll maxn = 4e5+5; ll n,m,k=0; const ll lg = 7; ll a[maxn], up[maxn][lg], cmp[maxn], mp[maxn]; set<ll>s; void _(ll tt){ cin>>n; for(ll i = 0; i < maxn; i ++) mp[i] = INF; ll pr = 0, pos = n + 1; for(ll i = 1; i <= n; i ++) cin>>a[i], pr += a[i], s.in(pr); ll ind = 0; for(auto x : s) cmp[++ ind] = x; auto get = [&](ll x){ ll l = 1, r = ind, cv; while(l <= r){ ll md = (l+r)>>1; if(cmp[md] <= x) l = md + 1, cv = md; else r = md - 1; } return cv; }; for(ll i = n; i >= 0; i --){ if(mp[get(pr)] != INF) pos = min(pos, mp[get(pr)]); up[i][0] = pos; mp[get(pr)] = i; pr -= a[i]; } up[n+1][0] = n + 1; for(ll i = 1; i < lg; i ++){ for(ll j = 0; j <= n + 1; j ++){ up[j][i] = up[up[up[up[up[j][i-1]][i-1]][i-1]][i-1]][i-1]; // 5^i-th parent } } cin>>m; for(ll i = 1, l, r; i <= m; i ++){ cin>>l>>r; l --; ll cv = 0; for(ll i = lg - 1, pw = 15625; i >= 0; i --, pw /= 5){ if(up[l][i] <= r and up[l][i] != 0){ cv += pw; l = up[l][i]; } if(up[l][i] <= r and up[l][i] != 0){ cv += pw; l = up[l][i]; } if(up[l][i] <= r and up[l][i] != 0){ cv += pw; l = up[l][i]; } if(up[l][i] <= r and up[l][i] != 0){ cv += pw; l = up[l][i]; } } cout<<cv<<'\n'; } } signed main(){ ll tm=clock(); cin.tie(0)->sync_with_stdio(0); ll t=1; // cin>>t; for(ll tt=1;tt<=t;tt++){ _(tt); } cerr<<"\n\033[1;31mTime: \033[1;30m" \ <<(double)(clock()-tm)/1000000<<"\033[1;32m seconds\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...