답안 #697052

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697052 2023-02-08T03:58:31 Z vjudge1 Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
const int mod=1e9+7, maxn=2e5+5;
ll n, h[maxn], pf[maxn], w[maxn], ans, ki, ka, mid, res, leb[maxn];

ll deret(ll a, ll b) {
	return ((b-a+1)*(a+b)/2)%mod;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for(int i=1; i<=n; i++) {
		cin >> h[i];
		pf[i]=pf[i-1];
		if(h[i]==2) pf[i]++;
	}
	for(int i=1; i<=n; i++) {
		cin >> w[i];
		leb[i]=leb[i-1]+w[i];
	}
	for(int i=1; i<=n; i++) {
		ki=leb[n]-leb[i-1], ka=leb[n]-leb[i]+1;
		ans+=deret(ka, ki), ans%=mod;
		if(h[i]==2) {
			ki=i, ka=n;
			while(ki<=ka) {
				mid=(ki+ka)/2;
				if(pf[mid]-pf[i-1]==mid-i+1) res=mid, ki=mid+1;
				else ka=mid-1;
			}
			ki=leb[res]-leb[i-1], ka=leb[res]-leb[i]+1;
			ans+=2*deret(ka, ki);
			ans%=mod;
		}
	}
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -