답안 #647115

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647115 2022-10-01T15:40:56 Z jamielim Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
41 ms 6364 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;

int n;
ll h[100005],w[100005],p[100005];
int l[100005],r[100005];

inline ll choose2(ll x){
	x%=MOD;
	return ((x)*(x-1)/2)%MOD;
}

int main(){
	//freopen("sample/input1.txt","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&h[i]);
	for(int i=1;i<=n;i++){
		scanf("%lld",&w[i]);
		p[i]=p[i-1]+w[i];
		p[i]%=MOD;
	}
	vector<ll> stk;
	stk.pb(0);
	for(int i=1;i<=n;i++){
		while(h[stk.back()]>=h[i]){
			stk.pop_back();
		}
		l[i]=stk.back()+1;
		stk.pb(i);
	}
	stk.clear();
	stk.pb(n+1);
	for(int i=n;i>=1;i--){
		while(h[stk.back()]>h[i]){
			stk.pop_back();
		}
		r[i]=stk.back()-1;
		stk.pb(i);
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		ll cur=((p[r[i]]-p[i-1])%MOD)*((p[i]-p[l[i]-1])%MOD)-choose2(w[i])%MOD;
		cur%=MOD;
		cur*=choose2(h[i]+1);
		ans+=cur%MOD;
		ans%=MOD;
	}
	printf("%lld",(ans+MOD)%MOD);
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
fancyfence.cpp:31:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  for(int i=1;i<=n;i++)scanf("%lld",&h[i]);
      |                       ~~~~~^~~~~~~~~~~~~~
fancyfence.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%lld",&w[i]);
      |   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 11 ms 2764 KB Output is correct
4 Correct 26 ms 5584 KB Output is correct
5 Correct 33 ms 5120 KB Output is correct
6 Correct 30 ms 4712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 980 KB Output is correct
3 Correct 20 ms 3144 KB Output is correct
4 Correct 29 ms 5176 KB Output is correct
5 Correct 26 ms 5216 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 5 ms 980 KB Output is correct
4 Correct 18 ms 3236 KB Output is correct
5 Correct 29 ms 5180 KB Output is correct
6 Correct 32 ms 5120 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 4 ms 980 KB Output is correct
9 Correct 16 ms 3000 KB Output is correct
10 Correct 26 ms 5088 KB Output is correct
11 Correct 27 ms 5000 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 17 ms 2776 KB Output is correct
12 Correct 23 ms 5592 KB Output is correct
13 Correct 22 ms 5064 KB Output is correct
14 Correct 22 ms 4768 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 14 ms 3396 KB Output is correct
18 Correct 27 ms 6304 KB Output is correct
19 Correct 27 ms 6364 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 4 ms 980 KB Output is correct
22 Correct 20 ms 3172 KB Output is correct
23 Correct 36 ms 6112 KB Output is correct
24 Correct 37 ms 6240 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 4 ms 836 KB Output is correct
31 Correct 4 ms 732 KB Output is correct
32 Correct 21 ms 2720 KB Output is correct
33 Correct 14 ms 2764 KB Output is correct
34 Correct 41 ms 5044 KB Output is correct
35 Correct 28 ms 5088 KB Output is correct
36 Correct 27 ms 5268 KB Output is correct
37 Correct 40 ms 5320 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 27 ms 5324 KB Output is correct
40 Correct 26 ms 5360 KB Output is correct
41 Correct 26 ms 5568 KB Output is correct
42 Correct 28 ms 5832 KB Output is correct