답안 #1116434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116434 2024-11-21T16:14:21 Z jamesbamber Fancy Fence (CEOI20_fancyfence) C++17
컴파일 오류
0 ms 0 KB
#include <vector>
#include <stack>
#include <cassert>
#include <iostream>
using namespace std;

constexpr int MOD = 1e9+7;

int maint(){
  	int N; cin >> N;
    vector<int> L(N), W(N);
  	for(int &x: L) cin >> x;
  	for(int &x: W) cin >> x;
    
    L.resize(N+2); 
    W.resize(N+2);
    for(int i=N; i>0; i--) L[i] = L[i-1]; L[0] = 0;
    for(int i=N; i>0; i--) W[i] = W[i-1]; W[0] = 0;
    N+=2; 
    
    vector<int> pf(N+1);
    for(int i=0; i<N; i++) pf[i+1] = (pf[i] + W[i])%MOD;

    auto count_rect = [&](long long l_high, long long l_low, long long w){
        long long l = l_high - l_low;
        return ((w*(w+1)/2)%MOD) * ((l*(l+1)/2)%MOD + l*l_low%MOD)%MOD;
    };

    long long ans = 0;
    stack<int> st;
    for(int i=0; i<N; i++){
        while(st.size() and L[st.top()] >= L[i]){
            int j = st.top(); st.pop();

            if(j == 0) break;

            int l2 = L[j];
            int l1 = max(L[i], L[st.top()]);

            int w = (pf[i] - pf[st.top()+1] + MOD)%MOD;
            ans += count_rect(l2, l1, w);
            ans %= MOD;
        }
        st.push(i);
    }
    assert(st.size() == 1);
    cout ans;
}

Compilation message

fancyfence.cpp: In function 'int maint()':
fancyfence.cpp:17:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   17 |     for(int i=N; i>0; i--) L[i] = L[i-1]; L[0] = 0;
      |     ^~~
fancyfence.cpp:17:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   17 |     for(int i=N; i>0; i--) L[i] = L[i-1]; L[0] = 0;
      |                                           ^
fancyfence.cpp:18:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   18 |     for(int i=N; i>0; i--) W[i] = W[i-1]; W[0] = 0;
      |     ^~~
fancyfence.cpp:18:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   18 |     for(int i=N; i>0; i--) W[i] = W[i-1]; W[0] = 0;
      |                                           ^
fancyfence.cpp:47:9: error: expected ';' before 'ans'
   47 |     cout ans;
      |         ^~~~
      |         ;
fancyfence.cpp:47:5: warning: statement has no effect [-Wunused-value]
   47 |     cout ans;
      |     ^~~~
fancyfence.cpp:11:20: warning: control reaches end of non-void function [-Wreturn-type]
   11 |     vector<int> L(N), W(N);
      |                    ^