이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=4e5+10, LG=8;
int n, a[N], nxt[N];
pair<ll, int> pf[N];
int st[LG][N];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
pf[0]={0, 0};
for (int i=1; i<=n; ++i) cin >> a[i], pf[i]={pf[i-1].first+a[i], i}, nxt[i]=n+1;
sort(pf, pf+n+1);
for (int i=0; i<=n; ++i){
int j=i;
while (j<n && pf[j+1].first==pf[i].first) ++j;
for (int k=i; k<j; ++k) nxt[pf[k].second+1]=pf[k+1].second;
i=j;
}
int q; cin >> q;
while (q--){
int l, r; cin >> l >> r;
vector<pair<int, int>> v, vv;
for (int i=l; i<=r; ++i) if (nxt[i]<=r) vv.emplace_back(i, nxt[i]);
sort(vv.begin(), vv.end(), [&](pair<int, int> x, pair<int, int> y){
return x.second<y.second;
});
for (auto &i:vv){
if (v.empty() || i.first>v.back().second) v.push_back(i);
}
cout << v.size() << '\n';
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |