답안 #946368

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946368 2024-03-14T14:43:55 Z Xiaoyang Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
24 ms 5464 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define fi first 
#define se second 
#define pll pair<ll,ll>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl;
#define MP make_pair
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define SZ(x) (ll)x.size()
#define ALL(x) x.begin(),x.end()
#define endl "\n"
const ll inf=1e18;
ll lowbit(ll x){return x&(-x);}



const ll mod=1e9+7;
ll c2(ll x){
	return (x*(x-1)/2)%mod;
}
ll rect(ll x,ll y){
	ll xx=(x*(x+1)/2)%mod;
	ll yy=(y*(y+1)/2)%mod;
	return (xx*yy)%mod;
}

const ll maxn=1e5+5;
ll h[maxn],w[maxn],pre[maxn];

ll inc(ll &a,ll b){return a=(a+b)%mod;}
ll dec(ll &a,ll b){return a=(a-b+mod)%mod;}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n;cin>>n;
	ll sum=0,ans=0;
	rep(i,1,n+1)cin>>h[i];
	rep(i,1,n+1)cin>>w[i];
	
	
	stack<ll>s;
	//monotonically increasing stack 
	rep(i,1,n+1){
		while(!s.empty() and h[i]<=h[s.top()]){
			dec(sum,(c2(h[s.top()]+1)*pre[s.top()])%mod);
			inc(pre[i],pre[s.top()]);
			s.pop();
		}
		s.push(i);
		inc(sum,(c2(h[i]+1)*pre[i])%mod);
		inc(ans,rect(h[i],w[i]));
		inc(ans,(sum*w[i])%mod);
		inc(sum,(c2(h[i]+1)*w[i])%mod);
		
		inc(pre[i],w[i]);
	}
	cout<<ans<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 9 ms 3164 KB Output is correct
4 Correct 14 ms 3932 KB Output is correct
5 Correct 14 ms 3932 KB Output is correct
6 Correct 15 ms 4184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 10 ms 2512 KB Output is correct
4 Correct 22 ms 2652 KB Output is correct
5 Correct 18 ms 2652 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 9 ms 2652 KB Output is correct
5 Correct 17 ms 2652 KB Output is correct
6 Correct 21 ms 2652 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 9 ms 2648 KB Output is correct
10 Correct 16 ms 3416 KB Output is correct
11 Correct 17 ms 3420 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2512 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2480 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2508 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 8 ms 3100 KB Output is correct
12 Correct 17 ms 3932 KB Output is correct
13 Correct 14 ms 3976 KB Output is correct
14 Correct 14 ms 3932 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 10 ms 3420 KB Output is correct
18 Correct 18 ms 4580 KB Output is correct
19 Correct 18 ms 4780 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 10 ms 3676 KB Output is correct
23 Correct 20 ms 5360 KB Output is correct
24 Correct 18 ms 5464 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 3 ms 2716 KB Output is correct
31 Correct 2 ms 2780 KB Output is correct
32 Correct 9 ms 3388 KB Output is correct
33 Correct 9 ms 3420 KB Output is correct
34 Correct 17 ms 4440 KB Output is correct
35 Correct 17 ms 4436 KB Output is correct
36 Correct 18 ms 4700 KB Output is correct
37 Correct 18 ms 4692 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 24 ms 4700 KB Output is correct
40 Correct 18 ms 4696 KB Output is correct
41 Correct 17 ms 4700 KB Output is correct
42 Correct 18 ms 4916 KB Output is correct