Submission #606314

# Submission time Handle Problem Language Result Execution time Memory
606314 2022-07-26T06:09:01 Z krit3379 Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
56 ms 12524 KB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define N 100005

int n;
long long t[4*N],mi[4*N],h[N],w[N],qs[N],m,pos,mod=1e9+7,ans;

void cre(int x,int l,int r){
    if(l==r){t[x]=l,mi[x]=h[l];return ;}
    int mid=(l+r)/2;
    cre(x*2,l,mid);
    cre(x*2+1,mid+1,r);
    if(mi[x*2]<mi[x*2+1])t[x]=t[x*2];
    else t[x]=t[x*2+1];
    mi[x]=min(mi[x*2],mi[x*2+1]);
}

void query(int x,int l,int r,int ll,int rr){
    if(l>rr||ll>r||ll>rr)return ;
    if(ll<=l&&r<=rr){
        if(mi[x]<m)m=mi[x],pos=t[x];
        return ;
    }
    int mid=(l+r)/2;
    query(x*2,l,mid,ll,rr);
    query(x*2+1,mid+1,r,ll,rr);
}

void sol(int l,int r){
    if(l>r)return ;
    m=1e18;
    query(1,1,n,l,r);
    long long p=h[pos]*(h[pos]+1)/2%mod;
    ans=(ans+p*(w[pos]*(w[pos]+1)/2%mod))%mod;
    ans=(ans+p*(w[pos]*(qs[pos-1]-qs[l-1])%mod))%mod;
    ans=(ans+p*(w[pos]*(qs[r]-qs[pos])%mod))%mod;
    ans=(ans+p*((qs[pos-1]-qs[l-1])*(qs[r]-qs[pos])%mod))%mod;
    int temp=pos;
    sol(l,temp-1),sol(temp+1,r);
}

int main(){
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)scanf("%lld",&h[i]);
    for(i=1;i<=n;i++)scanf("%lld",&w[i]),qs[i]=w[i]+qs[i-1];
    for(i=1;i<=n;i++)qs[i]%=mod;
    cre(1,1,n);
    sol(1,n);
    printf("%lld",ans);
    return 0;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
fancyfence.cpp:47:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     for(i=1;i<=n;i++)scanf("%lld",&h[i]);
      |                      ~~~~~^~~~~~~~~~~~~~
fancyfence.cpp:48:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     for(i=1;i<=n;i++)scanf("%lld",&w[i]),qs[i]=w[i]+qs[i-1];
      |                      ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 316 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 19 ms 4040 KB Output is correct
4 Correct 36 ms 7924 KB Output is correct
5 Correct 49 ms 7916 KB Output is correct
6 Correct 42 ms 7888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 23 ms 4480 KB Output is correct
4 Correct 41 ms 8700 KB Output is correct
5 Correct 43 ms 8744 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 7 ms 1248 KB Output is correct
4 Correct 21 ms 4488 KB Output is correct
5 Correct 44 ms 8604 KB Output is correct
6 Correct 42 ms 8736 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 5 ms 1236 KB Output is correct
9 Correct 19 ms 4552 KB Output is correct
10 Correct 37 ms 8488 KB Output is correct
11 Correct 43 ms 8680 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 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 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 29 ms 4120 KB Output is correct
12 Correct 43 ms 7912 KB Output is correct
13 Correct 40 ms 7900 KB Output is correct
14 Correct 36 ms 7856 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1236 KB Output is correct
17 Correct 30 ms 4424 KB Output is correct
18 Correct 51 ms 8692 KB Output is correct
19 Correct 41 ms 8760 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 4 ms 1236 KB Output is correct
22 Correct 24 ms 4544 KB Output is correct
23 Correct 37 ms 8472 KB Output is correct
24 Correct 47 ms 8576 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 5 ms 1236 KB Output is correct
31 Correct 4 ms 1204 KB Output is correct
32 Correct 21 ms 4436 KB Output is correct
33 Correct 23 ms 4412 KB Output is correct
34 Correct 44 ms 8588 KB Output is correct
35 Correct 42 ms 8472 KB Output is correct
36 Correct 43 ms 8684 KB Output is correct
37 Correct 42 ms 8696 KB Output is correct
38 Correct 0 ms 312 KB Output is correct
39 Correct 47 ms 8712 KB Output is correct
40 Correct 56 ms 8652 KB Output is correct
41 Correct 46 ms 9484 KB Output is correct
42 Correct 50 ms 12524 KB Output is correct