제출 #487925

#제출 시각아이디문제언어결과실행 시간메모리
487925MilosMilutinovicFancy Fence (CEOI20_fancyfence)C++14
100 / 100
29 ms5104 KiB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const ll mod2=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=101000;
int n,h[N],w[N],l[N],r[N];
ll pf[N];

int main() {
	scanf("%d",&n);
	rep(i,1,n+1) scanf("%d",h+i);
	rep(i,1,n+1) scanf("%d",w+i);
	rep(i,1,n+1) pf[i]=pf[i-1]+w[i];
	stack<int> stk;
	rep(i,1,n+1) {
		while (SZ(stk)&&h[stk.top()]>h[i]) stk.pop();
		l[i]=(SZ(stk)?stk.top()+1:1);
		stk.push(i);
	}
	while (SZ(stk)) stk.pop();
	per(i,1,n+1) {
		while (SZ(stk)&&h[stk.top()]>=h[i]) stk.pop();
		r[i]=(SZ(stk)?stk.top()-1:n);
		stk.push(i);
	}	
	//rep(i,1,n+1) printf("%d ",l[i]); puts("");
	//rep(i,1,n+1) printf("%d ",r[i]); puts("");
	ll ans=0;
	rep(i,1,n+1) {
		int L=l[i],R=r[i];
		ll sl=(pf[i-1]-pf[L-1])%mod;
		ll sr=(pf[R]-pf[i])%mod;
		ll x=((ll)h[i]*(h[i]+1)/2)%mod;
		ll y=((ll)w[i]*(w[i]+1)/2)%mod;
		ans=(ans+((x*sl)%mod)*(sr+w[i])%mod)%mod;
		ans=(ans+((x*w[i])%mod)*sr)%mod;
		ans=(ans+x*y)%mod;
	}
	printf("%lld",ans);
}

컴파일 시 표준 에러 (stderr) 메시지

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
fancyfence.cpp:29:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  rep(i,1,n+1) scanf("%d",h+i);
      |               ~~~~~^~~~~~~~~~
fancyfence.cpp:30:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  rep(i,1,n+1) scanf("%d",w+i);
      |               ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...