답안 #998456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998456 2024-06-14T02:26:32 Z cpptowin Fuel Station (NOI20_fuelstation) C++17
0 / 100
227 ms 72152 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
struct SegmentTree
{
    vector<int> st, lazy;
    int n;
    /// real n
    SegmentTree(int _n = 0) : n(_n)
    {
        st.resize(4 * n + 10);
        lazy.resize(4 * n + 10);
    }
    void resize(int _n)
    {
        n = _n;
        st.resize(4 * n + 10);
        lazy.resize(4 * n + 10);
    }

    void update(int id, int l, int r, int x, int val)
    {
        if (l > x or r < x)
            return;
        if (l == r)
        {
            st[id] += val;
            return;
        }
        int mid = l + r >> 1;
        update(id << 1, l, mid, x, val);
        update(id << 1 | 1, mid + 1, r, x, val);
        st[id] = st[id << 1] + st[id << 1 | 1];
    }

    int get(int id, int l, int r, int u, int v)
    {
        if (l > v || u > r)
            return 0;
        if (u <= l && r <= v)
            return st[id];
        int mid = (l + r) >> 1;
        return get(id << 1, l, mid, u, v) + get(id << 1 | 1, mid + 1, r, u, v);
    }
    int get(int l, int r)
    {
        return get(1, 1, n, l, r);
    }
    void update(int x, int val)
    {
        update(1, 1, n, x, val);
    }
};
int n;
vii ke[maxn];
vi nen;
int x[maxn], a[maxn], b[maxn];
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int d;
    cin >> n >> d;
    fo(i, 1, n)
    {
        cin >> x[i] >> a[i] >> b[i];
        nen.pb(b[i]);
    }
    SegmentTree st(n);
    sort(all(nen));
    nen.erase(unique(all(nen)),nen.end());
    fo(i,1,n)
    {
        b[i] = lower_bound(all(nen),b[i]) - nen.begin() + 1;
        ke[b[i]].pb(x[i],a[i]);
    }
    sort(all(nen),greater<int>());
    int ans = inf;
    sort(x + 1,x + n + 1);
    fo(it,1,(int)nen.size())
    {
        for(auto [i,u] : ke[it])
        {
            int lb = lower_bound(x + 1,x + n + 1,i) - x;
            int val = st.get(1,lb);
            st.update(lb,min(max(0LL,d - i - val),u));
        }
        if(d - st.st[1] <= nen[it - 1]) minimize(ans,d - st.st[1]);
    }
    cout << ans;
}

Compilation message

FuelStation.cpp: In member function 'void SegmentTree::update(long long int, long long int, long long int, long long int, long long int)':
FuelStation.cpp:69:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   69 |         int mid = l + r >> 1;
      |                   ~~^~~
FuelStation.cpp: At global scope:
FuelStation.cpp:97:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   97 | main()
      | ^~~~
FuelStation.cpp: In function 'int main()':
FuelStation.cpp:102:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
FuelStation.cpp:103:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 28764 KB Output is correct
2 Incorrect 5 ms 28764 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 227 ms 72152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 28760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 28760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 28764 KB Output is correct
2 Incorrect 5 ms 28764 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 28764 KB Output is correct
2 Incorrect 5 ms 28764 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 28764 KB Output is correct
2 Incorrect 5 ms 28764 KB Output isn't correct
3 Halted 0 ms 0 KB -