Submission #381002

# Submission time Handle Problem Language Result Execution time Memory
381002 2021-03-24T07:27:46 Z iris2617 Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
92 ms 5612 KB
#include<bits/stdc++.h>
#define int long long
#define matsuri pair<int,int>
#define iris 1000000007
using namespace std;

int H[100010],W[100010];
matsuri st[100010];
int p;

int qwq(int a)
{
	int b,res;
	b=iris-2;
	res=1;
	while(b)
	{
		if(b&1)
			res=res*a%iris;
		a=a*a%iris;
		b>>=1;
	}
	return res;
}

int cal(int h,int w)
{
	int ans,ouo;
	h%=iris;
	w%=iris;
	ans=(w*(w-1+iris)%iris*h%iris*(h-1+iris)%iris)%iris;
	ans=ans*qwq(4)%iris;
	ouo=(w*(w-1)%iris*h%iris+h*(h-1)%iris*w)%iris;
	ouo=ouo*qwq(2)%iris;
	ans=(ans+ouo+h*w)%iris;
	return ans;
}

int ccc(int h,int w1,int w2)
{
	h%=iris;
	w1%=iris;
	w2%=iris;
	int sum1,sum2;
	sum1=w1*w2%iris*h%iris;
	sum2=h*w1%iris*h%iris*w2%iris;
	sum1=((sum2-sum1+iris)%iris*qwq(2)%iris+sum1)%iris;
//	cout<<h<<' '<<w1<<' '<<w2<<' '<<sum1<<'\n';
	return sum1;
}

int stacksum;

void pop()
{
	int h,w,aoi;
	h=st[p-1].first;
	w=st[p-1].second;
	aoi=(h+1)*h/2%iris*w%iris;
	stacksum=(stacksum-aoi+iris)%iris;
	p--;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n,h,i,w,ans=0;
	
	cin>>n;
	w=0;
	for(i=0;i<n;i++)
	{
		cin>>H[i];
	}
	for(i=0;i<n;i++)
	{
		cin>>W[i];
	}
	for(i=0;i<n;i++)
	{
		h=H[i];
		w=W[i];
		int ww=w;
		ans+=cal(h,w);
		ans%=iris;
		while(p && st[p-1].first>=h)
		{
			w+=st[p-1].second;
			ans+=ccc(h,st[p-1].second,ww);
			ans%=iris;
			pop();
		}
		ans+=stacksum*ww%iris;
		ans%=iris;
		h%=iris;
		w%=iris;
		st[p++]={h,w};
		stacksum+=(h+1)*h/2%iris*w%iris;
		stacksum%=iris;
	}
	cout<<ans<<'\n';
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 36 ms 1772 KB Output is correct
4 Correct 80 ms 3016 KB Output is correct
5 Correct 71 ms 3052 KB Output is correct
6 Correct 73 ms 3180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 11 ms 748 KB Output is correct
3 Correct 45 ms 2156 KB Output is correct
4 Correct 79 ms 3948 KB Output is correct
5 Correct 80 ms 3948 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 9 ms 748 KB Output is correct
4 Correct 39 ms 2156 KB Output is correct
5 Correct 83 ms 3948 KB Output is correct
6 Correct 92 ms 3948 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 7 ms 876 KB Output is correct
9 Correct 36 ms 2412 KB Output is correct
10 Correct 58 ms 5356 KB Output is correct
11 Correct 60 ms 5356 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 36 ms 1772 KB Output is correct
12 Correct 73 ms 3052 KB Output is correct
13 Correct 81 ms 3148 KB Output is correct
14 Correct 72 ms 3052 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 8 ms 748 KB Output is correct
17 Correct 38 ms 2156 KB Output is correct
18 Correct 78 ms 3948 KB Output is correct
19 Correct 83 ms 3948 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 8 ms 800 KB Output is correct
22 Correct 36 ms 2540 KB Output is correct
23 Correct 59 ms 5356 KB Output is correct
24 Correct 62 ms 5612 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 2 ms 364 KB Output is correct
30 Correct 9 ms 748 KB Output is correct
31 Correct 9 ms 748 KB Output is correct
32 Correct 45 ms 2028 KB Output is correct
33 Correct 44 ms 2156 KB Output is correct
34 Correct 76 ms 3840 KB Output is correct
35 Correct 76 ms 3692 KB Output is correct
36 Correct 83 ms 3832 KB Output is correct
37 Correct 90 ms 3820 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 76 ms 3820 KB Output is correct
40 Correct 76 ms 3820 KB Output is correct
41 Correct 77 ms 4076 KB Output is correct
42 Correct 81 ms 4708 KB Output is correct