제출 #102639

#제출 시각아이디문제언어결과실행 시간메모리
102639psmaoCake 3 (JOI19_cake3)C++14
0 / 100
3 ms512 KiB
#include <bits/stdc++.h> using namespace std; #define fo(i,s,t) for(int i = s; i <= t; ++ i) #define fd(i,s,t) for(int i = s; i >= t; -- i) #define bf(i,s) for(int i = head[s]; i; i = e[i].next) #define mp make_pair #define fi first #define se second #define pii pair<int,int> #define pb push_back #define VI vector<int> #define sf scanf #define pf printf #define fp freopen #define SZ(x) ((int)(x).size()) #ifdef MPS #define D(x...) printf(x) #else #define D(x...) #endif typedef long long ll; typedef double db; typedef unsigned long long ull; const int inf = 1<<30; const ll INF = 1ll<<60; const db Inf = 1e20; const db eps = 1e-9; void gmax(int &a,int b){a = (a > b ? a : b);} void gmin(int &a,int b){a = (a < b ? a : b);} const int maxn = 200050; int n, m, rt[maxn], tot; int ls[maxn], rs[maxn], nd[maxn]; ll sum[maxn]; ll ans = -INF; struct cake{int v, c;}c[maxn]; bool cmp(cake a, cake b) { return a.c < b.c; } void upd(int &now, int pre, int p, int l = 1, int r = 1000000000) { if(!now) now = ++ tot; nd[now] = nd[pre] + 1; sum[now] = sum[pre] + p; if(l == r) return; int mid = l + r >> 1; if(p <= mid) upd(ls[now], ls[pre], p, l, mid), rs[now] = rs[pre]; else upd(rs[now], rs[pre], p, mid+1, r), ls[now] = ls[pre]; } ll query(int now, int pre, int num, int l = 1, int r = 1000000000) { if(!now) return 0; int mid = l + r >> 1, c = nd[rs[now]] - nd[rs[pre]]; if(c == num) return sum[rs[now]] - sum[rs[pre]]; else if(c < num) return sum[rs[now]] - sum[rs[pre]] + query(ls[now], ls[pre], num - c, l, mid); else return query(rs[now], rs[pre], num, mid+1, r); } ll ask(int l, int r) { return query(rt[r], rt[l-1], m); } void solve(int l, int r, int ll, int rr) { if(l > r) return; if(l == r) { fo(i,ll,rr) if(l - i + 1 >= m) ans = max(ans, ask(i, l) - (c[l].c - c[i].c)*2); return; } int mid = l + r >> 1, p; long long best = -INF; fo(i, ll, rr) if(mid - i + 1 >= m) { long long v = ask(i, mid) - (c[mid].c - c[i].c)*2; if(best < v) { best = v; p = i; } } ans = max(ans, best); solve(l, mid-1, ll, p); solve(mid+1, r, p, rr); } int main() { #ifdef MPS fp("1.in","r",stdin); fp("1.out","w",stdout); #endif sf("%d%d",&n,&m); fo(i,1,n) sf("%d%d",&c[i].v,&c[i].c); sort(c+1,c+n+1,cmp); fo(i,1,n) upd(rt[i], rt[i-1], c[i].v); solve(1, n, 1, n); pf("%lld\n",ans); return 0; }

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

cake3.cpp: In function 'void upd(int&, int, int, int, int)':
cake3.cpp:50:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l + r >> 1;
            ~~^~~
cake3.cpp: In function 'll query(int, int, int, int, int)':
cake3.cpp:57:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l + r >> 1, c = nd[rs[now]] - nd[rs[pre]];
            ~~^~~
cake3.cpp: In function 'void solve(int, int, int, int)':
cake3.cpp:75:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l + r >> 1, p;
            ~~^~~
cake3.cpp: In function 'int main()':
cake3.cpp:97:4: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  sf("%d%d",&n,&m);
    ^
cake3.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fo(i,1,n) sf("%d%d",&c[i].v,&c[i].c);
              ^
cake3.cpp: In function 'void solve(int, int, int, int)':
cake3.cpp:88:7: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
  solve(l, mid-1, ll, p);
  ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...