Submission #701504

# Submission time Handle Problem Language Result Execution time Memory
701504 2023-02-21T11:26:32 Z PCTprobability Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
80 ms 4920 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();
    }
    sum2%=mod;
    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 0 ms 224 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 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 25 ms 1716 KB Output is correct
4 Correct 50 ms 4032 KB Output is correct
5 Correct 51 ms 3016 KB Output is correct
6 Correct 50 ms 2240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 7 ms 852 KB Output is correct
3 Correct 36 ms 2116 KB Output is correct
4 Correct 73 ms 4028 KB Output is correct
5 Correct 75 ms 4020 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 8 ms 724 KB Output is correct
4 Correct 38 ms 2228 KB Output is correct
5 Correct 80 ms 4028 KB Output is correct
6 Correct 75 ms 4020 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 7 ms 852 KB Output is correct
9 Correct 38 ms 2228 KB Output is correct
10 Correct 71 ms 4024 KB Output is correct
11 Correct 70 ms 4028 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 284 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 276 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 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 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 25 ms 1608 KB Output is correct
12 Correct 50 ms 4036 KB Output is correct
13 Correct 51 ms 3000 KB Output is correct
14 Correct 50 ms 2248 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 8 ms 852 KB Output is correct
17 Correct 39 ms 2232 KB Output is correct
18 Correct 74 ms 4024 KB Output is correct
19 Correct 75 ms 4040 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 7 ms 832 KB Output is correct
22 Correct 37 ms 2220 KB Output is correct
23 Correct 70 ms 4028 KB Output is correct
24 Correct 71 ms 4020 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 312 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 8 ms 340 KB Output is correct
31 Correct 8 ms 340 KB Output is correct
32 Correct 34 ms 1084 KB Output is correct
33 Correct 37 ms 1076 KB Output is correct
34 Correct 68 ms 1876 KB Output is correct
35 Correct 67 ms 1876 KB Output is correct
36 Correct 76 ms 1876 KB Output is correct
37 Correct 73 ms 1876 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 73 ms 1876 KB Output is correct
40 Correct 74 ms 1876 KB Output is correct
41 Correct 74 ms 4160 KB Output is correct
42 Correct 74 ms 4920 KB Output is correct