답안 #701499

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701499 2023-02-21T11:16:15 Z PCTprobability Fancy Fence (CEOI20_fancyfence) C++17
42 / 100
75 ms 6080 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
#define fi first
#define se second
int main(){
  ll n;
  cin>>n;
  vector<ll> a(n),b(n);
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) cin>>b[i];
  ll ans=0;
  for(int i=0;i<n;i++) (ans+=((b[i]*(b[i]+1))/2%mod)*((a[i]*(a[i]+1)/2)%mod))%=mod;
  ans%=mod;
  vector<pair<ll,ll>> s;
  ll sum=0;
  for(int i=0;i<n;i++){
    if(i==0){
      s.push_back({a[i],b[i]});
      sum+=(a[i]*(a[i]+1)/2)%mod*b[i];
      sum%=mod;
      continue;
    }
    ll sum2=b[i];
    while(s.size()&&s.back().fi>a[i]){
      sum2+=s.back().se;
      sum-=(s.back().fi*(s.back().fi+1)/2%mod)*s.back().se%mod;
      sum%=mod;
      sum+=mod;
      sum%=mod;
      s.pop_back();
    }
    ans+=sum*b[i];
    ans+=(a[i]*(a[i]+1)/2%mod)*(sum2-b[i]+mod)%mod;
    sum+=(a[i]*(a[i]+1)/2)%mod*sum2%mod;
    sum%=mod;
    ans%=mod;
    s.push_back({a[i],sum2%mod});
  }
  cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 224 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 8 ms 1036 KB Output is correct
3 Correct 40 ms 3100 KB Output is correct
4 Correct 73 ms 5932 KB Output is correct
5 Correct 75 ms 6080 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 8 ms 980 KB Output is correct
4 Correct 36 ms 3192 KB Output is correct
5 Correct 72 ms 5940 KB Output is correct
6 Correct 75 ms 6052 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 8 ms 952 KB Output is correct
9 Correct 38 ms 3240 KB Output is correct
10 Correct 70 ms 5816 KB Output is correct
11 Correct 75 ms 5924 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 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 212 KB Output isn't correct
3 Halted 0 ms 0 KB -