답안 #298017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
298017 2020-09-12T09:48:42 Z VusetOrucov Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
37 ms 6000 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define black_tree tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pair_black_tree tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update>
#define gp __gnu_pbds
#define INF 1000000000
#define MOD 1000000007
#define MAX 100001
#define endl '\n'
#define ll long long
#define ld long double
#define lli long long int
#define ull unsigned long long
#define ulli unsigned long long int
#define pb push_back
#define pf push_front
#define ook order_of_key
#define fbo find_by_order
#define np next_permutation
#define mp make_pair
#define eb emplace_back 
#define mae max_element
#define mie min_element
#define lb lower_bound 
#define ub upper_bound
#define bs binary_search
#define ff first
#define ss second
using namespace std;
using namespace gp;
vector<pair<ll,ll> >v;
vector<ll>h(MAX),w(MAX);
ll n,a,b,c,ans,k=500000004;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	for(int i=0;i<n;i++){
		cin>>w[i];
	}
	v.pb({0,0});
	for(int i=0;i<=n;i++){
		c=0;
		while(v.back().ff>h[i]){
			a=max(h[i],v[v.size()-2].ff);
			b=v.back().ff-a;
			c=(c+v.back().ss)%MOD;
			v.pop_back();
			ans+=(((b*(b+1)%MOD)*k)%MOD+(a*b)%MOD)*(((c*(c+1)%MOD)*k)%MOD)%MOD;
			ans%=MOD;
		}
		if(v.back().ff==h[i]){
			v.back().ss=(v.back().ss+c+w[i])%MOD;
		}
		else{
			v.pb({h[i],(c+w[i])%MOD});
		}
	}
	cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 2 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1920 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 1 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1920 KB Output is correct
3 Correct 10 ms 2432 KB Output is correct
4 Correct 20 ms 3072 KB Output is correct
5 Correct 19 ms 3072 KB Output is correct
6 Correct 19 ms 3072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 5 ms 2048 KB Output is correct
3 Correct 18 ms 2944 KB Output is correct
4 Correct 25 ms 3840 KB Output is correct
5 Correct 32 ms 3968 KB Output is correct
6 Correct 1 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 2 ms 1920 KB Output is correct
3 Correct 5 ms 2048 KB Output is correct
4 Correct 19 ms 2816 KB Output is correct
5 Correct 24 ms 3840 KB Output is correct
6 Correct 27 ms 3968 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 4 ms 2432 KB Output is correct
9 Correct 14 ms 3584 KB Output is correct
10 Correct 37 ms 5872 KB Output is correct
11 Correct 28 ms 6000 KB Output is correct
12 Correct 2 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 2 ms 1920 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 2 ms 2032 KB Output is correct
6 Correct 1 ms 1920 KB Output is correct
7 Correct 1 ms 1920 KB Output is correct
8 Correct 2 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 1 ms 1920 KB Output is correct
12 Correct 2 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 2 ms 1920 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
16 Correct 1 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 2 ms 1920 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 2 ms 1920 KB Output is correct
5 Correct 2 ms 1920 KB Output is correct
6 Correct 1 ms 1920 KB Output is correct
7 Correct 1 ms 1920 KB Output is correct
8 Correct 1 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 11 ms 2560 KB Output is correct
12 Correct 20 ms 3072 KB Output is correct
13 Correct 20 ms 3072 KB Output is correct
14 Correct 20 ms 3072 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
16 Correct 4 ms 2048 KB Output is correct
17 Correct 13 ms 2816 KB Output is correct
18 Correct 25 ms 3840 KB Output is correct
19 Correct 27 ms 3968 KB Output is correct
20 Correct 2 ms 1920 KB Output is correct
21 Correct 4 ms 2432 KB Output is correct
22 Correct 15 ms 3584 KB Output is correct
23 Correct 27 ms 5880 KB Output is correct
24 Correct 28 ms 6000 KB Output is correct
25 Correct 1 ms 1920 KB Output is correct
26 Correct 2 ms 1920 KB Output is correct
27 Correct 2 ms 1920 KB Output is correct
28 Correct 2 ms 1920 KB Output is correct
29 Correct 2 ms 1920 KB Output is correct
30 Correct 4 ms 2048 KB Output is correct
31 Correct 4 ms 2048 KB Output is correct
32 Correct 14 ms 2816 KB Output is correct
33 Correct 17 ms 2816 KB Output is correct
34 Correct 26 ms 3712 KB Output is correct
35 Correct 26 ms 3712 KB Output is correct
36 Correct 27 ms 3832 KB Output is correct
37 Correct 27 ms 3840 KB Output is correct
38 Correct 1 ms 1920 KB Output is correct
39 Correct 26 ms 3840 KB Output is correct
40 Correct 28 ms 3840 KB Output is correct
41 Correct 27 ms 4216 KB Output is correct
42 Correct 28 ms 4988 KB Output is correct