답안 #320419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
320419 2020-11-08T17:07:52 Z tasfiq4 Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
34 ms 7148 KB
/// #
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<lld,lld > pii;
#define pi acos(-1)
#define fr(i,m,n) for(i=m;i<n;i++)
#define fu(i,m,n) for(i=m;i>=n;i--)
#define vec vector<lld>
#define pb push_back
#define pp pop_back()
#define ft first
#define sd second
#define all(v) v.begin(),v.end()
#define mom(ara) memset(ara,0,sizeof(ara));
#define m1m(ara) memset(ara,-1,sizeof(ara));
#define endl "\n"
#define eps 1.19209e-07
const lld mod=1e9+7;
lld pref[100010],suf[100010];
lld cal(lld x,lld y)
{
	x%=mod;y%=mod;
	lld i=(x*(x+1))/2,j=(y*(y+1))/2;
	i%=mod;j%=mod;
	return (i*j)%mod;
}
int main()
{ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    lld i,j,k,a,b,c,x,y,z,n,m,ans,t;

    cin>>n;
    vec h,w;
    fr(i,0,n)
    {
    	cin>>x;
    	h.pb(x);
    }
    fr(i,0,n)
    {
    	cin>>x;
    	w.pb(x);
    }
    stack<pii> st;
    fr(i,0,n)
    {
    	if(st.empty() || st.top().ft<h[i])
    	{
    		st.push({h[i],w[i]});
    		pref[i]=0;
    	}
    	else
    	{
    		x=0;
    		while(!st.empty() && st.top().ft>=h[i])
    		{
    			x+=st.top().sd;
    			st.pop();
    		}
    		pref[i]=x;
    		st.push({h[i],x+w[i]});
    	}
    }
    while(!st.empty()) st.pop();
    fu(i,n-1,0)
    {
    	if(st.empty() || st.top().ft<=h[i])
    	{
    		st.push({h[i],w[i]});
    		suf[i]=0;
    	}
    	else
    	{
    		x=0;
    		while(!st.empty() && st.top().ft>h[i])
    		{
    			x+=st.top().sd;
    			st.pop();
    		}
    		suf[i]=x;
    		st.push({h[i],x+w[i]});
    	}
    }
    ans=0;
    fr(i,0,n)
    {
    	ans+=cal(h[i],pref[i]+w[i]+suf[i]);
    	ans%=mod;
    	ans-=(cal(pref[i],h[i])+cal(suf[i],h[i]))%mod;
    	ans+=mod;
    	ans%=mod;
    }
    cout<<ans<<endl;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:30:11: warning: unused variable 'j' [-Wunused-variable]
   30 |     lld i,j,k,a,b,c,x,y,z,n,m,ans,t;
      |           ^
fancyfence.cpp:30:13: warning: unused variable 'k' [-Wunused-variable]
   30 |     lld i,j,k,a,b,c,x,y,z,n,m,ans,t;
      |             ^
fancyfence.cpp:30:15: warning: unused variable 'a' [-Wunused-variable]
   30 |     lld i,j,k,a,b,c,x,y,z,n,m,ans,t;
      |               ^
fancyfence.cpp:30:17: warning: unused variable 'b' [-Wunused-variable]
   30 |     lld i,j,k,a,b,c,x,y,z,n,m,ans,t;
      |                 ^
fancyfence.cpp:30:19: warning: unused variable 'c' [-Wunused-variable]
   30 |     lld i,j,k,a,b,c,x,y,z,n,m,ans,t;
      |                   ^
fancyfence.cpp:30:23: warning: unused variable 'y' [-Wunused-variable]
   30 |     lld i,j,k,a,b,c,x,y,z,n,m,ans,t;
      |                       ^
fancyfence.cpp:30:25: warning: unused variable 'z' [-Wunused-variable]
   30 |     lld i,j,k,a,b,c,x,y,z,n,m,ans,t;
      |                         ^
fancyfence.cpp:30:29: warning: unused variable 'm' [-Wunused-variable]
   30 |     lld i,j,k,a,b,c,x,y,z,n,m,ans,t;
      |                             ^
fancyfence.cpp:30:35: warning: unused variable 't' [-Wunused-variable]
   30 |     lld i,j,k,a,b,c,x,y,z,n,m,ans,t;
      |                                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 14 ms 2928 KB Output is correct
4 Correct 26 ms 5988 KB Output is correct
5 Correct 27 ms 5356 KB Output is correct
6 Correct 26 ms 4972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 5 ms 1260 KB Output is correct
3 Correct 16 ms 3696 KB Output is correct
4 Correct 31 ms 7136 KB Output is correct
5 Correct 34 ms 7144 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 4 ms 1004 KB Output is correct
4 Correct 16 ms 3696 KB Output is correct
5 Correct 31 ms 7148 KB Output is correct
6 Correct 34 ms 7140 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 4 ms 1004 KB Output is correct
9 Correct 17 ms 3456 KB Output is correct
10 Correct 31 ms 7012 KB Output is correct
11 Correct 32 ms 7012 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 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 0 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 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 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
# 결과 실행 시간 메모리 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 0 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 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 14 ms 2928 KB Output is correct
12 Correct 27 ms 5996 KB Output is correct
13 Correct 27 ms 5348 KB Output is correct
14 Correct 26 ms 4876 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 4 ms 1004 KB Output is correct
17 Correct 16 ms 3696 KB Output is correct
18 Correct 32 ms 7136 KB Output is correct
19 Correct 34 ms 7140 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 4 ms 1004 KB Output is correct
22 Correct 16 ms 3440 KB Output is correct
23 Correct 31 ms 7012 KB Output is correct
24 Correct 31 ms 7020 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 1 ms 364 KB Output is correct
30 Correct 4 ms 1004 KB Output is correct
31 Correct 4 ms 1004 KB Output is correct
32 Correct 16 ms 2928 KB Output is correct
33 Correct 17 ms 3056 KB Output is correct
34 Correct 31 ms 5344 KB Output is correct
35 Correct 31 ms 5348 KB Output is correct
36 Correct 32 ms 5600 KB Output is correct
37 Correct 32 ms 5612 KB Output is correct
38 Correct 0 ms 364 KB Output is correct
39 Correct 31 ms 5604 KB Output is correct
40 Correct 32 ms 5612 KB Output is correct
41 Correct 31 ms 5624 KB Output is correct
42 Correct 34 ms 6244 KB Output is correct