제출 #377100

#제출 시각아이디문제언어결과실행 시간메모리
377100Kevin_Zhang_TWCake 3 (JOI19_cake3)C++17
0 / 100
10 ms8704 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long ; #define pb emplace_back #define AI(i) begin(i), end(i) template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); } template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); } #ifdef KEV #define DE(args...) kout("[ " + string(#args) + " ] = ", args) void kout() { cerr << endl; } template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); } template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l) == r], ++l; } #else #define DE(...) 0 #define debug(...) 0 #endif const int MAX_N = 1<<18; const ll linf = 1ll << 59; int n, k; // color, value pair<int,int> cake[MAX_N]; struct lisan : vector<int> { void done() { sort(AI()), erase(unique(AI()), end()); } int operator()(int i) { return lower_bound(AI(), i) - begin(); } }allv; ll res = -linf; struct sgt { ll sum[MAX_N << 1], cnt[MAX_N << 1]; int cl = 0, cr = -1; void add(int i, int d) { int val = allv[i]; for (i += MAX_N;i;i>>=1) sum[i] += val * d, cnt[i] += d; } ll qry(int k = ::k) { if (cnt[1] < k) return -linf; int now = 1; ll res = 0; while (now < MAX_N) { if (cnt[now<<1|1] > k) now = now << 1 | 1; else { k -= cnt[now<<1|1]; res += sum[now<<1|1]; now = now << 1; } } return res; } void reset() { memset(sum, 0, sizeof(sum)); memset(cnt, 0, sizeof(cnt)); cl = 0, cr = -1; } void update(int l, int r) { if (r < cr) reset(); while (cr < r) { add(cake[++cr].second, 1); } while (cl < l) { add(cake[cl++].second,-1); } } }tree; ll cost(int i, int j) { return 2ll * abs(cake[i].first - cake[j].first); } void solve() { queue< tuple<int,int,int,int> > q; q.emplace(k-1, n-1, 0, n-1); while (q.size()) { auto [l, r, fl, fr] = q.front(); q.pop(); if (l > r) continue; int mid = l + r >> 1; ll mx = -linf, pos = -1; for (int i = fl;i <= min(mid, fr);++i) { tree.update(i, mid); DE(i, mid, tree.qry()); if (chmax(mx, tree.qry() - cost(i, mid))) pos = i; } chmax(res, mx); q.emplace(l, mid-1, fl, pos); q.emplace(mid+1, r, pos, fr); } } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> k; for (int i = 0;i < n;++i) { auto &[c, v] = cake[i]; cin >> v >> c; allv.pb(v); } allv.done(); sort(cake, cake + n); for (int i = 0;i < n;++i) { auto &[c, v] = cake[i]; v = allv(v); } solve(); cout << res << '\n'; }

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

cake3.cpp: In function 'void solve()':
cake3.cpp:79:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   79 |   int mid = l + r >> 1;
      |             ~~^~~
cake3.cpp:14:17: warning: statement has no effect [-Wunused-value]
   14 | #define DE(...) 0
      |                 ^
cake3.cpp:83:4: note: in expansion of macro 'DE'
   83 |    DE(i, mid, tree.qry());
      |    ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...