# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
791370 | Amylopectin | Fancy Fence (CEOI20_fancyfence) | C++14 | 55 ms | 9676 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 <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stdlib.h>
using namespace std;
const long long mxn = 1e6 + 10,mo = 1e9 + 7;
struct we
{
long long hhei,idx;
};
bool cmp(const struct we &l,const struct we &r)
{
return l.hhei < r.hhei;
}
set<long long> see = {};
struct we sot[mxn] = {};
long long hei[mxn] = {},wei[mxn] = {},chei[mxn] = {},enn[mxn] = {};
long long pot(long long l)
{
long long cn = (l * (l+1)) / 2;
return cn % mo;
}
int main()
{
// freopen("input1.txt","r",stdin);
long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen;
set<long long> :: iterator f;
scanf("%lld",&n);
for(i=0; i<n; i++)
{
scanf("%lld",&hei[i]);
sot[i] = {hei[i],i};
}
for(i=1; i<=n; i++)
{
scanf("%lld",&wei[i]);
wei[i] += wei[i-1];
}
sort(sot,sot+n,cmp);
see.insert(0);
chei[0] = 0;
enn[0] = n-1;
su = 0;
for(i=0; i<n; i++)
{
cn = sot[i].idx;
f = see.upper_bound(cn);
cl = (*(prev(f)));
cen = enn[cl];
fn = pot((wei[cen+1] - wei[cl])%mo);
fm = (pot(hei[cn]) - pot(chei[cl]));
if(fm < 0)
{
fm += mo;
}
su += (fn * fm) % mo;
su %= mo;
if(cn > cl)
{
chei[cl] = hei[cn];
enn[cl] = cn-1;
}
if(cen > cn)
{
see.insert(cn+1);
chei[cn+1] = hei[cn];
enn[cn+1] = cen;
}
}
printf("%lld\n",su);
return 0;
}
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... |