Submission #789389

# Submission time Handle Problem Language Result Execution time Memory
789389 2023-07-21T10:12:15 Z JakobZorz Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
34 ms 17152 KB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <limits.h>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <cstring>
#include <sstream>
 
#pragma GCC target("popcnt")
 
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD = 1e9+7;
typedef pair<ld,ld> point;
//#define x first
//#define y second

int n;
ll w[100000],h[100000];
ll wsum[100001];
int hmin[100000][20];

int get_hmin(int l,int r){
    int width=r-l;
    int p=0;
    while((1<<p)<=width)
        p++;
    p--;
    
    int a=hmin[l][p];
    int b=hmin[r-(1<<p)][p];
    if(h[a]<h[b])
        return a;
    else
        return b;
}

ll get_combs(ll w,ll h){
    ll c1=w*(w+1)/2;
    c1%=MOD;
    ll c2=h*(h+1)/2;
    c2%=MOD;
    return(c1*c2)%MOD;
}

ll get(int l,int r,ll level){
    if(l==r)
        return 0;
    int m=get_hmin(l,r);
    ll width=(MOD+wsum[r]-wsum[l])%MOD;
    ll res=0;
    res+=get_combs(width,h[m]);
    res+=MOD-get_combs(width,level);
    res+=get(l,m,h[m]);
    res+=get(m+1,r,h[m]);
    return res%MOD;
}

int main(){
    ios::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
    
    //freopen("speeding.in","r",stdin);
    //freopen("speeding.out","w",stdout);
    
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>h[i];
    for(int i=0;i<n;i++)
        cin>>w[i];
    for(int i=0;i<n;i++)
        wsum[i+1]=(wsum[i]+w[i])%MOD;
    
    for(int i=0;i<n;i++)
        hmin[i][0]=i;
    for(int p=1;p<20;p++){
        for(int i=0;i<n;i++){
            int a=i;
            int b=i+(1<<(p-1));
            int c=i+(1<<p);
            if(c>n)
                break;
            if(h[hmin[a][p-1]]<h[hmin[b][p-1]])
                hmin[a][p]=hmin[a][p-1];
            else
                hmin[a][p]=hmin[b][p-1];
        }
    }
    
    cout<<get(0,n,0)<<"\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 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 468 KB Output is correct
3 Correct 11 ms 6880 KB Output is correct
4 Correct 23 ms 15272 KB Output is correct
5 Correct 24 ms 13424 KB Output is correct
6 Correct 21 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 4 ms 1992 KB Output is correct
3 Correct 13 ms 8700 KB Output is correct
4 Correct 28 ms 17068 KB Output is correct
5 Correct 28 ms 17120 KB Output is correct
6 Correct 1 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 464 KB Output is correct
3 Correct 3 ms 2004 KB Output is correct
4 Correct 13 ms 8720 KB Output is correct
5 Correct 27 ms 17116 KB Output is correct
6 Correct 28 ms 17144 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 3 ms 2004 KB Output is correct
9 Correct 13 ms 8660 KB Output is correct
10 Correct 26 ms 16972 KB Output is correct
11 Correct 34 ms 17044 KB Output is correct
12 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 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 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 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 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 0 ms 340 KB Output is correct
2 Correct 1 ms 468 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 0 ms 340 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 14 ms 6868 KB Output is correct
12 Correct 26 ms 15292 KB Output is correct
13 Correct 23 ms 13416 KB Output is correct
14 Correct 21 ms 12032 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 3 ms 2000 KB Output is correct
17 Correct 13 ms 8660 KB Output is correct
18 Correct 27 ms 17100 KB Output is correct
19 Correct 34 ms 17152 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 3 ms 2020 KB Output is correct
22 Correct 15 ms 8748 KB Output is correct
23 Correct 26 ms 16980 KB Output is correct
24 Correct 28 ms 16976 KB Output is correct
25 Correct 0 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 3 ms 1492 KB Output is correct
31 Correct 3 ms 1492 KB Output is correct
32 Correct 14 ms 6296 KB Output is correct
33 Correct 15 ms 6356 KB Output is correct
34 Correct 24 ms 12108 KB Output is correct
35 Correct 23 ms 12224 KB Output is correct
36 Correct 31 ms 12352 KB Output is correct
37 Correct 24 ms 12308 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 24 ms 12296 KB Output is correct
40 Correct 24 ms 12424 KB Output is correct
41 Correct 25 ms 13300 KB Output is correct
42 Correct 26 ms 17084 KB Output is correct