Submission #373556

#TimeUsernameProblemLanguageResultExecution timeMemory
373556PixelCatGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms364 KiB
/* /^--^\ \____/ / \ _____ _ __ __ ____ _ ____ ____ _____ | || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_ _| \__ __/ |_| |_|/_/\_\|____||____|\____)/__/\__\ |_| |^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^| | | |\ \| | | | | | | | | | | | | | | | | | | | | | | | | #####/ /################################################# | | |\/ | | | | | | | | | | | | | | | | | | | | | | | | | |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|*/ //#pragma GCC optimize("O4,unroll-loops,no-stack-protector") #include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; using pii=pair<ll,ll>; #define int ll #define double long double #define For(i,a,b) for(int i=a;i<=b;i++) #define Forr(i,a,b) for(int i=a;i>=b;i--) #define F first #define S second #define L(id) (id*2+1) #define R(id) (id*2+2) #define LO(x) (x&(-x)) #define eb emplace_back #define all(x) x.begin(),x.end() #define sz(x) ((int)x.size()) #define mkp make_pair #define MOD (ll)(1000000007) #define INF (ll)(1e15) #define EPS (1e-9) #ifdef LOCALMEOW #define debug(...) do{\ cerr << __LINE__ <<\ " : ("#__VA_ARGS__ << ") = ";\ _OUT(__VA_ARGS__);\ }while(0) template<typename T> void _OUT(T x) { cerr << x << "\n"; } template<typename T,typename...I> void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); } #else #define debug(...) #endif inline void IOS(){ ios::sync_with_stdio(false); cin.tie(0); } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int gcd(int a,int b) { return b==0?a:gcd(b,a%b); } int lcm(int a,int b) { return a/gcd(a,b)*b; } int fpow(int b,int p){ int ans=1,now=b; while(p){ if(p&1) ans=ans*now%MOD; p/=2; now=now*now%MOD; } return ans; } void minify(int &a,int b) { if(b<a) a=b; } void maxify(int &a,int b) { if(b>a) a=b; } struct SegTree{ int a[800080]; void build(int id,int l,int r,vector<int> &v){ if(l==r){ a[id]=v[l]; return; } int m=(l+r)/2; build(L(id),l,m,v); build(R(id),m+1,r,v); } void add(int id,int l,int r,int L,int R,int x){ if(l>R || r<L) return; if(l>=L && r<=R){ a[id]+=x; return; } int m=(l+r)/2; add(L(id),l,m,L,R,x); add(R(id),m+1,r,L,R,x); } int ask(int id,int l,int r,int x){ if(l==r) return a[id]; int m=(l+r)/2; if(x<=m) return a[id]+ask(L(id),l,m,x); else return a[id]+ask(R(id),m+1,r,x); } }seg; int32_t main(){ IOS(); //code... int n; cin>>n; vector<int> v(n); for(auto &i:v) cin>>i; seg.build(0,0,n-1,v); int r=n-2,l=1; while(r>=0 && v[r]>v[r+1]) r--; while(l<n && v[l]>v[l-1]) l++; int ans=0; while(r>=l){ int k=min(seg.ask(0,0,n-1,r+1)-seg.ask(0,0,n-1,r)+1, seg.ask(0,0,n-1,l-1)-seg.ask(0,0,n-1,l)+1); seg.add(0,0,n-1,l,r,k); ans+=k; while(r>=0 && seg.ask(0,0,n-1,r)>seg.ask(0,0,n-1,r+1)) r--; while(l<n && seg.ask(0,0,n-1,l)>seg.ask(0,0,n-1,l-1)) l++; } //cout<<l<<" "<<r<<" "<<ans<<"\n"; if(seg.ask(0,0,n-1,r)==seg.ask(0,0,n-1,l)) ans+=(l-r+1)/2; cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...