QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#684326 | #6626. Real Mountains | cocoa_chan | 3 | 7ms | 43684kb | C++14 | 2.9kb | 2024-10-28 12:37:11 | 2024-10-28 12:37:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll inf=1e18,siz=1048576,mod=1000003;
ll n,m,i,j,k,l,r,x,y,z,w,s,t,a[1100000],seg[2200000],num,b[1100000];
set<ll> st;
vector<ll> u;
vector<pair<ll,ll>> v[1100000];
ll lb(ll x)
{
return lower_bound(u.begin(),u.end(),x)-u.begin();
}
void f(ll x)
{
seg[x]=min(seg[x*2],seg[x*2+1]);
if(x==1)
return;
f(x/2);
}
ll g(ll x,ll y,ll z)
{
if(l>y||x>r)
return inf;
if(l<=x&&y<=r)
return seg[z];
return min(g(x,(x+y)/2,z*2),g((x+y)/2+1,y,z*2+1));
}
ll sum(ll x,ll y)
{
return y*(y+1)/2-x*(x-1)/2;
}
ll find_smallest(ll x,ll y)
{
l=x;
r=y;
return g(1,siz,1);
}
int main()
{
scanf("%lld",&n);
for(i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
s=0;
r=0;
for(i=1;i<=n;i++)
{
if(a[i]>=s)
{
s=a[i];
r=i;
}
}
s=0;
l=0;
for(i=n;i>=1;i--)
{
if(a[i]>=s)
{
s=a[i];
l=i;
}
}
s=0;
for(i=1;i<=r;i++)
{
s=max(s,a[i]);
b[i]=s;
}
s=0;
for(i=n;i>=l;i--)
{
s=max(s,a[i]);
b[i]=s;
}
/*for(i=1;i<=n;i++)
printf("%lld ",b[i]);
printf("\n");
*/s=0;
for(i=1;i<=n;i++)
{
u.push_back(a[i]);
u.push_back(b[i]);
seg[i+siz-1]=a[i];
f((i+siz-1)/2);
s+=sum(a[i],b[i]-1);
s%=mod;
}
//printf("(%lld)\n",s);
sort(u.begin(),u.end());
u.erase(unique(u.begin(),u.end()),u.end());
for(i=1;i<=n;i++)
{
/*if(a[i]==b[i])
continue;
*/v[lb(a[i])].push_back({1,i});
v[lb(b[i])].push_back({0,i});
}
num=0;
for(i=0;i<ll(u.size())-1;i++)
{
for(auto p:v[i])
{
x=p.first;
y=p.second;
if(x)
{
num++;
st.insert(y);
seg[y+siz-1]=inf;
f((y+siz-1)/2);
}
else
{
num--;
st.erase(y);
}
}
if(st.empty())
continue;
l=(*st.begin());
r=(*(--st.end()));
if(l==r)
{
z=0;
z+=find_smallest(1,l-1);
z+=find_smallest(r+1,n);
//printf("(%lld->%lld:%lld)\n",u[i],u[i+1],z*(u[i+1]-u[i]));
s+=z*(u[i+1]-u[i]);
s%=mod;
continue;
}
z=0;
z+=find_smallest(1,l-1);
z+=find_smallest(r+1,n);
z+=min(find_smallest(l+1,n),find_smallest(1,r-1));
z*=(u[i+1]-u[i]);
//printf("(%lld->%lld:%lld)\n",u[i],u[i+1],z+(2*num-3)*sum(u[i]+1,u[i+1]));
s+=z+(2*num-3)*sum(u[i]+1,u[i+1]);
s%=mod;
}
s%=mod;
printf("%lld",s);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 0ms
memory: 41664kb
input:
3 29 9 9
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 3
Accepted
time: 4ms
memory: 40320kb
input:
3 62 20 71
output:
7287
result:
ok 1 number(s): "7287"
Test #3:
score: 3
Accepted
time: 0ms
memory: 40940kb
input:
10 72 33 22 22 13 49 53 57 72 85
output:
40403
result:
ok 1 number(s): "40403"
Test #4:
score: 3
Accepted
time: 4ms
memory: 40264kb
input:
5000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 97 97 97 97 9...
output:
481053
result:
ok 1 number(s): "481053"
Test #5:
score: 3
Accepted
time: 3ms
memory: 41904kb
input:
5000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 3
Accepted
time: 6ms
memory: 41296kb
input:
5000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...
output:
12595
result:
ok 1 number(s): "12595"
Test #7:
score: 3
Accepted
time: 4ms
memory: 41788kb
input:
5000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...
output:
299
result:
ok 1 number(s): "299"
Test #8:
score: 3
Accepted
time: 5ms
memory: 41984kb
input:
5000 100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
224232
result:
ok 1 number(s): "224232"
Test #9:
score: 3
Accepted
time: 7ms
memory: 43684kb
input:
5000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4...
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 3
Accepted
time: 0ms
memory: 41652kb
input:
5000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 9...
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 3
Accepted
time: 6ms
memory: 40304kb
input:
5000 100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4...
output:
499735
result:
ok 1 number(s): "499735"
Test #12:
score: 3
Accepted
time: 7ms
memory: 41204kb
input:
5000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 9...
output:
461407
result:
ok 1 number(s): "461407"
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #13:
score: 0
Wrong Answer
time: 0ms
memory: 41160kb
input:
5000 37 39 93 78 85 71 59 21 57 96 61 59 23 16 57 90 13 59 85 70 62 67 78 97 16 60 8 48 28 53 4 24 1 97 97 98 57 87 96 91 74 54 100 76 86 86 46 39 100 57 70 76 73 55 84 93 64 6 84 39 75 94 30 15 3 31 11 34 27 10 6 81 30 76 60 9 4 47 1 88 17 71 61 30 19 10 4 57 79 37 22 74 84 8 91 58 15 45 7 98 32 46...
output:
214154
result:
wrong answer 1st numbers differ - expected: '216624', found: '214154'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #3:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%