Submission #1057719

# Submission time Handle Problem Language Result Execution time Memory
1057719 2024-08-14T04:05:38 Z vjudge1 Bigger segments (IZhO19_segments) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 5e5+7;
ll n, dp[mxn], opt[mxn], a[mxn];
struct dynamic_segment_tree
{
    struct node {ll v, l, r; node() {v = 0; l = -1, r = -1;}};
    vector<node> st;
    dynamic_segment_tree() {st.clear(); st.pb(node());};
    void update(ll id, ll l, ll r, ll i, ll x)
    {
        if (l == r) {st[id].v = max(st[id].v,x); return;}
        ll m = (r+l)>>1; st[id].v = max(st[id].v,x);
        if (l <= i && i <= m)
        {
            if (st[id].l == -1) {st[id].l = st.size(); st.pb(node());}
            update(st[id].l,l,m,i,x);
        }
        if (m < i && i <= r)
        {
            if (st[id].r == -1) {st[id].r = st.size(); st.pb(node());}
            update(st[id].r,m+1,r,i,x);
        }
    }
    ll get(ll id, ll l, ll r, ll u, ll v)
    {
        if (r < u || v < l) return 0;
        if (u <= l && r <= v) return st[id].v;
        ll m = (r+l)>>1, val = 0;
        if (st[id].l != -1) val = max(val,get(st[id].l,l,m,u,v));
        if (st[id].r != -1) val = max(val,get(st[id].r,m+1,r,u,v));
        return val;
    }
    void update(ll i, ll x) {update(0,0,1e17,i,x);}
    ll get(ll u, ll v) {return get(0,0,1e17,u,v);}
} st;
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
    cin >> n;
    for (ll i = 1; i <= n; i++)
    {
        cin >> a[i];
        a[i] += a[i#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 5e5+7;
ll n, dp[mxn], opt[mxn], a[mxn];
struct dynamic_segment_tree
{
    struct node {ll v, l, r; node() {v = 0; l = -1, r = -1;}};
    vector<node> st;
    dynamic_segment_tree() {st.clear(); st.pb(node());};
    void update(ll id, ll l, ll r, ll i, ll x)
    {
        if (l == r) {st[id].v = max(st[id].v,x); return;}
        ll m = (r+l)>>1; st[id].v = max(st[id].v,x);
        if (l <= i && i <= m)
        {
            if (st[id].l == -1) {st[id].l = st.size(); st.pb(node());}
            update(st[id].l,l,m,i,x);
        }
        if (m < i && i <= r)
        {
            if (st[id].r == -1) {st[id].r = st.size(); st.pb(node());}
            update(st[id].r,m+1,r,i,x);
        }
    }
    ll get(ll id, ll l, ll r, ll u, ll v)
    {
        if (r < u || v < l) return 0;
        if (u <= l && r <= v) return st[id].v;
        ll m = (r+l)>>1, val = 0;
        if (st[id].l != -1) val = max(val,get(st[id].l,l,m,u,v));
        if (st[id].r != -1) val = max(val,get(st[id].r,m+1,r,u,v));
        return val;
    }
    void update(ll i, ll x) {update(0,0,1e17,i,x);}
    ll get(ll u, ll v) {return get(0,0,1e17,u,v);}
} st;
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
    cin >> n;
    for (ll i = 1; i <= n; i++)
    {
        cin >> a[i];
        a[i] += a[i-1];
    }
    for (ll i = 1; i <= n; i++)
    {
        ll opt_pos = st.get(0,a[i]);
        dp[i] = dp[opt_pos]+1;
        opt[i] = a[i]-a[opt_pos];
        st.update(opt[i]+a[i],i);
    }   
    cout << dp[n];
}-1];
    }
    for (ll i = 1; i <= n; i++)
    {
        ll opt_pos = st.get(0,a[i]);
        dp[i] = dp[opt_pos]+1;
        opt[i] = a[i]-a[opt_pos];
        st.update(opt[i]+a[i],i);
    }   
    cout << dp[n];
}

Compilation message

segments.cpp:51:20: error: stray '#' in program
   51 |         a[i] += a[i#include <bits/stdc++.h>
      |                    ^
segments.cpp: In function 'int main()':
segments.cpp:51:20: error: expected ']' before 'include'
   51 |         a[i] += a[i#include <bits/stdc++.h>
      |                    ^~~~~~~~
      |                    ]
segments.cpp:51:20: error: expected ';' before 'include'
   51 |         a[i] += a[i#include <bits/stdc++.h>
      |                    ^~~~~~~~
      |                    ;
segments.cpp:94:1: error: a function-definition is not allowed here before '{' token
   94 | {
      | ^
segments.cpp:111:4: error: expected ';' before ']' token
  111 | }-1];
      |    ^
      |    ;
segments.cpp:111:2: warning: statement has no effect [-Wunused-value]
  111 | }-1];
      |  ^~
segments.cpp:59:10: warning: unused variable 'mod' [-Wunused-variable]
   59 | const ll mod = 1e9+7, mxn = 5e5+7;
      |          ^~~
segments.cpp:60:4: warning: unused variable 'n' [-Wunused-variable]
   60 | ll n, dp[mxn], opt[mxn], a[mxn];
      |    ^
segments.cpp:60:7: warning: unused variable 'dp' [-Wunused-variable]
   60 | ll n, dp[mxn], opt[mxn], a[mxn];
      |       ^~
segments.cpp:60:16: warning: unused variable 'opt' [-Wunused-variable]
   60 | ll n, dp[mxn], opt[mxn], a[mxn];
      |                ^~~
segments.cpp:60:26: warning: unused variable 'a' [-Wunused-variable]
   60 | ll n, dp[mxn], opt[mxn], a[mxn];
      |                          ^
segments.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
segments.cpp:46:43: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
      |                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:46:75: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
      |                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~