제출 #952263

#제출 시각아이디문제언어결과실행 시간메모리
952263yeediotCake 3 (JOI19_cake3)C++14
0 / 100
1 ms4444 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define F first #define S second #define all(x) x.begin(),x.end() #define pii pair<int,int> #define pb push_back #define sz(x) (int)(x.size()) #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) #define vi vector<int> #define vp vector<pii> #define vvi vector<vi> #define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) #define __lg(x) 63-__builtin_clzll(x) #define pow2(x) (1LL<<x) void __print(int x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef local void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);} #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else void setio(){} #define debug(x...) #endif void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } struct line{ int a,b; int operator()(const int x)const{ return a*x+b; } }; bool check(line l1,line l2,line l3){ return (l3.b-l2.b)*(l1.a-l2.a)<=(l2.b-l1.b)*(l2.a-l3.a); } const int mxn=2e5+5; int V[mxn],c[mxn],root[mxn]; vector<int>temp; struct SegTree{ int l,r,sum,c; }; SegTree seg[mxn<<5]; int cnt; int build(int l,int r){ int node=++cnt; seg[node].sum=0; seg[node].c=0; if(l==r){ return node; } int mm=l+r>>1; seg[node].l=build(l,mm); seg[node].r=build(mm+1,r); return node; } int update(int from,int l,int r,int p,int v){ int node=++cnt; seg[node]=seg[from]; if(l==r){ seg[node].c++; seg[node].sum+=v; return node; } int mm=l+r>>1; if(p<=mm){ seg[node].l=update(seg[node].l,l,mm,p,v); } else{ seg[node].r=update(seg[node].r,mm+1,r,p,v); } seg[node].sum=seg[seg[node].l].sum+seg[seg[node].r].sum; seg[node].c=seg[seg[node].l].c+seg[seg[node].r].c; return node; } int query(int v,int u,int l,int r,int k){ if(l==r){ return min(seg[u].c-seg[v].c,k)*temp[l-1]; } int mm=l+r>>1; int x=seg[seg[u].r].sum-seg[seg[v].r].sum; int y=seg[seg[u].r].c-seg[seg[v].r].c; if(y>=k){ return query(seg[v].r,seg[u].r,mm+1,r,k); } else{ return x+query(seg[v].l,seg[u].l,l,mm,k-y); } } int P,m; int calc(int l,int r){ return 2*c[l]-2*c[r]+query(root[l-1],root[r],1,P,m); } int ans=0; void go(int l,int r,int ql,int qr){ if(r<l){ return; } int mm=l+r>>1; int mx=-8e18,best=ql; for(int i=ql;i<=qr and i+m-1<=mm;i++){ int x=calc(i,mm); debug(i,mm,x); if(x>mx){ mx=x; best=i; } } chmax(ans,mx); go(l,mm-1,ql,best); go(mm+1,r,best,qr); } signed main(){ setio(); ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int n; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>V[i]>>c[i]; temp.pb(V[i]); } sort(all(temp)); temp.resize(unique(all(temp))-temp.begin()); P=sz(temp); root[0]=build(1,P); for(int i=1;i<=n;i++){ int x=lower_bound(all(temp),V[i])-temp.begin()+1; root[i]=update(root[i-1],1,P,x,temp[x-1]); } go(1,n,1,n); cout<<ans<<'\n'; } /* input: */

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

cake3.cpp: In function 'long long int build(long long int, long long int)':
cake3.cpp:69:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   69 |     int mm=l+r>>1;
      |            ~^~
cake3.cpp: In function 'long long int update(long long int, long long int, long long int, long long int, long long int)':
cake3.cpp:82:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   82 |     int mm=l+r>>1;
      |            ~^~
cake3.cpp: In function 'long long int query(long long int, long long int, long long int, long long int, long long int)':
cake3.cpp:97:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   97 |     int mm=l+r>>1;
      |            ~^~
cake3.cpp: In function 'void go(long long int, long long int, long long int, long long int)':
cake3.cpp:116:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  116 |     int mm=l+r>>1;
      |            ~^~
cake3.cpp: In function 'void setIO(std::string)':
cake3.cpp:42:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cake3.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...