답안 #959407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959407 2024-04-08T07:08:03 Z Pring Bigger segments (IZhO19_segments) C++17
100 / 100
23 ms 20936 KB
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx2","popcnt","sse4","abm")
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;

#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

// #define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MXN = 500005;
int n, a[MXN];
int dp[MXN];
ll pre[MXN];
vector<pli> dq;
int ptr;

inline char readchar(){
	const int S = 1<<16;
	static char buf[S], *p = buf, *q = buf;
	return p == q and (q = (p = buf) + fread(buf, 1, S, stdin)) == buf ? EOF : *p++;
}

inline int R(){
	int ans = 0; char c = readchar(); bool minus = false;
	while((c < '0' or c > '9') and c != '-' and c != EOF) c = readchar();
	if(c == '-') minus = true, c = readchar();
	while(c >= '0' and c <= '9') ans = ans * 10 + (c ^ '0'), c = readchar();
	return minus ? -ans : ans;
}

void DP(int id) {
    while (ptr < dq.size() && dq[ptr].fs <= pre[id]) ptr++;
    int l = dq[ptr - 1].sc;
    dp[id] = dp[l] + 1;
    pli now = mp(2 * pre[id] - pre[l], id);
    debug(now.fs, now.sc);
    while (dq.size() && dq.back().fs >= now.fs) dq.pop_back();
    dq.push_back(now);
}

void miku() {
    // cin >> n;
    n = R();
    FOR(i, 1, n + 1) a[i] = R();
    FOR(i, 1, n + 1) pre[i] = pre[i - 1] + a[i];
    dq.push_back(mp(0LL, 0));
    FOR(i, 1, n + 1) DP(i);
    cout << dp[n] << '\n';
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    miku();
    return 0;
}

Compilation message

segments.cpp: In function 'void DP(int)':
segments.cpp:48:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     while (ptr < dq.size() && dq[ptr].fs <= pre[id]) ptr++;
      |            ~~~~^~~~~~~~~~~
segments.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 39
      |                    ^~
segments.cpp:52:5: note: in expansion of macro 'debug'
   52 |     debug(now.fs, now.sc);
      |     ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2516 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2516 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2524 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2516 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2524 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2648 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2904 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2520 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 1 ms 2516 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2904 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2516 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2524 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2648 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2904 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2520 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 1 ms 2516 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2904 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 4 ms 7640 KB Output is correct
47 Correct 4 ms 7640 KB Output is correct
48 Correct 4 ms 5980 KB Output is correct
49 Correct 5 ms 6876 KB Output is correct
50 Correct 5 ms 7976 KB Output is correct
51 Correct 6 ms 7896 KB Output is correct
52 Correct 5 ms 6620 KB Output is correct
53 Correct 2 ms 5600 KB Output is correct
54 Correct 5 ms 7384 KB Output is correct
55 Correct 5 ms 7896 KB Output is correct
56 Correct 4 ms 7640 KB Output is correct
57 Correct 5 ms 7632 KB Output is correct
58 Correct 4 ms 7760 KB Output is correct
59 Correct 4 ms 7640 KB Output is correct
60 Correct 5 ms 7640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2516 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2524 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2648 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2904 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2520 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 1 ms 2516 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2904 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 4 ms 7640 KB Output is correct
47 Correct 4 ms 7640 KB Output is correct
48 Correct 4 ms 5980 KB Output is correct
49 Correct 5 ms 6876 KB Output is correct
50 Correct 5 ms 7976 KB Output is correct
51 Correct 6 ms 7896 KB Output is correct
52 Correct 5 ms 6620 KB Output is correct
53 Correct 2 ms 5600 KB Output is correct
54 Correct 5 ms 7384 KB Output is correct
55 Correct 5 ms 7896 KB Output is correct
56 Correct 4 ms 7640 KB Output is correct
57 Correct 5 ms 7632 KB Output is correct
58 Correct 4 ms 7760 KB Output is correct
59 Correct 4 ms 7640 KB Output is correct
60 Correct 5 ms 7640 KB Output is correct
61 Correct 17 ms 17864 KB Output is correct
62 Correct 15 ms 19664 KB Output is correct
63 Correct 16 ms 18712 KB Output is correct
64 Correct 16 ms 12892 KB Output is correct
65 Correct 19 ms 20076 KB Output is correct
66 Correct 23 ms 20936 KB Output is correct
67 Correct 19 ms 19628 KB Output is correct
68 Correct 10 ms 11732 KB Output is correct
69 Correct 19 ms 17704 KB Output is correct
70 Correct 21 ms 19400 KB Output is correct
71 Correct 15 ms 18828 KB Output is correct
72 Correct 18 ms 19748 KB Output is correct
73 Correct 16 ms 19148 KB Output is correct
74 Correct 17 ms 18988 KB Output is correct
75 Correct 16 ms 18632 KB Output is correct