답안 #106604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
106604 2019-04-19T07:51:56 Z Alexa2001 Two Dishes (JOI19_dishes) C++17
10 / 100
10000 ms 52884 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int Nmax = 1e6 + 5;


struct restrictie
{
    int x, y, add;
};
vector<restrictie> R[Nmax];

int n, m;


namespace rd
{
    const int bsize = 1<<16;
    char buffer[bsize+2];
    int cursor;

    static void refresh()
    {
        fread(buffer, 1, bsize, stdin), cursor = 0;
    }

    template <typename T>
    static void read(T &x)
    {
        x = 0;
        bool sgn = 0;
        while(!isdigit(buffer[cursor]))
        {
            sgn |= (buffer[cursor] == '-');
            ++cursor;
            if(cursor == bsize) refresh();
        }
        while(isdigit(buffer[cursor]))
        {
            x = x * 10 + buffer[cursor] - '0';
            ++cursor;
            if(cursor == bsize) refresh();
        }
        if(sgn) x *= (-1);
    }
}


void read_and_init()
{
    rd :: refresh();
    rd :: read(n); rd :: read(m);

    int i;
    vector<ll> A(n+1), B(m+1), S(n+1), T(m+1);
    vector<int> P(n+1), Q(m+1), T1(n+1), T2(m+1);

    for(i=1; i<=n; ++i) rd :: read(A[i]), rd :: read(S[i]), rd :: read(P[i]);
    for(i=1; i<=m; ++i) rd :: read(B[i]), rd :: read(T[i]), rd :: read(Q[i]);

    for(i=1; i<=n; ++i) A[i] += A[i-1];
    for(i=1; i<=m; ++i) B[i] += B[i-1];

    for(i=1; i<=n; ++i)
        T1[i] = upper_bound(B.begin(), B.end(), S[i] - A[i]) - B.begin() - 1;

    for(i=1; i<=m; ++i)
        T2[i] = upper_bound(A.begin(), A.end(), T[i] - B[i]) - A.begin() - 1;

    for(i=1; i<=n; ++i)
        R[i].push_back({ 0, T1[i], P[i] });

    for(i=1; i<=m; ++i)
        R[T2[i]+1].push_back({ i, m, Q[i] });
}



class SegTree
{
    ll a[Nmax];

public:


    void maximize()
    {
        int i;
        for(i=1; i<=m; ++i) a[i] = max(a[i], a[i-1]);
    }

    void update(vector<restrictie> &v)
    {
        for(auto it : v)
            for(int i=it.x; i<=it.y; ++i)
                a[i] += it.add;
    }

    void init()
    {
        memset(a, 0, sizeof(a));
    }

    ll query()
    {
        maximize();
        return a[m];
    }
} aint;

void solve()
{
    aint.init();

    int i;
    for(i=1; i<=n; ++i)
    {
        aint.maximize();
        aint.update(R[i]);
    }

    ll ans = aint.query();
    for(auto it : R[n+1]) ans += it.add;
    cout << ans << '\n';
}

int main()
{
  //  freopen("input", "r", stdin);

    read_and_init();
    solve();

    return 0;
}

Compilation message

dishes.cpp: In function 'void rd::refresh()':
dishes.cpp:26:39: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         fread(buffer, 1, bsize, stdin), cursor = 0;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10079 ms 45496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 31616 KB Output is correct
2 Correct 39 ms 31580 KB Output is correct
3 Correct 32 ms 31608 KB Output is correct
4 Correct 34 ms 31608 KB Output is correct
5 Correct 31 ms 31608 KB Output is correct
6 Correct 33 ms 31608 KB Output is correct
7 Correct 33 ms 31608 KB Output is correct
8 Correct 32 ms 31616 KB Output is correct
9 Correct 28 ms 31616 KB Output is correct
10 Correct 31 ms 31616 KB Output is correct
11 Correct 28 ms 31752 KB Output is correct
12 Correct 33 ms 31616 KB Output is correct
13 Correct 32 ms 31736 KB Output is correct
14 Correct 32 ms 31616 KB Output is correct
15 Correct 33 ms 31736 KB Output is correct
16 Correct 36 ms 31608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 31616 KB Output is correct
2 Correct 39 ms 31580 KB Output is correct
3 Correct 32 ms 31608 KB Output is correct
4 Correct 34 ms 31608 KB Output is correct
5 Correct 31 ms 31608 KB Output is correct
6 Correct 33 ms 31608 KB Output is correct
7 Correct 33 ms 31608 KB Output is correct
8 Correct 32 ms 31616 KB Output is correct
9 Correct 28 ms 31616 KB Output is correct
10 Correct 31 ms 31616 KB Output is correct
11 Correct 28 ms 31752 KB Output is correct
12 Correct 33 ms 31616 KB Output is correct
13 Correct 32 ms 31736 KB Output is correct
14 Correct 32 ms 31616 KB Output is correct
15 Correct 33 ms 31736 KB Output is correct
16 Correct 36 ms 31608 KB Output is correct
17 Correct 52 ms 31964 KB Output is correct
18 Correct 51 ms 32164 KB Output is correct
19 Correct 49 ms 32000 KB Output is correct
20 Correct 47 ms 31992 KB Output is correct
21 Correct 45 ms 32120 KB Output is correct
22 Correct 41 ms 31872 KB Output is correct
23 Correct 44 ms 31964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 31616 KB Output is correct
2 Correct 39 ms 31580 KB Output is correct
3 Correct 32 ms 31608 KB Output is correct
4 Correct 34 ms 31608 KB Output is correct
5 Correct 31 ms 31608 KB Output is correct
6 Correct 33 ms 31608 KB Output is correct
7 Correct 33 ms 31608 KB Output is correct
8 Correct 32 ms 31616 KB Output is correct
9 Correct 28 ms 31616 KB Output is correct
10 Correct 31 ms 31616 KB Output is correct
11 Correct 28 ms 31752 KB Output is correct
12 Correct 33 ms 31616 KB Output is correct
13 Correct 32 ms 31736 KB Output is correct
14 Correct 32 ms 31616 KB Output is correct
15 Correct 33 ms 31736 KB Output is correct
16 Correct 36 ms 31608 KB Output is correct
17 Correct 52 ms 31964 KB Output is correct
18 Correct 51 ms 32164 KB Output is correct
19 Correct 49 ms 32000 KB Output is correct
20 Correct 47 ms 31992 KB Output is correct
21 Correct 45 ms 32120 KB Output is correct
22 Correct 41 ms 31872 KB Output is correct
23 Correct 44 ms 31964 KB Output is correct
24 Execution timed out 10083 ms 52884 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 31616 KB Output is correct
2 Correct 39 ms 31580 KB Output is correct
3 Correct 32 ms 31608 KB Output is correct
4 Correct 34 ms 31608 KB Output is correct
5 Correct 31 ms 31608 KB Output is correct
6 Correct 33 ms 31608 KB Output is correct
7 Correct 33 ms 31608 KB Output is correct
8 Correct 32 ms 31616 KB Output is correct
9 Correct 28 ms 31616 KB Output is correct
10 Correct 31 ms 31616 KB Output is correct
11 Correct 28 ms 31752 KB Output is correct
12 Correct 33 ms 31616 KB Output is correct
13 Correct 32 ms 31736 KB Output is correct
14 Correct 32 ms 31616 KB Output is correct
15 Correct 33 ms 31736 KB Output is correct
16 Correct 36 ms 31608 KB Output is correct
17 Correct 52 ms 31964 KB Output is correct
18 Correct 51 ms 32164 KB Output is correct
19 Correct 49 ms 32000 KB Output is correct
20 Correct 47 ms 31992 KB Output is correct
21 Correct 45 ms 32120 KB Output is correct
22 Correct 41 ms 31872 KB Output is correct
23 Correct 44 ms 31964 KB Output is correct
24 Execution timed out 10083 ms 52884 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 31616 KB Output is correct
2 Correct 39 ms 31580 KB Output is correct
3 Correct 32 ms 31608 KB Output is correct
4 Correct 34 ms 31608 KB Output is correct
5 Correct 31 ms 31608 KB Output is correct
6 Correct 33 ms 31608 KB Output is correct
7 Correct 33 ms 31608 KB Output is correct
8 Correct 32 ms 31616 KB Output is correct
9 Correct 28 ms 31616 KB Output is correct
10 Correct 31 ms 31616 KB Output is correct
11 Correct 28 ms 31752 KB Output is correct
12 Correct 33 ms 31616 KB Output is correct
13 Correct 32 ms 31736 KB Output is correct
14 Correct 32 ms 31616 KB Output is correct
15 Correct 33 ms 31736 KB Output is correct
16 Correct 36 ms 31608 KB Output is correct
17 Correct 52 ms 31964 KB Output is correct
18 Correct 51 ms 32164 KB Output is correct
19 Correct 49 ms 32000 KB Output is correct
20 Correct 47 ms 31992 KB Output is correct
21 Correct 45 ms 32120 KB Output is correct
22 Correct 41 ms 31872 KB Output is correct
23 Correct 44 ms 31964 KB Output is correct
24 Execution timed out 10083 ms 52884 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10079 ms 45496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10079 ms 45496 KB Time limit exceeded
2 Halted 0 ms 0 KB -