답안 #703424

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703424 2023-02-27T10:08:19 Z Darren0724 Fancy Fence (CEOI20_fancyfence) C++17
15 / 100
27 ms 3028 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
const int mod=1e9+7;
int cal(int left,int right,int up,int down){
    int width=right-left+1;
    width%=mod;
    int ans=width*(width-1)/2;
    ans%=mod;
    int tmp=up*(up+1)-down*(down+1);
    tmp/=2;
    tmp%=mod;
    //cout<<left<<' '<<right<<' '<<up<<' '<<down<<' '<<ans*tmp<<endl;
    return ans*tmp%mod;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    vector<int> a(n+1),b(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
        b[i]+=b[i-1];
    }
    int ans=0;
    vector<int> v;
    v.push_back(0);
    for(int i=1;i<=n;i++){
        while(a[i]<a[v.back()]){
            //cout<<"OK"<<endl;
            int tmp=v.back();
            v.pop_back();
            ans+=cal(b[v.back()],b[i-1],a[tmp],max(a[i],a[v.back()]));
            ans%=mod;
        }
        if(a[i]>a[v.back()]){
            v.push_back(i);
        }
    }
    while(v.size()>1){
        int tmp=v.back();
        v.pop_back();
        ans+=cal(b[v.back()],b[n],a[tmp],a[v.back()]);
        ans%=mod;
    }
    cout<<ans<<endl;

    return 0;
}
/*
4
1 3 2 4
1 1 1 1
32
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 9 ms 1108 KB Output is correct
4 Correct 20 ms 1876 KB Output is correct
5 Correct 22 ms 1908 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 9 ms 1108 KB Output is correct
5 Correct 27 ms 1888 KB Output is correct
6 Correct 25 ms 1884 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 11 ms 1492 KB Output is correct
10 Incorrect 19 ms 3028 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -