Submission #587741

#TimeUsernameProblemLanguageResultExecution timeMemory
587741Koosha_mvMeetings (IOI18_meetings)C++14
0 / 100
42 ms22048 KiB
#include "meetings.h" #include <bits/stdc++.h> using namespace std; #define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl #define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl #define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl #define eror(x) cout<<#x<<'='<<(x)<<endl #define f_(i,a,b) for(int i=a;i>=b;i--) #define f(i,a,b) for(int i=a;i<b;i++) #define nb(x) __builtin_popcount(x) #define all(v) v.begin(),v.end() #define bit(n,k) (((n)>>(k))&1) #define Add(x,y) x=(x+y)%mod #define maxm(a,b) a=max(a,b) #define minm(a,b) a=min(a,b) #define lst(x) x[x.size()-1] #define sz(x) int(x.size()) #define mp make_pair #define ll long long #define pb push_back #define S second #define F first const int N=1e6+99; const ll inf=1e9+99; int n,q; ll res[N]; vector<ll> H,A; vector<ll> ans; struct node{ int pfx,sfx,res,l,r; node(int x=-1){ if(x==-1){ pfx=sfx=res=l=r=0; } else{ l=x,r=x+1; if(H[x]==1) pfx=sfx=res=1; else pfx=sfx=res=0; } } node friend operator + (node A,node B){ node ans; ans.pfx=A.pfx; ans.sfx=B.sfx; ans.res=max(A.res,B.res); if(ans.pfx==A.r-A.l) ans.pfx+=B.pfx; if(ans.sfx==B.r-B.l) ans.sfx+=B.sfx; maxm(ans.res,A.sfx+B.pfx); return ans; } } seg[N]; void build(int id=1,int l=0,int r=n){ if(l+1==r){ seg[id]=node(l); return ; } int mid=(l+r)>>1; build(id<<1,l,mid); build(id<<1|1,mid,r); seg[id]=seg[id<<1]+seg[id<<1|1]; } node get(int L,int R,int id=1,int l=0,int r=n){ if(r<=L || R<=l) return node(); if(L<=l && r<=R){ return seg[id]; } int mid=(l+r)>>1; return get(L,R,id<<1,l,mid)+get(L,R,id<<1|1,mid,r); } vector<ll> minimum_costs(vector<int> _H,vector<int> L,vector<int> R){ q=L.size(),n=_H.size(); f(i,0,n) H.pb(_H[i]); ans.resize(q); build(); f(i,0,q){ int l=L[i],r=R[i]+1; ans[i]=2*(r-l)-get(l,r).res; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...