Submission #875204

#TimeUsernameProblemLanguageResultExecution timeMemory
875204NintsiChkhaidzeSplit the sequence (APIO14_sequence)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define s second #define f first #define left L[id][h],l,(l + r)/2 #define right R[id][h],(l + r)/2 + 1,r #define pii pair <int,int> #define int ll using namespace std; const int N = 1e5 + 3,inf = 2e9; int a[N],p[N],dp[N][203],lst[N][203]; pii t[203][4*N]; int vis[203][4*N],cnt[203],L[203][4*N],R[203][4*N]; bool mp[203][4*N]; int f(pii line,int x){ return x * line.f + line.s; } void upd(int id,int h,int l,int r,pii line,int idx){ if (!mp[id][h]) mp[id][h] = ++cnt[id]; if (!vis[id][h]){ vis[id][h] = idx; t[id][h] = line; return; } int mid = (l + r)/2; if (f(t[id][h],mid) < f(line,mid)) swap(t[id][h],line),vis[id][h] = idx; if (l == r) return; if (!L[id][h]) L[id][h] = ++cnt[id]; if (!R[id][h]) R[id][h] = ++cnt[id]; if (f(t[id][h],l) > f(line,l)){ upd(id,right,line,idx); }else{ upd(id,left,line,idx); } } pii get(int id,int h,int l,int r,int x){ pii cur = {0,0}; if (vis[id][h]) cur.f = f(t[id][h],x - 1),cur.s = vis[id][h]; if (l == r) return cur; pii res = {0,0}; if (x > (l + r)/2) { if (R[id][h]) res = get(id,right,x); }else{ if (L[id][h]) res = get(id,left,x); } if (res.f > cur.f) return res; return cur; } signed main() { ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n,k; cin>>n>>k; for (int i = 1; i <= n; i++){ cin >> a[i]; p[i] = p[i - 1] + a[i]; } for (int r = 0; r <= n + 1; r++) for (int kk = 1; kk <= k; kk++) dp[r][kk] = -1; for (int i = 2; i <= n; i++){ for (int j = 1; j <= min(k,i - 1); j++){ if (j == 1){ int s1 = p[n] - p[i - 1],s2 = p[i - 1]; int cur = s1*s2; if (cur > dp[i][j]){ dp[i][j] = cur; lst[i][j] = i; } continue; } int s1 = p[n] - p[i - 1]; pii res = get(j - 1,1,1,2e9,s1+1); dp[i][j] = res.f + s1*p[i - 1]; lst[i][j] = res.s; } for (int j = 1; j <= min(k,i - 1); j++){ if (dp[i][j] == -1) continue; upd(j,1,1,2e9,{-p[i - 1],dp[i][j]},i); } } int id=n; for (int i = 1; i <= n; i++){ if (dp[i][k] > dp[id][k]) id = i; } cout<<dp[id][k]<<endl; vector <int> ans; for (int i = k; i >= 1; i--){ ans.pb(id); id = lst[id][i]; } for (int i = k - 1; i >= 0; i--) cout<<ans[i] - 1<<" "; }

Compilation message (stderr)

/tmp/ccVhs1mv.o: in function `main':
sequence.cpp:(.text.startup+0xd): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccVhs1mv.o
sequence.cpp:(.text.startup+0x1c): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
sequence.cpp:(.text.startup+0x24): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccVhs1mv.o
sequence.cpp:(.text.startup+0x4f): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
sequence.cpp:(.text.startup+0x56): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
sequence.cpp:(.text.startup+0x61): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
sequence.cpp:(.text.startup+0xc7): relocation truncated to fit: R_X86_64_PC32 against symbol `dp' defined in .bss section in /tmp/ccVhs1mv.o
sequence.cpp:(.text.startup+0x120): relocation truncated to fit: R_X86_64_PC32 against symbol `lst' defined in .bss section in /tmp/ccVhs1mv.o
sequence.cpp:(.text.startup+0x127): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccVhs1mv.o
sequence.cpp:(.text.startup+0x138): relocation truncated to fit: R_X86_64_PC32 against symbol `dp' defined in .bss section in /tmp/ccVhs1mv.o
sequence.cpp:(.text.startup+0x15b): additional relocation overflows omitted from the output
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status