Submission #1040397

# Submission time Handle Problem Language Result Execution time Memory
1040397 2024-08-01T03:09:48 Z Yang8on Divide and conquer (IZhO14_divide) C++14
100 / 100
33 ms 9684 KB
#include <bits/stdc++.h>
#define Y8o "Divide and conquer"
#define maxn (int) 1e5 + 5
#define ll long long
#define pii pair<ll, ll>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r

//#define f first
//#define s second

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
    if(fopen(Y8o".in", "r"))
    {
        freopen(Y8o".in", "r", stdin);
        freopen(Y8o".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}
void ctime() {
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}


int n;
struct dl { int td, g, e; } a[maxn];
ll se[maxn], sg[maxn], dp[maxn];

vector<ll> cur;
int rz(ll x) {
    return lower_bound( all(cur), x ) - cur.begin() + 1;
}

ll bit[2 * maxn];
void update(int x, ll val) {
    while(x) bit[x] = min(bit[x], val), x -= (x & -x);
}
ll get(int x, ll best = 1e18) {
    while(x < 2 * maxn) best = min(best, bit[x]), x += (x & -x);
    return best;
}

void solve()
{
    cin >> n;
    for(int i = 1; i <= n; i ++) {
        cin >> a[i].td >> a[i].g >> a[i].e;
        se[i] = se[i - 1] + a[i].e, sg[i] = sg[i - 1] + a[i].g;
    }

//    ll ans = 0;
//    for(int i = 1; i <= n; i ++) {
//        for(int j = i; j <= n; j ++) {
//            if(a[j].td - a[i].td <= se[j] - se[i - 1]) {
//                ans = max(ans, sg[j] - sg[i - 1]);
//            }
//        }
//    }

    for(int i = 1; i <= n; i ++) {
        cur.push_back(a[i].td - se[i]);
        cur.push_back(a[i].td - se[i - 1]);
    }

    sort( all(cur) );
    cur.resize( unique( all(cur) ) - cur.begin() );

    for(int i = 1; i < 2 * maxn; i ++) bit[i] = 1e18;
    for(int i = 1; i <= n; i ++) {
        update( rz(a[i].td - se[i - 1]), sg[i - 1] );
        dp[i] = sg[i] - get( rz(a[i].td - se[i]) );
    }

    cout << *max_element(dp + 1, dp + n + 1);
}


int main()
{
    iof();

    int nTest = 1;
//    cin >> nTest;

    while(nTest --) {
        solve();
    }

    ctime();
    return 0;
}

Compilation message

divide.cpp: In function 'void iof()':
divide.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(Y8o".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
divide.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(Y8o".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 2016 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 2016 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1880 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 1 ms 2140 KB Output is correct
18 Correct 1 ms 2140 KB Output is correct
19 Correct 1 ms 2140 KB Output is correct
20 Correct 1 ms 2140 KB Output is correct
21 Correct 1 ms 2140 KB Output is correct
22 Correct 1 ms 2028 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 2 ms 2404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 2016 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1880 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 1 ms 2140 KB Output is correct
18 Correct 1 ms 2140 KB Output is correct
19 Correct 1 ms 2140 KB Output is correct
20 Correct 1 ms 2140 KB Output is correct
21 Correct 1 ms 2140 KB Output is correct
22 Correct 1 ms 2028 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 2 ms 2404 KB Output is correct
25 Correct 2 ms 2404 KB Output is correct
26 Correct 4 ms 2792 KB Output is correct
27 Correct 4 ms 2820 KB Output is correct
28 Correct 16 ms 5592 KB Output is correct
29 Correct 16 ms 5852 KB Output is correct
30 Correct 33 ms 9684 KB Output is correct
31 Correct 27 ms 8660 KB Output is correct
32 Correct 29 ms 8916 KB Output is correct
33 Correct 28 ms 8656 KB Output is correct
34 Correct 29 ms 8660 KB Output is correct
35 Correct 28 ms 9092 KB Output is correct
36 Correct 30 ms 9472 KB Output is correct