제출 #1036722

#제출 시각아이디문제언어결과실행 시간메모리
1036722trandangquang휴가 (IOI14_holiday)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define task "test" #define FOR(i, a, b) for(int i = (a); i <= (b); ++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define sz(a) (int)(a).size() #define all(a) (a).begin(), (a).end() #define bit(s, i) (((s) >> (i)) & 1) #define ii pair <int, int> #define vii vector <ii> #define vi vector <int> #define fi first #define se second #define int long long #define ll long long #define eb emplace_back #define pb push_back #define __builtin_popcount __builtin_popcountll void solve(); int32_t main() { if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } // cin.tie(0)->sync_with_stdio(0); int tc = 1; // cin >> tc; FOR(i, 1, tc) { solve(); } } const int N = 250005; int n, st, d, att[N], upto[20]; ii bestr[N], bestl[N]; vi rar; /// bestr[u] = {gia tri, vi tri gan nhat} khi di voi thoi gian u /// bestl[u]: tuong tu voi bestr[u] struct segmentTree { struct node { int num = 0; ll sum = 0; } st[N<<2]; void reset() { node tmp = {0, 0}; fill(begin(st), end(st), tmp); } void upd(int x, int val) { int id=1, l=1, r=sz(rar); while(1) { if(l==r) break; int m=(l+r)>>1; if(x<=m) { id = id<<1; r=m; } else { id = id<<1|1; l=m+1; } } st[id].num += val; st[id].sum += val*rar[x-1]; while(id>1) { id /= 2; st[id].num = st[id<<1].num + st[id<<1|1].num; st[id].sum = st[id<<1].sum + st[id<<1|1].sum; } } ll get_max(int nli) { int id=1, l=1, r=sz(rar); ll res = 0; while(l<=r) { if(l==r) break; int m=(l+r)>>1; if(st[id<<1|1].num <= nli) { nli-=st[id<<1|1].num; res+=st[id<<1|1].sum; id=id<<1; r=m; } else { id=id<<1|1; l=m+1; } } return res + min(nli, st[id].num)*rar[l-1]; } } smt[20]; void calcr(int L, int R, int optL, int optR, int lvl) { // printf("Range: %d %d, optRange: %d %d\n", L, R, optL, optR); if(L > R) return; int mid = (L+R) >> 1; FOR(i, optL, optR) { if(mid-(i-st) < 0) break; /// neu nhu di qua xa -> break while(upto[lvl] < i) smt[lvl].upd(att[++upto[lvl]], 1); int nwVal = smt[lvl].get_max(mid-(i-st)); if(nwVal > bestr[mid].fi) { bestr[mid].fi = nwVal; bestr[mid].se = i; } } calcr(L, mid-1, optL, bestr[mid].se, lvl+1); calcr(mid+1, R, bestr[mid].se, optR, lvl+1); } void calcl(int L, int R, int optL, int optR, int lvl) { // printf("Range: %d %d, optRange: %d %d\n", L, R, optL, optR); if(L > R) return; int mid = (L+R) >> 1; FORD(i, optR, optL) { if(mid-(st-i) < 0) break; /// while(upto[lvl] > i) smt[lvl].upd(att[--upto[lvl]], 1); int nwVal = smt[lvl].get_max(mid-(st-i)); // if(mid == 3) cout << i << " " << nwVal << " " << mid-(st-i) << '\n'; if(nwVal > bestl[mid].fi) { bestl[mid].fi = nwVal; bestl[mid].se = i; } } // cout << mid << " " << bestl[mid].se<<" "<<bestl[mid].fi<<'\n'; calcl(L, mid-1, bestl[mid].se, optR, lvl+1); calcl(mid+1, R, optL, bestl[mid].se, lvl+1); } void solve() { cin >> n >> st >> d; ++st; FOR(i, 1, n) { cin >> att[i]; rar.eb(att[i]); } sort(all(rar)); FOR(i, 1, n) { att[i] = upper_bound(all(rar), att[i]) - rar.begin(); } memset(bestr, -1, sizeof(bestr)); memset(bestl, -1, sizeof(bestl)); FOR(i, 1, 19) upto[i] = st; calcr(1, d, st+1, n, 1); FOR(i, 1, 19) { smt[i].reset(); upto[i] = st; } calcl(1, d, 1, st-1, 1); // cout << "left things:\n"; // FOR(i, 1, d) printf("time: %d, pos: %d, val: %d\n", i, bestl[i].se, bestl[i].fi); int ans = 0; bestl[0].fi = bestr[0].fi = 0; FOR(i, 0, d) { if(d-i-(bestr[i].se-st)>=0) { ans = max(ans, bestr[i].fi + bestl[d-i-(bestr[i].se-st)].fi); } if(d-i-(st-bestl[i].se)>=0) { ans = max(ans, bestl[i].fi + bestr[d-i-(st-bestl[i].se)].fi); } ans = max(ans, bestl[i].fi); ans = max(ans, bestr[i].fi); } // cout<<bestr[2].fi<<" "<<d-2-(bestr[2].se-st)<<'\n'; // cout<<bestl[3].fi << '\n'; --d; FOR(i, 0, d) { if(d-i-(bestr[i].se-st)>=0) { ans = max(ans, bestr[i].fi + bestl[d-i-(bestr[i].se-st)].fi + rar[att[st] - 1]); // if(i==2) cout<<att[st]<<'\n'; } if(d-i-(st-bestl[i].se)>=0) { ans = max(ans, bestl[i].fi + bestr[d-i-(st-bestl[i].se)].fi + rar[att[st] - 1]); } ans = max(ans, bestl[i].fi + rar[att[st] - 1]); ans = max(ans, bestr[i].fi + rar[att[st] - 1]); } cout << ans; }

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

holiday.cpp: In function 'void solve()':
holiday.cpp:160:36: warning: 'void* memset(void*, int, size_t)' writing to an object of type 'struct std::pair<long long int, long long int>' with no trivial copy-assignment [-Wclass-memaccess]
  160 |     memset(bestr, -1, sizeof(bestr));
      |                                    ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from holiday.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<long long int, long long int>' declared here
  211 |     struct pair
      |            ^~~~
holiday.cpp:161:36: warning: 'void* memset(void*, int, size_t)' writing to an object of type 'struct std::pair<long long int, long long int>' with no trivial copy-assignment [-Wclass-memaccess]
  161 |     memset(bestl, -1, sizeof(bestl));
      |                                    ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from holiday.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<long long int, long long int>' declared here
  211 |     struct pair
      |            ^~~~
holiday.cpp: In function 'int32_t main()':
holiday.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holiday.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cct0rJft.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccJD4ULv.o:holiday.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cct0rJft.o: in function `main':
grader.cpp:(.text.startup+0xaf): undefined reference to `findMaxAttraction(int, int, int, int*)'
collect2: error: ld returned 1 exit status