답안 #577546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
577546 2022-06-15T04:19:27 Z temporary_juggernaut Fancy Fence (CEOI20_fancyfence) C++14
25 / 100
50 ms 15548 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef juggernaut
    #define printl(args...) printf(args)
#else
    #define printl(args...) 0
#endif
int h[100005];
int w[100005];
ll pref[100005];
int n;
ll mod=1e9+7;
const ll cn=(mod+1)/2;
pair<int,int>sp[100005][17];
int logs[100005];
int get(int l,int r){
	int len=logs[r-l+1];
	return min(sp[l][len],sp[r-(1<<len)+1][len]).sc;
}
ll ans;
void go(int l,int r){
	if(l>r)return;
	int pos=get(l,r);
	ll A=w[pos];
	ll B=h[pos];
	ans+=A*(A+1)/2%mod*(B*(B+1)/2)%mod;
	ans%=mod;
	B=B*(B+1)/2%mod;
	ans+=B*((pref[pos-1]-pref[l-1])%mod)%mod*((pref[r]-pref[pos])%mod)%mod;
	ans%=mod;
	ans+=B*A%mod*((pref[r]-pref[l-1]-A)%mod)%mod;
	ans%=mod;
	go(l,pos-1);
	go(pos+1,r);
}
int main(){
	scanf("%d",&n);
	logs[0]--;
	for(int i=1;i<=n;i++){
		scanf("%d",&h[i]);
		logs[i]=logs[i>>1]+1;
		sp[i][0]=make_pair(h[i],i);
	}
	for(int j=1;j<17;j++)
	for(int i=1;i+(1<<j)-1<=n;i++)sp[i][j]=min(sp[i][j-1],sp[i+(1<<(j-1))][j-1]);
	for(int i=1;i<=n;i++){
		scanf("%d",&w[i]);
		pref[i]=pref[i-1];
		pref[i]+=w[i];
	}
	go(1,n);
	cout<<ans;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
fancyfence.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   scanf("%d",&h[i]);
      |   ~~~~~^~~~~~~~~~~~
fancyfence.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   scanf("%d",&w[i]);
      |   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 20 ms 7892 KB Output is correct
4 Correct 50 ms 15532 KB Output is correct
5 Correct 46 ms 15548 KB Output is correct
6 Correct 46 ms 15544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -