이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
#define left (h<<1),l,(l + r)/2
#define right ((h<<1)|1),(l + r)/2 + 1,r
using namespace std;
const int N = 4e5 + 3;
unordered_map <int,int> last;
int dp[N],l[N],r[N],p[N];
int to[N],ans[N],cur[N];
signed main(){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>p[i];
}
for (int i = n; i >= 1; i--){
p[i] += p[i + 1];
last[p[i]] = 1e9;
}
last[0] = n + 1;
int k = 1e9;
for (int i = n; i >= 1; i--){
k = min(k,last[p[i]]);
to[i] = k;
last[p[i]] = i;
}
to[n+1] = 1e9;
int q;
cin>>q;
for (int i = 1; i <= q; i++){
cin >> l[i] >> r[i];
}
for (int i = 18; i >= 0; i--){
for (int j = 1; j <= n+1; j++)
cur[j] = to[j];
for (int j = 1; j <= i; j++){
for (int k = 1; k <= n; k++){
if (cur[k] >= 1e9) cur[k] = 1e9;
else cur[k] = cur[cur[k]];
}
}
for (int j = 1; j <= q; j++){
if (cur[l[j]] <= r[j] + 1){
l[j] = cur[l[j]];
ans[j] += (1<<i);
}
}
}
for (int i=1;i<=q;i++)
cout<<ans[i]<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |