답안 #963086

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963086 2024-04-14T13:34:28 Z anton Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
28 ms 6324 KB
#include<bits/stdc++.h>

using namespace std;
#define int long long
#define pii pair<int,int>

const int MAX_N = 1e5+1;
const int mod =1e9+7;

int h[MAX_N];
int w[MAX_N];

int nbp(int u){
    u = u%mod;
    return (u*(u+1LL)/2LL)%mod;
}
struct stak{
    int s =0;
    vector<pii> st;
    stak(){
        st.push_back({0, 0});
    }

    void insert(pii val){
        while(st.back().second>=val.second){
            auto e= st.back();
            val.first+=e.first;
            s = (s+mod-(nbp(e.second)*(e.first%mod))%mod)%mod;
            st.pop_back();
        }
        s =(s+(nbp(val.second)*(val.first%mod))%mod)%mod;
        st.push_back(val);
    }
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; 
    cin>>n;
    int sw = 0;
    vector<pair<int, int>> ev;
    for(int i = 0; i<n; i++){
        cin>>h[i];
    }
    for(int i = 0; i<n; i++){
        cin>>w[i];
    }
    int res= 0;
    auto s = stak();
    for(int i = 0; i<n; i++){
        res = (res+ (nbp(w[i]) * nbp(h[i]))%mod)%mod;
        
        s.insert({0, h[i]});
        res = (res + ((w[i]%mod)*s.s)%mod)%mod;
        s.insert({w[i], h[i]});
    }

    cout<<res<<endl;



}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:42:9: warning: unused variable 'sw' [-Wunused-variable]
   42 |     int sw = 0;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 8 ms 1116 KB Output is correct
4 Correct 18 ms 1796 KB Output is correct
5 Correct 16 ms 1884 KB Output is correct
6 Correct 16 ms 2024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 10 ms 2220 KB Output is correct
4 Correct 22 ms 3792 KB Output is correct
5 Correct 21 ms 4036 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 11 ms 2128 KB Output is correct
5 Correct 20 ms 3932 KB Output is correct
6 Correct 28 ms 4044 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 11 ms 2784 KB Output is correct
10 Correct 20 ms 5848 KB Output is correct
11 Correct 21 ms 5936 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 356 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 356 KB Output is correct
13 Correct 1 ms 356 KB Output is correct
14 Correct 1 ms 360 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 0 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 356 KB Output is correct
5 Correct 0 ms 356 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 0 ms 360 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 9 ms 1628 KB Output is correct
12 Correct 16 ms 2944 KB Output is correct
13 Correct 16 ms 3144 KB Output is correct
14 Correct 17 ms 3160 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 3 ms 804 KB Output is correct
17 Correct 15 ms 2140 KB Output is correct
18 Correct 21 ms 3972 KB Output is correct
19 Correct 21 ms 4064 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 1112 KB Output is correct
22 Correct 15 ms 2784 KB Output is correct
23 Correct 22 ms 6048 KB Output is correct
24 Correct 19 ms 6324 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 10 ms 1884 KB Output is correct
33 Correct 10 ms 2008 KB Output is correct
34 Correct 21 ms 3576 KB Output is correct
35 Correct 20 ms 3748 KB Output is correct
36 Correct 22 ms 3932 KB Output is correct
37 Correct 20 ms 3932 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 20 ms 3708 KB Output is correct
40 Correct 20 ms 3896 KB Output is correct
41 Correct 19 ms 4168 KB Output is correct
42 Correct 23 ms 5112 KB Output is correct