이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<random>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*x)
#define rc (2*x+1)
using namespace std;
const int N = 400009;
int n;
int p[N];
map<int,int> mp;
int b[N][19];
int main()
{
d3
cin >> n;
for(int i = 1 ; n>=i ; i++)
{
cin >> p[i];
p[i]+=p[i-1];
}
for(int i = 1 ; n>=i ; i++)
b[i][0]=n+1;
mp[0]=0;
for(int i = 1 ; n>=i ; i++)
{
if(mp[p[i]]==0&&p[i]!=0)
{
mp[p[i]]=i;
continue;
}
int e = mp[p[i]]+1;
mp[p[i]]=i;
b[e][0]=min(b[e][0],i);
}
for(int16_t j = 0 ; 19>j ; j++)
b[n+1][j]=n+1;
for(int i = n ; i>0 ; i--)
b[i][0]=min(b[i][0],b[i+1][0]);
for(int16_t j = 1 ; 19>j ; j++)
{
for(int i = 1 ; n>=i ; i++)
{
b[i][j]=b[b[i][j-1]+1][j-1];
if(b[i][j]==0)
b[i][j]=n+1;
}
}
cin >> n;
while(n--)
{
int l , r;
cin >> l >> r;
int ans = 0;
for(int16_t j = 18 ; j>=0 ; j--)
{
if(l>r)
break;
if(b[l][j]>r)
continue;
ans+=(1<<j);
l=b[l][j]+1;
}
cans
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |