Submission #236421

# Submission time Handle Problem Language Result Execution time Memory
236421 2020-06-02T07:47:46 Z _7_7_ Bigger segments (IZhO19_segments) C++14
100 / 100
161 ms 20984 KB
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 5e5 + 11;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, a[N], dp[N];
pii t[N];

void inc (int pos, pii x) {
	while (pos < N) {
		t[pos] = max(t[pos], x);
		pos |= pos + 1;
	}	
}

pii get (int r) {
	pii res = {0, 0};
	while (r >= 0) {
		res = max(res, t[r]);    
		r = (r & (r + 1)) - 1;
	}

	return res;
}

                                                  
main () {
	scanf("%lld", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
		a[i] += a[i - 1];	
	}

	for (int i = 1; i <= n; ++i) {
		pii cur = get(i);
		dp[i] = cur.f + 1;

		int j = lower_bound(a + 1, a + 1 + n, a[i]*2 - a[cur.s]) - a;
		inc(j, {dp[i], i});
	}

	cout << dp[n] << endl;
}

Compilation message

segments.cpp:62:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
segments.cpp: In function 'int main()':
segments.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
segments.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &a[i]);
   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
37 Correct 5 ms 512 KB Output is correct
38 Correct 5 ms 512 KB Output is correct
39 Correct 5 ms 512 KB Output is correct
40 Correct 5 ms 512 KB Output is correct
41 Correct 5 ms 512 KB Output is correct
42 Correct 5 ms 512 KB Output is correct
43 Correct 6 ms 512 KB Output is correct
44 Correct 5 ms 512 KB Output is correct
45 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
37 Correct 5 ms 512 KB Output is correct
38 Correct 5 ms 512 KB Output is correct
39 Correct 5 ms 512 KB Output is correct
40 Correct 5 ms 512 KB Output is correct
41 Correct 5 ms 512 KB Output is correct
42 Correct 5 ms 512 KB Output is correct
43 Correct 6 ms 512 KB Output is correct
44 Correct 5 ms 512 KB Output is correct
45 Correct 5 ms 512 KB Output is correct
46 Correct 21 ms 2304 KB Output is correct
47 Correct 28 ms 3712 KB Output is correct
48 Correct 34 ms 4344 KB Output is correct
49 Correct 32 ms 4216 KB Output is correct
50 Correct 30 ms 4480 KB Output is correct
51 Correct 36 ms 4472 KB Output is correct
52 Correct 20 ms 2432 KB Output is correct
53 Correct 14 ms 1664 KB Output is correct
54 Correct 28 ms 3676 KB Output is correct
55 Correct 32 ms 4472 KB Output is correct
56 Correct 28 ms 3968 KB Output is correct
57 Correct 25 ms 3328 KB Output is correct
58 Correct 28 ms 3712 KB Output is correct
59 Correct 30 ms 4092 KB Output is correct
60 Correct 30 ms 4096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
37 Correct 5 ms 512 KB Output is correct
38 Correct 5 ms 512 KB Output is correct
39 Correct 5 ms 512 KB Output is correct
40 Correct 5 ms 512 KB Output is correct
41 Correct 5 ms 512 KB Output is correct
42 Correct 5 ms 512 KB Output is correct
43 Correct 6 ms 512 KB Output is correct
44 Correct 5 ms 512 KB Output is correct
45 Correct 5 ms 512 KB Output is correct
46 Correct 21 ms 2304 KB Output is correct
47 Correct 28 ms 3712 KB Output is correct
48 Correct 34 ms 4344 KB Output is correct
49 Correct 32 ms 4216 KB Output is correct
50 Correct 30 ms 4480 KB Output is correct
51 Correct 36 ms 4472 KB Output is correct
52 Correct 20 ms 2432 KB Output is correct
53 Correct 14 ms 1664 KB Output is correct
54 Correct 28 ms 3676 KB Output is correct
55 Correct 32 ms 4472 KB Output is correct
56 Correct 28 ms 3968 KB Output is correct
57 Correct 25 ms 3328 KB Output is correct
58 Correct 28 ms 3712 KB Output is correct
59 Correct 30 ms 4092 KB Output is correct
60 Correct 30 ms 4096 KB Output is correct
61 Correct 84 ms 10104 KB Output is correct
62 Correct 99 ms 14072 KB Output is correct
63 Correct 120 ms 16252 KB Output is correct
64 Correct 161 ms 20472 KB Output is correct
65 Correct 132 ms 20856 KB Output is correct
66 Correct 160 ms 20856 KB Output is correct
67 Correct 136 ms 16760 KB Output is correct
68 Correct 70 ms 8568 KB Output is correct
69 Correct 120 ms 17016 KB Output is correct
70 Correct 144 ms 20984 KB Output is correct
71 Correct 126 ms 18040 KB Output is correct
72 Correct 112 ms 15224 KB Output is correct
73 Correct 118 ms 17784 KB Output is correct
74 Correct 127 ms 19320 KB Output is correct
75 Correct 128 ms 19320 KB Output is correct