이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#pragma GCC target("avx2,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int B = 18;
const int mxn = 4e5+10;
int N,Q;
int dp[mxn];
int arr[mxn];
int ans[mxn];
pii req[mxn];
bool roll;
void calc(int lvl){
roll = 0;
for(int i = 1;i<=N+1;i++)dp[i] = arr[i];
dp[mxn-1] = mxn-1;
for(int i = 0;i<lvl;i++){
roll ^= 1;
for(int j = 1;j<=N+1;j++){
dp[j] = dp[dp[j]];
}
}
for(int i = 1;i<=Q;i++){
auto &[s,e] = req[i];
if(dp[s]<=e+1){
ans[i] += 1<<lvl;
s = dp[s];
}
}
return;
}
unordered_map<ll,int> mp;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N;
for(int i = 1;i<=N;i++){
cin>>arr[i];
}
int mn = mxn-1;
ll sum = 0;
for(int i = N+1;i>=1;i--){
sum += arr[i];
if(mp.find(sum) != mp.end())mn = min(mn,mp[sum]);
mp[sum] = i;
arr[i] = mn;
}
cin>>Q;
for(int i = 1;i<=Q;i++){
cin>>req[i].fs>>req[i].sc;
}
for(int i = B-1;i>=0;i--)calc(i);
for(int i = 1;i<=Q;i++){
cout<<ans[i]<<'\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... |