# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
471626 | ToroTN | Pilot (NOI19_pilot) | C++14 | 874 ms | 79632 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n,m,a,chk[1000005],p[1000005],node,fuck;
long long cnt=0,ans[1000005],l,r;
vector<int> v[1000005];
int f(int a)
{
if(p[a]==a)
{
return a;
}
return p[a]=f(p[a]);
}
void un(int b,int c)
{
chk[f(c)]+=chk[f(b)];
p[f(b)]=f(c);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%d",&a);
v[a].push_back(i);
chk[i]=1;
}
for(int i=1;i<=1000000;i++)
{
for(int j=0;j<v[i].size();j++)
{
node=v[i][j];
chk[node]=1;
p[node]=node;
l=(long long)(chk[f(node-1)]);
r=(long long)(chk[f(node+1)]);
if(l==0&&r==0)
{
cnt+=1;
}else if(l==0)
{
cnt+=r+(long long)1;
}else if(r==0)
{
cnt+=l+(long long)1;
}else
{
cnt+=(l+(long long)1)*(r+(long long)1);
}
//printf("%lld\n",cnt);
if(p[node-1]!=0)
{
un(node-1,node);
}
if(p[node+1]!=0)
{
un(node+1,node);
}
/*for(int k=1;k<=n;k++)
{
printf("%d ",chk[f(k)]);
}
printf("\n\n");*/
}
ans[i]=cnt;
}
while(m--)
{
scanf("%d",&fuck);
printf("%lld\n",ans[fuck]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |