Submission #803060

# Submission time Handle Problem Language Result Execution time Memory
803060 2023-08-02T20:47:54 Z farhan132 Bigger segments (IZhO19_segments) C++17
100 / 100
154 ms 71736 KB
/***Farhan132***/
// #pragma GCC optimize("Ofast,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef double dd;
typedef pair<ll , ll> ii;
typedef tuple < ll,  ll, ll > tp;
 
#define ff first
#define ss second
#define pb push_back
#define in insert
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clz(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcount(n)
#define clean fflush(stdout)
 
const ll mod =  (ll) 998244353;
// const ll mod =  (ll) 1e9 + 7;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = (ll)2e18;
 
// ll dx[]={0,1,0,-1};
// ll dy[]={1,0,-1,0};
// ll dxx[]={0,1,0,-1,1,1,-1,-1};
// ll dyy[]={1,0,-1,0,1,-1,1,-1};
 
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll N = 5e5 + 5;

ll f[N], pref[N], a[N], k[N], ans[N];

set < pair < ll , ll  > > s[N];

void solve(){

    pref[0] = 0;

    ll n; cin >> n;

    for(ll i = 1; i <= n; i++){
        cin >> a[i];
        pref[i] = pref[i - 1] + a[i]; 
        f[i] = INF;
    }

    ll cur = 0;
    ll last = 0;

    f[0] = 0, k[0] = 0, ans[0] = 0;
    s[0].in({0, 0});
    ll to = 0;

    for(ll i = 1; i <= n; i++){
        // p_i + f_j >= 0
        if(- (*s[cur].begin()).ff + pref[i] >= 0){
            cur++;
            to = (*s[cur-1].begin()).ss;
        }
        while(s[cur - 1].size() > 0){
            auto it = s[cur - 1].begin(); s[cur - 1].erase(it);
            to = max((*it).ss, to);
            if(s[cur-1].size() == 0 || - (*s[cur - 1].begin()).ff + pref[i] < 0){
                s[cur - 1] .in(*it);
                break;
            } 
        }
        s[cur].in({pref[i] + (pref[i] - pref[to]), i});
    }
    cout << cur << '\n';
    
   return;
}

int main() {

    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        auto start_time = clock();
    #else
         // freopen("subsequence.in", "r", stdin);
         // freopen("subsequence.out", "w", stdout); 
         ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    #endif

    //precalc();
 
    ll T = 1, CT = 0;// cin >> T; 
 
    while(T--){
        // cout << "Case #" << ++CT << ": ";
        solve();
    }
    
    #ifdef LOCAL
        auto end_time = clock();
        cerr<< "Execution time: "<<(end_time - start_time)*(int)1e3/CLOCKS_PER_SEC<<" ms\n";
    #endif
 
    return 0;
} 

Compilation message

segments.cpp: In function 'void solve()':
segments.cpp:63:8: warning: unused variable 'last' [-Wunused-variable]
   63 |     ll last = 0;
      |        ^~~~
segments.cpp: In function 'int main()':
segments.cpp:104:15: warning: unused variable 'CT' [-Wunused-variable]
  104 |     ll T = 1, CT = 0;// cin >> T;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23828 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 11 ms 23776 KB Output is correct
6 Correct 11 ms 23824 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23780 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23792 KB Output is correct
12 Correct 11 ms 23828 KB Output is correct
13 Correct 12 ms 23772 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23828 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 11 ms 23776 KB Output is correct
6 Correct 11 ms 23824 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23780 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23792 KB Output is correct
12 Correct 11 ms 23828 KB Output is correct
13 Correct 12 ms 23772 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 12 ms 23892 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 11 ms 23892 KB Output is correct
19 Correct 13 ms 23828 KB Output is correct
20 Correct 13 ms 23892 KB Output is correct
21 Correct 11 ms 23828 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 12 ms 23832 KB Output is correct
24 Correct 11 ms 23764 KB Output is correct
25 Correct 11 ms 23828 KB Output is correct
26 Correct 11 ms 23772 KB Output is correct
27 Correct 11 ms 23828 KB Output is correct
28 Correct 11 ms 23868 KB Output is correct
29 Correct 14 ms 23812 KB Output is correct
30 Correct 12 ms 23812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23828 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 11 ms 23776 KB Output is correct
6 Correct 11 ms 23824 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23780 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23792 KB Output is correct
12 Correct 11 ms 23828 KB Output is correct
13 Correct 12 ms 23772 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 12 ms 23892 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 11 ms 23892 KB Output is correct
19 Correct 13 ms 23828 KB Output is correct
20 Correct 13 ms 23892 KB Output is correct
21 Correct 11 ms 23828 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 12 ms 23832 KB Output is correct
24 Correct 11 ms 23764 KB Output is correct
25 Correct 11 ms 23828 KB Output is correct
26 Correct 11 ms 23772 KB Output is correct
27 Correct 11 ms 23828 KB Output is correct
28 Correct 11 ms 23868 KB Output is correct
29 Correct 14 ms 23812 KB Output is correct
30 Correct 12 ms 23812 KB Output is correct
31 Correct 12 ms 24120 KB Output is correct
32 Correct 12 ms 24020 KB Output is correct
33 Correct 14 ms 24020 KB Output is correct
34 Correct 12 ms 24088 KB Output is correct
35 Correct 13 ms 24096 KB Output is correct
36 Correct 12 ms 23892 KB Output is correct
37 Correct 12 ms 23844 KB Output is correct
38 Correct 12 ms 23840 KB Output is correct
39 Correct 13 ms 23828 KB Output is correct
40 Correct 14 ms 23884 KB Output is correct
41 Correct 12 ms 24020 KB Output is correct
42 Correct 13 ms 24036 KB Output is correct
43 Correct 12 ms 23984 KB Output is correct
44 Correct 11 ms 24020 KB Output is correct
45 Correct 12 ms 24020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23828 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 11 ms 23776 KB Output is correct
6 Correct 11 ms 23824 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23780 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23792 KB Output is correct
12 Correct 11 ms 23828 KB Output is correct
13 Correct 12 ms 23772 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 12 ms 23892 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 11 ms 23892 KB Output is correct
19 Correct 13 ms 23828 KB Output is correct
20 Correct 13 ms 23892 KB Output is correct
21 Correct 11 ms 23828 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 12 ms 23832 KB Output is correct
24 Correct 11 ms 23764 KB Output is correct
25 Correct 11 ms 23828 KB Output is correct
26 Correct 11 ms 23772 KB Output is correct
27 Correct 11 ms 23828 KB Output is correct
28 Correct 11 ms 23868 KB Output is correct
29 Correct 14 ms 23812 KB Output is correct
30 Correct 12 ms 23812 KB Output is correct
31 Correct 12 ms 24120 KB Output is correct
32 Correct 12 ms 24020 KB Output is correct
33 Correct 14 ms 24020 KB Output is correct
34 Correct 12 ms 24088 KB Output is correct
35 Correct 13 ms 24096 KB Output is correct
36 Correct 12 ms 23892 KB Output is correct
37 Correct 12 ms 23844 KB Output is correct
38 Correct 12 ms 23840 KB Output is correct
39 Correct 13 ms 23828 KB Output is correct
40 Correct 14 ms 23884 KB Output is correct
41 Correct 12 ms 24020 KB Output is correct
42 Correct 13 ms 24036 KB Output is correct
43 Correct 12 ms 23984 KB Output is correct
44 Correct 11 ms 24020 KB Output is correct
45 Correct 12 ms 24020 KB Output is correct
46 Correct 40 ms 32792 KB Output is correct
47 Correct 31 ms 27960 KB Output is correct
48 Correct 33 ms 33236 KB Output is correct
49 Correct 31 ms 33304 KB Output is correct
50 Correct 30 ms 33424 KB Output is correct
51 Correct 33 ms 27284 KB Output is correct
52 Correct 22 ms 25544 KB Output is correct
53 Correct 18 ms 24952 KB Output is correct
54 Correct 30 ms 26624 KB Output is correct
55 Correct 32 ms 27256 KB Output is correct
56 Correct 26 ms 32832 KB Output is correct
57 Correct 32 ms 32864 KB Output is correct
58 Correct 29 ms 31520 KB Output is correct
59 Correct 32 ms 32992 KB Output is correct
60 Correct 28 ms 29204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23828 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 11 ms 23776 KB Output is correct
6 Correct 11 ms 23824 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23780 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23792 KB Output is correct
12 Correct 11 ms 23828 KB Output is correct
13 Correct 12 ms 23772 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 12 ms 23892 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 11 ms 23892 KB Output is correct
19 Correct 13 ms 23828 KB Output is correct
20 Correct 13 ms 23892 KB Output is correct
21 Correct 11 ms 23828 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 12 ms 23832 KB Output is correct
24 Correct 11 ms 23764 KB Output is correct
25 Correct 11 ms 23828 KB Output is correct
26 Correct 11 ms 23772 KB Output is correct
27 Correct 11 ms 23828 KB Output is correct
28 Correct 11 ms 23868 KB Output is correct
29 Correct 14 ms 23812 KB Output is correct
30 Correct 12 ms 23812 KB Output is correct
31 Correct 12 ms 24120 KB Output is correct
32 Correct 12 ms 24020 KB Output is correct
33 Correct 14 ms 24020 KB Output is correct
34 Correct 12 ms 24088 KB Output is correct
35 Correct 13 ms 24096 KB Output is correct
36 Correct 12 ms 23892 KB Output is correct
37 Correct 12 ms 23844 KB Output is correct
38 Correct 12 ms 23840 KB Output is correct
39 Correct 13 ms 23828 KB Output is correct
40 Correct 14 ms 23884 KB Output is correct
41 Correct 12 ms 24020 KB Output is correct
42 Correct 13 ms 24036 KB Output is correct
43 Correct 12 ms 23984 KB Output is correct
44 Correct 11 ms 24020 KB Output is correct
45 Correct 12 ms 24020 KB Output is correct
46 Correct 40 ms 32792 KB Output is correct
47 Correct 31 ms 27960 KB Output is correct
48 Correct 33 ms 33236 KB Output is correct
49 Correct 31 ms 33304 KB Output is correct
50 Correct 30 ms 33424 KB Output is correct
51 Correct 33 ms 27284 KB Output is correct
52 Correct 22 ms 25544 KB Output is correct
53 Correct 18 ms 24952 KB Output is correct
54 Correct 30 ms 26624 KB Output is correct
55 Correct 32 ms 27256 KB Output is correct
56 Correct 26 ms 32832 KB Output is correct
57 Correct 32 ms 32864 KB Output is correct
58 Correct 29 ms 31520 KB Output is correct
59 Correct 32 ms 32992 KB Output is correct
60 Correct 28 ms 29204 KB Output is correct
61 Correct 154 ms 68744 KB Output is correct
62 Correct 133 ms 53048 KB Output is correct
63 Correct 145 ms 43724 KB Output is correct
64 Correct 105 ms 71296 KB Output is correct
65 Correct 94 ms 71736 KB Output is correct
66 Correct 120 ms 40780 KB Output is correct
67 Correct 99 ms 37484 KB Output is correct
68 Correct 56 ms 30720 KB Output is correct
69 Correct 108 ms 37140 KB Output is correct
70 Correct 114 ms 40808 KB Output is correct
71 Correct 82 ms 68804 KB Output is correct
72 Correct 111 ms 69196 KB Output is correct
73 Correct 95 ms 69708 KB Output is correct
74 Correct 91 ms 70184 KB Output is correct
75 Correct 87 ms 63460 KB Output is correct