답안 #998494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998494 2024-06-14T04:29:57 Z underwaterkillerwhale Bigger segments (IZhO19_segments) C++17
13 / 100
2 ms 11876 KB
#include <bits/stdc++.h>
#define se              second
#define fs              first
#define mp              make_pair
#define pb              push_back
#define ll              long long
#define ii              pair<ll,ll>
#define ld              long double
#define SZ(v)           (int)v.size()
#define ALL(v)          v.begin(), v.end()
#define bit(msk, i)     ((msk >> i) & 1)
#define iter(id, v)     for(auto id : v)
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }

const int N  = 5e5 + 7;
const int Mod = 998244353;
const int szBL = 916;
const ll INF = 1e17;
const int BASE = 137;

int n;
ll a[N];
ll pre[N];
pair<ll,ll> dp[N];

struct fenwick_tree {
    int Range;
    ll fen[N];
    void init (int n) {
        Range = n;
        rep (i, 1, n) fen[i] = -1;
    }
    void update (int pos, ll val) {
        for (; pos <= Range; pos += pos & -pos) fen[pos] = max(fen[pos], val);
    }
    ll get (int pos) {
        ll res = -1;
        for (; pos > 0; pos -= pos & -pos) res = max(res, fen[pos]);
        return res;
    }
}BIT;

void solution () {
    cin >> n;
    rep (i, 1, n) cin >> a[i];
    rep (i, 1, n) pre[i] = pre[i - 1] + a[i];
    memset(dp, 0x3f, sizeof dp);
    dp[0] = {0, 0};
    int res = 0;
    rep (i, 1, n) {
        int lf = 0, rt = i - 1;
        while (lf < rt) {
            int mid = lf + rt + 1 >> 1;
            if (dp[mid].fs <= pre[i] - pre[mid]) lf = mid;
            else rt = mid - 1;
        }
        dp[i] = {pre[i] - pre[lf], dp[lf].se + 1};
    }
    cout << dp[n].se<<"\n";
}
#define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);
int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    file ("c");
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
}
/*
5 10
1 2
3 1
4 2
5 3
1 4
2 3
3 5
4 5
3 4
1 4

*/

Compilation message

segments.cpp: In function 'void solution()':
segments.cpp:53:31: warning: 'void* memset(void*, int, size_t)' writing to an object of type 'struct std::pair<long long int, long long int>' with no trivial copy-assignment [-Wclass-memaccess]
   53 |     memset(dp, 0x3f, sizeof dp);
      |                               ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from segments.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<long long int, long long int>' declared here
  211 |     struct pair
      |            ^~~~
segments.cpp:59:31: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |             int mid = lf + rt + 1 >> 1;
      |                       ~~~~~~~~^~~
segments.cpp:55:9: warning: unused variable 'res' [-Wunused-variable]
   55 |     int res = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11868 KB Output is correct
2 Correct 2 ms 11868 KB Output is correct
3 Correct 2 ms 11868 KB Output is correct
4 Correct 2 ms 11868 KB Output is correct
5 Correct 2 ms 11840 KB Output is correct
6 Correct 2 ms 11864 KB Output is correct
7 Correct 2 ms 11876 KB Output is correct
8 Correct 2 ms 11864 KB Output is correct
9 Correct 2 ms 11864 KB Output is correct
10 Correct 2 ms 11864 KB Output is correct
11 Correct 2 ms 11868 KB Output is correct
12 Correct 2 ms 11868 KB Output is correct
13 Correct 2 ms 11864 KB Output is correct
14 Correct 2 ms 11864 KB Output is correct
15 Correct 2 ms 11864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11868 KB Output is correct
2 Correct 2 ms 11868 KB Output is correct
3 Correct 2 ms 11868 KB Output is correct
4 Correct 2 ms 11868 KB Output is correct
5 Correct 2 ms 11840 KB Output is correct
6 Correct 2 ms 11864 KB Output is correct
7 Correct 2 ms 11876 KB Output is correct
8 Correct 2 ms 11864 KB Output is correct
9 Correct 2 ms 11864 KB Output is correct
10 Correct 2 ms 11864 KB Output is correct
11 Correct 2 ms 11868 KB Output is correct
12 Correct 2 ms 11868 KB Output is correct
13 Correct 2 ms 11864 KB Output is correct
14 Correct 2 ms 11864 KB Output is correct
15 Correct 2 ms 11864 KB Output is correct
16 Correct 2 ms 11868 KB Output is correct
17 Incorrect 2 ms 11868 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11868 KB Output is correct
2 Correct 2 ms 11868 KB Output is correct
3 Correct 2 ms 11868 KB Output is correct
4 Correct 2 ms 11868 KB Output is correct
5 Correct 2 ms 11840 KB Output is correct
6 Correct 2 ms 11864 KB Output is correct
7 Correct 2 ms 11876 KB Output is correct
8 Correct 2 ms 11864 KB Output is correct
9 Correct 2 ms 11864 KB Output is correct
10 Correct 2 ms 11864 KB Output is correct
11 Correct 2 ms 11868 KB Output is correct
12 Correct 2 ms 11868 KB Output is correct
13 Correct 2 ms 11864 KB Output is correct
14 Correct 2 ms 11864 KB Output is correct
15 Correct 2 ms 11864 KB Output is correct
16 Correct 2 ms 11868 KB Output is correct
17 Incorrect 2 ms 11868 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11868 KB Output is correct
2 Correct 2 ms 11868 KB Output is correct
3 Correct 2 ms 11868 KB Output is correct
4 Correct 2 ms 11868 KB Output is correct
5 Correct 2 ms 11840 KB Output is correct
6 Correct 2 ms 11864 KB Output is correct
7 Correct 2 ms 11876 KB Output is correct
8 Correct 2 ms 11864 KB Output is correct
9 Correct 2 ms 11864 KB Output is correct
10 Correct 2 ms 11864 KB Output is correct
11 Correct 2 ms 11868 KB Output is correct
12 Correct 2 ms 11868 KB Output is correct
13 Correct 2 ms 11864 KB Output is correct
14 Correct 2 ms 11864 KB Output is correct
15 Correct 2 ms 11864 KB Output is correct
16 Correct 2 ms 11868 KB Output is correct
17 Incorrect 2 ms 11868 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11868 KB Output is correct
2 Correct 2 ms 11868 KB Output is correct
3 Correct 2 ms 11868 KB Output is correct
4 Correct 2 ms 11868 KB Output is correct
5 Correct 2 ms 11840 KB Output is correct
6 Correct 2 ms 11864 KB Output is correct
7 Correct 2 ms 11876 KB Output is correct
8 Correct 2 ms 11864 KB Output is correct
9 Correct 2 ms 11864 KB Output is correct
10 Correct 2 ms 11864 KB Output is correct
11 Correct 2 ms 11868 KB Output is correct
12 Correct 2 ms 11868 KB Output is correct
13 Correct 2 ms 11864 KB Output is correct
14 Correct 2 ms 11864 KB Output is correct
15 Correct 2 ms 11864 KB Output is correct
16 Correct 2 ms 11868 KB Output is correct
17 Incorrect 2 ms 11868 KB Output isn't correct
18 Halted 0 ms 0 KB -