답안 #755437

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
755437 2023-06-10T06:05:57 Z otarius 거래 (IZhO13_trading) C++17
0 / 100
1 ms 456 KB
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define sc second
#define ll long long
#define pii pair<int, int>

int t[1200005], lazy[1200005];
void prop(int v, int tl, int tr) {
    t[v] = max(t[v], lazy[v]);
    if (tl != tr) {
        int tm = (tl + tr) / 2;
        lazy[2 * v] = max(lazy[2 * v], lazy[v] - tr + tm);
        lazy[2 * v + 1] = max(lazy[2 * v + 1], lazy[v]);
    }
}
void update(int v, int tl, int tr, int l, int r, int x) {
    if (lazy[v])
        prop(v, tl, tr);
    if (tr < l || tl > r)
        return;
    if (l <= tl && tr <= r) {
        t[v] = max(t[v], x + tr - l);
        if (tl != tr) {
            int tm = (tl + tr) / 2;
            lazy[2 * v] = max(lazy[2 * v], x + tm - tl);
            lazy[2 * v + 1] = max(lazy[2 * v + 1], x + tr - tl);
        }
        return;
    } int tm = (tl + tr) / 2;
    update(2 * v, tl, tm, l, min(r, tm), x);
    if (l >= tm + 1)
        update(2 * v + 1, tm + 1, tr, l, r, x);
    else update(2 * v + 1, tm + 1, tr, tm + 1, r, x + tm + 1 - l);
    t[v] = max(t[2 * v], t[2 * v + 1]);
}
int getans(int v, int tl, int tr, int pos) {
    if (lazy[v])
        prop(v, tl, tr);
    if (tl == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    if (pos <= tm)
        getans(2 * v, tl, tm, pos);
    else getans(2 * v + 1, tm + 1, tr, pos);
}
void solve() {
    int n, m;
    cin >> n >> m;
    int l, r, x;
    while (m--) {
        cin >> l >> r >> x;
        update(1, 1, n, l, r, x);
    } for (int i = 1; i <= n; i++)
        cout << getans(1, 1, n, i) << ' ';
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}

Compilation message

trading.cpp: In function 'int getans(int, int, int, int)':
trading.cpp:47:1: warning: control reaches end of non-void function [-Wreturn-type]
   47 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 456 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -