제출 #1329722

#제출 시각아이디문제언어결과실행 시간메모리
1329722nguyenkhanghuyFancy Fence (CEOI20_fancyfence)C++20
0 / 100
1 ms344 KiB
#include <bits/stdc++.h>
#define int int64_t
using namespace std;

#define endl '\n'

const int nmax = 1e5 + 5, mod = 1e9 + 7;
int n, h[nmax], w[nmax], wp[nmax];
int st[4 * nmax], res, st_1[4 * nmax], lz[4 * nmax];

void lazy(int id)
{
    if(lz[id] != 0)
    {
        st_1[id << 1] = max({st_1[id << 1], lz[id], lz[id << 1]});
        lz[id << 1] = max(lz[id << 1], lz[id]);

        st_1[id << 1 | 1] = max({st_1[id << 1 | 1], lz[id], lz[id << 1 | 1]});
        lz[id << 1 | 1] = max(lz[id << 1 | 1], lz[id]);

        lz[id] = 0;
    }
}

void update_1(int id, int l, int r, int u, int v, int val)
{
    if(l > v || r < u)
        return;

    if(l >= u && r <= v)
    {
        st_1[id] = max(st_1[id], val);
        lz[id] = val;
        return;
    }

    int mid = (l + r) >> 1;
    lazy(id);
    update_1(id << 1, l, mid, u, v, val);
    update_1(id << 1 | 1, mid + 1, r, u, v, val);
    st_1[id] = max(st_1[id << 1], st_1[id << 1 | 1]);
}

int get_1(int id, int l, int r, int pos)
{
    if(pos > r || pos < l)
        return 0;

    if(l == r)
        return st_1[id];

    int mid = (l + r) >> 1;
    lazy(id);
    return max(get_1(id << 1, l, mid, pos), get_1(id << 1 | 1, mid + 1, r, pos));
}

void update(int id, int l, int r, int pos, int val)
{
    if(r < pos || l > pos)
        return;

    if(l == r)
    {
        st[id] = val;
        return;
    }

    int mid = (l + r) >> 1;
    update(id << 1, l, mid, pos, val);
    update(id << 1 | 1, mid + 1, r, pos, val);
    st[id] = min(st[id << 1], st[id << 1 | 1]);
}

int get_r(int id, int l, int r, int pos, int val)
{
    if(st[id] >= val || r < pos)
        return n + 1;

    if(l == r)
        return l;

    int mid = (l + r) >> 1;
    int kq = get_r(id << 1, l, mid, pos, val);
    if(kq == n + 1)
        kq = get_r(id << 1 | 1, mid + 1, r, pos, val);
    return kq;
}

int get_l(int id, int l, int r, int pos, int val)
{
    if(st[id] >= val || pos < l)
        return 0;

    if(l == r)
        return l;

    int mid = (l + r) >> 1;
    int kq = get_l(id << 1 | 1, mid + 1, r, pos, val);
    if(kq == 0)
        kq = get_l(id << 1, l, mid, pos, val);
    return kq;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    freopen("FENCE.INP", "r", stdin);
    freopen("FENCE.OUT", "w", stdout);

    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>h[i];
        update(1, 1, n, i, h[i]);
    }
    for(int i=1; i<=n; i++)
    {
        cin>>w[i];
        wp[i] = wp[i-1] + w[i];
    }
    for(int i=1, l, r, tmp_1, tmp_2, ck; i<=n; i++)
    {
        l = get_l(1, 1, n, i, h[i]) + 1;
        r = get_r(1, 1, n, i, h[i]) - 1;

        tmp_1 = (wp[r] - wp[l-1]) * (wp[r] - wp[l-1] + 1) >> 1;
        tmp_2 = tmp_1 * (h[i] * (h[i] + 1) >> 1);
        tmp_2 -= tmp_1 * get_1(1, 1, n, i);

        res += tmp_2;
        update_1(1, 1, n, l, r, h[i]);
    }
    cout<<res;
}

컴파일 시 표준 에러 (stderr) 메시지

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:110:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |     freopen("FENCE.INP", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fancyfence.cpp:111:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |     freopen("FENCE.OUT", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...