Submission #701501

# Submission time Handle Problem Language Result Execution time Memory
701501 2023-02-21T11:20:25 Z PCTprobability Fancy Fence (CEOI20_fancyfence) C++17
73 / 100
89 ms 6060 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*b[i]%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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 26 ms 2300 KB Output is correct
4 Correct 53 ms 5168 KB Output is correct
5 Correct 51 ms 4148 KB Output is correct
6 Correct 55 ms 3376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 8 ms 852 KB Output is correct
3 Correct 38 ms 2228 KB Output is correct
4 Correct 73 ms 4028 KB Output is correct
5 Correct 76 ms 4040 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 11 ms 852 KB Output is correct
4 Correct 38 ms 2216 KB Output is correct
5 Correct 76 ms 4020 KB Output is correct
6 Correct 82 ms 4024 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 8 ms 836 KB Output is correct
9 Correct 38 ms 2220 KB Output is correct
10 Correct 89 ms 4040 KB Output is correct
11 Correct 74 ms 4032 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 28 ms 2216 KB Output is correct
12 Correct 52 ms 5188 KB Output is correct
13 Correct 52 ms 4140 KB Output is correct
14 Correct 53 ms 3392 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 8 ms 952 KB Output is correct
17 Correct 38 ms 3188 KB Output is correct
18 Correct 76 ms 5952 KB Output is correct
19 Correct 87 ms 6060 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 8 ms 948 KB Output is correct
22 Correct 37 ms 3116 KB Output is correct
23 Correct 68 ms 5804 KB Output is correct
24 Correct 72 ms 5944 KB Output is correct
25 Correct 1 ms 256 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 312 KB Output is correct
30 Correct 8 ms 564 KB Output is correct
31 Correct 8 ms 560 KB Output is correct
32 Correct 34 ms 1964 KB Output is correct
33 Correct 37 ms 1964 KB Output is correct
34 Correct 68 ms 3532 KB Output is correct
35 Correct 68 ms 3648 KB Output is correct
36 Correct 74 ms 3788 KB Output is correct
37 Correct 80 ms 3764 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 74 ms 3776 KB Output is correct
40 Incorrect 74 ms 3788 KB Output isn't correct
41 Halted 0 ms 0 KB -