# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1116271 |
2024-11-21T12:04:16 Z |
SalihSahin |
Cigle (COI21_cigle) |
C++14 |
|
1000 ms |
376364 KB |
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
const int inf = 1e16;
const int N = 5e3 + 5;
vector<int> a(N);
vector<pair<int, int> > prec[N];
int add(int l, int r, int x){
if(!prec[r].size() || (prec[r][0].first <= l || prec[r][0].second >= x)) return 0;
int lb = 0, rb = prec[r].size()-1;
while(lb < rb){
int mid = (lb + rb + 1)/2;
if(prec[r][mid].first > l && prec[r][mid].second < x) lb = mid;
else rb = mid - 1;
}
return lb + 1;
}
struct SEGT{
vector<int> tree, lazy;
void init(int n){
tree.assign(4*n, 0);
lazy.assign(4*n, 0);
}
void push(int ind){
if(lazy[ind] == 0) return;
lazy[ind*2] += lazy[ind];
tree[ind*2] += lazy[ind];
lazy[ind*2+1] += lazy[ind];
tree[ind*2+1] += lazy[ind];
lazy[ind] = 0;
}
void update(int ind, int l, int r, int ql, int qr, int val){
if(l > r || r < ql || l > qr || ql > qr) return;
if(l >= ql && r <= qr){
tree[ind] += val;
lazy[ind] += val;
}
else{
push(ind);
int m = (l + r)/2;
update(ind*2, l, m, ql, qr, val);
update(ind*2+1, m+1, r, ql, qr, val);
tree[ind] = max(tree[ind*2], tree[ind*2+1]);
}
}
int query(int ind, int l, int r, int ql, int qr){
if(l > r || r < ql || l > qr || ql > qr) return 0;
if(l >= ql && r <= qr){
return tree[ind];
}
else{
push(ind);
int m = (l + r)/2;
return max(query(ind*2, l, m, ql, qr), query(ind*2+1, m+1, r, ql, qr));
}
}
};
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// dp[son kat l][son kat r] -> dp[r + 1][x] + match({l, r} , {r+1, x});
int n;
cin>>n;
for(int i = 1; i <= n; i++){
cin>>a[i];
}
vector<pair<int, int> > upd[n+5];
for(int i = 2; i <= n-1; i++){
vector<pair<int, int> > v1, v2;
int val = 0;
for(int j = i; j > 1; j--){
val += a[j];
v1.pb({val, j});
}
val = 0;
for(int j = i+1; j <= n-1; j++){
val += a[j];
v2.pb({val, j});
}
int ind2 = 0;
for(int j = 0; j < v1.size(); j++){
while(ind2 < v2.size() && v2[ind2].first < v1[j].first) ind2++;
if(ind2 < v2.size() && v2[ind2].first == v1[j].first){
prec[i].pb({v1[j].second, v2[ind2].second});
upd[i].pb({v2[ind2].second, v1[j].second});
}
}
}
vector<vector<int> > dp(n+5, vector<int>(n+5));
for(int r = 1; r <= n-1; r++){
sort(upd[r].begin(), upd[r].end());
int updind = 0;
SEGT seg;
seg.init(r);
for(int l = 1; l <= r; l++){
seg.update(1, 1, r, l, l, dp[l][r]);
}
for(int x = r+1; x <= n; x++){
while(updind < upd[r].size() && upd[r][updind].first < x){
seg.update(1, 1, r, 1, upd[r][updind].second-1, 1);
updind++;
}
dp[r+1][x] = seg.tree[1];
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
ans = max(ans, dp[i][n]);
}
cout<<ans<<endl;
return 0;
}
Compilation message
cigle.cpp: In function 'int32_t main()':
cigle.cpp:103:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for(int j = 0; j < v1.size(); j++){
| ~~^~~~~~~~~~~
cigle.cpp:104:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | while(ind2 < v2.size() && v2[ind2].first < v1[j].first) ind2++;
| ~~~~~^~~~~~~~~~~
cigle.cpp:105:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | if(ind2 < v2.size() && v2[ind2].first == v1[j].first){
| ~~~~~^~~~~~~~~~~
cigle.cpp:125:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
125 | while(updind < upd[r].size() && upd[r][updind].first < x){
| ~~~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
816 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
760 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
816 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
760 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
1 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
592 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
592 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
1 ms |
592 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
4188 KB |
Output is correct |
2 |
Correct |
16 ms |
4944 KB |
Output is correct |
3 |
Correct |
16 ms |
4432 KB |
Output is correct |
4 |
Correct |
17 ms |
4852 KB |
Output is correct |
5 |
Correct |
17 ms |
4856 KB |
Output is correct |
6 |
Correct |
17 ms |
4688 KB |
Output is correct |
7 |
Correct |
15 ms |
4688 KB |
Output is correct |
8 |
Correct |
15 ms |
4688 KB |
Output is correct |
9 |
Correct |
18 ms |
4860 KB |
Output is correct |
10 |
Correct |
17 ms |
4432 KB |
Output is correct |
11 |
Correct |
15 ms |
4604 KB |
Output is correct |
12 |
Correct |
15 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
816 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
760 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
1 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
592 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
592 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
1 ms |
592 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
592 KB |
Output is correct |
21 |
Correct |
17 ms |
4188 KB |
Output is correct |
22 |
Correct |
16 ms |
4944 KB |
Output is correct |
23 |
Correct |
16 ms |
4432 KB |
Output is correct |
24 |
Correct |
17 ms |
4852 KB |
Output is correct |
25 |
Correct |
17 ms |
4856 KB |
Output is correct |
26 |
Correct |
17 ms |
4688 KB |
Output is correct |
27 |
Correct |
15 ms |
4688 KB |
Output is correct |
28 |
Correct |
15 ms |
4688 KB |
Output is correct |
29 |
Correct |
18 ms |
4860 KB |
Output is correct |
30 |
Correct |
17 ms |
4432 KB |
Output is correct |
31 |
Correct |
15 ms |
4604 KB |
Output is correct |
32 |
Correct |
15 ms |
4432 KB |
Output is correct |
33 |
Correct |
14 ms |
4176 KB |
Output is correct |
34 |
Correct |
16 ms |
4432 KB |
Output is correct |
35 |
Correct |
16 ms |
4688 KB |
Output is correct |
36 |
Correct |
19 ms |
4764 KB |
Output is correct |
37 |
Correct |
16 ms |
4688 KB |
Output is correct |
38 |
Correct |
17 ms |
4572 KB |
Output is correct |
39 |
Correct |
14 ms |
3152 KB |
Output is correct |
40 |
Correct |
12 ms |
2640 KB |
Output is correct |
41 |
Correct |
13 ms |
2640 KB |
Output is correct |
42 |
Correct |
16 ms |
2640 KB |
Output is correct |
43 |
Correct |
11 ms |
2932 KB |
Output is correct |
44 |
Correct |
11 ms |
2640 KB |
Output is correct |
45 |
Correct |
12 ms |
2640 KB |
Output is correct |
46 |
Correct |
11 ms |
2640 KB |
Output is correct |
47 |
Correct |
11 ms |
2808 KB |
Output is correct |
48 |
Correct |
11 ms |
2640 KB |
Output is correct |
49 |
Correct |
11 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
816 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
760 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
1 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
592 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
592 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
1 ms |
592 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
592 KB |
Output is correct |
21 |
Correct |
17 ms |
4188 KB |
Output is correct |
22 |
Correct |
16 ms |
4944 KB |
Output is correct |
23 |
Correct |
16 ms |
4432 KB |
Output is correct |
24 |
Correct |
17 ms |
4852 KB |
Output is correct |
25 |
Correct |
17 ms |
4856 KB |
Output is correct |
26 |
Correct |
17 ms |
4688 KB |
Output is correct |
27 |
Correct |
15 ms |
4688 KB |
Output is correct |
28 |
Correct |
15 ms |
4688 KB |
Output is correct |
29 |
Correct |
18 ms |
4860 KB |
Output is correct |
30 |
Correct |
17 ms |
4432 KB |
Output is correct |
31 |
Correct |
15 ms |
4604 KB |
Output is correct |
32 |
Correct |
15 ms |
4432 KB |
Output is correct |
33 |
Correct |
14 ms |
4176 KB |
Output is correct |
34 |
Correct |
16 ms |
4432 KB |
Output is correct |
35 |
Correct |
16 ms |
4688 KB |
Output is correct |
36 |
Correct |
19 ms |
4764 KB |
Output is correct |
37 |
Correct |
16 ms |
4688 KB |
Output is correct |
38 |
Correct |
17 ms |
4572 KB |
Output is correct |
39 |
Correct |
14 ms |
3152 KB |
Output is correct |
40 |
Correct |
12 ms |
2640 KB |
Output is correct |
41 |
Correct |
13 ms |
2640 KB |
Output is correct |
42 |
Correct |
16 ms |
2640 KB |
Output is correct |
43 |
Correct |
11 ms |
2932 KB |
Output is correct |
44 |
Correct |
11 ms |
2640 KB |
Output is correct |
45 |
Correct |
12 ms |
2640 KB |
Output is correct |
46 |
Correct |
11 ms |
2640 KB |
Output is correct |
47 |
Correct |
11 ms |
2808 KB |
Output is correct |
48 |
Correct |
11 ms |
2640 KB |
Output is correct |
49 |
Correct |
11 ms |
2640 KB |
Output is correct |
50 |
Execution timed out |
1064 ms |
376364 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |