제출 #653016

#제출 시각아이디문제언어결과실행 시간메모리
653016vladutpieleBigger segments (IZhO19_segments)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int nmax = 500000; int n; int v[nmax + 5], sume[nmax + 5]; struct elem { int maxSeg; /// in cate segmente impart prefixul [1 ... i] int maxPrv; /// capatul stanga al ultimului segment }; elem dp[nmax + 5]; void update(int a,int b) { if(dp[a].maxSeg < dp[b].maxSeg) { dp[a] = dp[b]; } else { if(dp[a].maxSeg == dp[b].maxSeg && dp[a].maxPrv < dp[b].maxPrv) { dp[a] = dp[b]; } } } signed main() { cin >> n; for(int i = 1; i <= n; i ++) { cin >> v[i]; sume[i] = sume[i - 1] + v[i]; } dp[1].maxSeg = 1; dp[1].maxPrv = 1; for(int i = 1; i <= n; i ++) { update(i, i - 1); int st = i + 1, dr = n; int pozmin = n + 1; while(st <= dr) { int mid = (st + dr) >> 1; int S = sume[mid] - sume[i]; if(S >= sume[i] - sume[dp[i].maxPrv - 1]) { pozmin = mid; dr = mid - 1; } else { st = mid + 1; } } dp[pozmin] = dp[i].maxSeg + 1; dp[pozmin] = i + 1; /* if(pozmin <= n) { dp[n + 1].maxSeg = dp[i].maxSeg + 1; dp[n + 1].maxPrv = i + 1; update(pozmin, n + 1); } */ } cout << dp[n].maxSeg << '\n'; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

segments.cpp: In function 'int main()':
segments.cpp:64:37: error: no match for 'operator=' (operand types are 'elem' and 'long long int')
   64 |         dp[pozmin] = dp[i].maxSeg + 1;
      |                                     ^
segments.cpp:12:8: note: candidate: 'constexpr elem& elem::operator=(const elem&)'
   12 | struct elem
      |        ^~~~
segments.cpp:12:8: note:   no known conversion for argument 1 from 'long long int' to 'const elem&'
segments.cpp:12:8: note: candidate: 'constexpr elem& elem::operator=(elem&&)'
segments.cpp:12:8: note:   no known conversion for argument 1 from 'long long int' to 'elem&&'
segments.cpp:65:26: error: no match for 'operator=' (operand types are 'elem' and 'long long int')
   65 |         dp[pozmin] = i + 1;
      |                          ^
segments.cpp:12:8: note: candidate: 'constexpr elem& elem::operator=(const elem&)'
   12 | struct elem
      |        ^~~~
segments.cpp:12:8: note:   no known conversion for argument 1 from 'long long int' to 'const elem&'
segments.cpp:12:8: note: candidate: 'constexpr elem& elem::operator=(elem&&)'
segments.cpp:12:8: note:   no known conversion for argument 1 from 'long long int' to 'elem&&'