제출 #133133

#제출 시각아이디문제언어결과실행 시간메모리
133133ekremCake 3 (JOI19_cake3)C++98
24 / 100
4070 ms41212 KiB
#include <bits/stdc++.h> #define st first #define nd second #define mp make_pair #define pb push_back #define sol (k+k) #define sag (k+k+1) #define orta ((bas+son)/2) #define coc g[node][i] #define mod 1000000007 #define inf 1000000000000000009 #define N 1000005 using namespace std; typedef long long ll; typedef pair < ll , ll > ii; ll n, m, k, ans = -inf, bas = 1, son, amk, a[N], b[N], ne[N], say[4*N], seg[4*N]; ii xx[N]; map < ll , ll > h, x; map < ll , ll > :: iterator it; void up(ll k, ll bas, ll son, ll x, ll y){ if(bas == son){ seg[k] += y*ne[bas]; say[k] += y; return; } if(x <= orta) up(sol, bas, orta, x, y); else up(sag, orta + 1, son, x, y); seg[k] = seg[sol] + seg[sag]; say[k] = say[sol] + say[sag]; } ll qu(ll k, ll bas, ll son, ll x){ if(bas == son) return x*ne[bas]; if(say[sag] >= x) return qu(sag, orta + 1, son, x); return seg[sag] + qu(sol, bas, orta, x - say[sag]); } void getir(ll bs, ll sn){ while(bas < bs){ up(1, 1, k, x[a[bas]], -1); bas++; } while(bas > bs){ bas--; up(1, 1, k, x[a[bas]], 1); } while(son > sn){ up(1, 1, k, x[a[son]], -1); son--; } while(son < sn){ son++; up(1, 1, k, x[a[son]], 1); } } void f(ll bas, ll son, ll optl, ll optr){ // amk++;if(amk > 50)exit(0); if(bas > son)return; ll optm = optr, opt = -inf; for(ll i = optl; i <= optr; i++){ if(i - orta + 1 < m) continue; getir(orta + 1, i - 1); ll of = qu(1, 1, k, m - 2); ll cvp = of + a[orta] + a[i] - 2*(b[i] - b[orta]); // if(cvp == 152)cout << "geldi amk " << orta << " " << i << " " << of << " = " << cvp << endl; if(cvp > opt){ opt = cvp; optm = i; } } // cout << bas << " " << son << " " << orta << " " << optl << " " << optr << " = " << opt << " " << optm << endl; ans = max(ans, opt); f(bas, orta - 1, optl, optm); f(orta + 1, son, optm, optr); } int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); scanf("%lld %lld",&n ,&m); for(ll i = 1; i <= n; i++){ scanf("%lld %lld",&xx[i].nd ,&xx[i].st); h[xx[i].nd]++; } for(it = h.begin(); it != h.end(); it++){ x[it->st] = ++k; ne[k] = it->st; // cout << k << " " << it->st << endl; } sort(xx + 1, xx + n + 1); for(ll i = 1; i <= n; i++){ a[i] = xx[i].nd; b[i] = xx[i].st; // cout << a[i] << " " << b[i] << endl;; } // cout << endl; // getir(2, 4); // cout << qu(1, 1, k, 3) << endl; // cout << qu(1, 1, k, 2) << endl; // cout << qu(1, 1, k, 1) << endl; // cout << qu(1, 1, k, 0) << endl; f(1, n, 1, n); printf("%lld\n", ans); return 0; }

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

cake3.cpp: In function 'int main()':
cake3.cpp:89:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld",&n ,&m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
cake3.cpp:91:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld",&xx[i].nd ,&xx[i].st);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...