Submission #1294995

#TimeUsernameProblemLanguageResultExecution timeMemory
1294995azamuraiBigger segments (IZhO19_segments)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

#define ll long long
#define mp make_pair
#define fi first 
#define se second 
#define Sz(x) (int)x.size()

using namespace std;

const int N = 5e5 + 5;
const int LOG1 = 47;
const int LOG2 = 17;
const ll MXA = 1e14;
const int M = 1e8 + 5e7;

struct tree {
	int l, r, mx, pos;
};

int n, sz = 0, dp[N];
ll last[N], pref[N], a[N];
tree t[M];

void newnode() {
    sz++;
    t[sz].l = t[sz].r = 0;
    t[sz].mx = t[sz].pos = 0;
}

void upd(ll pos, int val, int val2, int v = 1, ll tl = 1, ll tr = MXA) {
	if (tl == tr) {
		if (val > t[v].mx) {
			t[v].mx = val;
			t[v].pos = val2;
		}
		else if (val == t[v].mx) {
		    if (val2 > t[v].pos) {
		        t[v].mx = val;
			    t[v].pos = val2;
		    }
		}
		return;
	}
	ll mid = (tl + tr) / 2;
	if (pos <= mid) {
		if (t[v].l == 0) {
		    newnode();
		    t[v].l = sz;
		}
		upd(pos, val, val2, t[v].l, tl, mid);
	}
 	else {
		if (t[v].r == 0) {
		    newnode();
		    t[v].r = sz;
		}
		upd(pos, val, val2, t[v].r, mid + 1, tr);
	}
	if (t[t[v].l].mx > t[t[v].r].mx) {
		t[v].mx = t[t[v].l].mx;
		t[v].pos = t[t[v].l].pos;
	}
	else {
	    if (t[t[v].l].pos > t[t[v].r].pos) {
	        t[v].mx = t[t[v].l].mx;
		    t[v].pos = t[t[v].l].pos;
	    }
	    else {
    		t[v].mx = t[t[v].r].mx;
    		t[v].pos = t[t[v].r].pos;
	    }
	}
}

pair <int,int> merge(pair<int,int> p1, pair<int,int> p2) {
	if (p1.fi > p2.fi) return p1;
	else {
	    if (p1.se > p2.se) return p1;
	    return p2;
	}
}

pair <int,int> get(ll l, ll r, int v = 1, ll tl = 1, ll tr = MXA) {
	if (tl > r || l > tr || v == 0) return mp(0, 0);
	if (tl >= l && tr <= r) return mp(t[v].mx, t[v].pos);
	ll mid = (tl + tr) / 2;
	return merge(get(l, r, t[v].l, tl, mid), get(l, r, t[v].r, mid + 1, tr));
}

void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		pref[i] = pref[i - 1] + a[i];
	}
	newnode();
	dp[1] = 1;
	last[1] = a[1];
	upd(a[1] + a[1], 1, 1);
	for (int i = 2; i <= n; i++) {
		pair <int,int> p = get(1, pref[i]);
		if (p.se == 0) {
			dp[i] = 1;
			last[i] = pref[i];
		}
		else {
			dp[i] = p.fi + 1;
			last[i] = (pref[i] - pref[p.se]);
		}
		upd(pref[i] + last[i], dp[i], i);
	}
	cout << dp[n];
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
		cout << '\n';
	}
}

Compilation message (stderr)

/usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(ios_init.o): in function `std::ios_base::Init::Init()':
(.text._ZNSt8ios_base4InitC2Ev+0x1f): failed to convert GOTPCREL relocation against '_ZNSt8ios_base4Init11_S_refcountE'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x5f): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0x66): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0x71): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0x7c): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0xa0): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0xab): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0xc8): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0xe1): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0xf4): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cin_sync' defined in .bss._ZN14__gnu_internal12buf_cin_syncE section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0xfb): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0x101): additional relocation overflows omitted from the output
(.text._ZNSt8ios_base4InitC2Ev+0x1ed): failed to convert GOTPCREL relocation against '_ZSt4cout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x252): failed to convert GOTPCREL relocation against '_ZSt3cin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x2bc): failed to convert GOTPCREL relocation against '_ZSt4cerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x316): failed to convert GOTPCREL relocation against '_ZSt4clog'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x50f): failed to convert GOTPCREL relocation against '_ZSt5wcout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x57d): failed to convert GOTPCREL relocation against '_ZSt4wcin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x5f0): failed to convert GOTPCREL relocation against '_ZSt5wcerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x654): failed to convert GOTPCREL relocation against '_ZSt5wclog'; relink with --no-relax
/usr/bin/ld: final link failed
collect2: error: ld returned 1 exit status