Submission #731523

#TimeUsernameProblemLanguageResultExecution timeMemory
731523groguMizuyokan 2 (JOI23_mizuyokan2)C++14
0 / 100
4072 ms7832 KiB
#define here cerr<<"===========================================\n" #define dbg(x) cerr<<#x<<": "<<x<<endl; #include <bits/stdc++.h> #define ld double #define ll long long #define ull unsigned long long #define llinf 100000000000000000LL // 10^17 #define iinf 2000000000 // 2*10^9 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pii pair<int,int> #define pll pair<ll,ll> #define pld pair<ld,ld> #define all(a) a.begin(),a.end() #define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;} #define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;} using namespace std; #define maxn 200005 ll n,q; ll a[maxn]; ll t[2*maxn]; int ls[2*maxn],rs[2*maxn],tsz = 0,root = 0; void init(int &v,int tl,int tr){ if(!v) v = ++tsz; if(tl==tr){t[v] = a[tl];return;} int mid = (tl+tr)/2; init(ls[v],tl,mid); init(rs[v],mid+1,tr); t[v] = t[ls[v]] + t[rs[v]]; } void upd(ll v,ll tl,ll tr,ll i,ll x){ if(tl==tr){t[v] = x;return;} int mid = (tl+tr)/2; if(i<=mid) upd(ls[v],tl,mid,i,x); else upd(rs[v],mid+1,tr,i,x); t[v] = t[ls[v]] + t[rs[v]]; } ll sum(ll v,ll tl,ll tr,ll l,ll r){ if(l>r||l>tr||tl>r||tl>tr) return 0; if(tl>=l&&tr<=r) return t[v]; ll mid = (tl+tr)/2; return sum(ls[v],tl,mid,l,r) + sum(rs[v],mid+1,tr,l,r); } int main(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); cin >> n; for(ll i = 1;i<=n;i++) cin >> a[i]; init(root,1,n); cin >> q; while(q--){ ll i,x,l,r; cin >> i >> x >> l >> r; a[i] = x; upd(1,1,n,i,x); l++; vector<ll> ans; ll cur = 0; ll rez = 1; for(ll i = l;i<=r;i++){ ll x = ans.size()?ans.back():0; if(cur<=a[i]||cur<=x){ cur+=a[i]; }else{ ans.pb(cur); ans.pb(a[i]); if(sum(1,1,n,i+1,r)>a[i]) rez = max(rez,(ll)ans.size()+1); if(i+1<=r-1){ ll y = sum(1,1,n,i+1,r-1); if(y>a[r]&&y>a[i]) rez = max(rez,(ll)(ans.size())+2); } cur = 0; } } if(!cur) rez = max(rez,(ll)ans.size()); ans.clear(); cur = 0; ans.pb(a[l]); if(sum(1,1,n,l+1,r)>a[l]) rez = max(rez,2LL); for(ll i = l+1;i<=r;i++){ ll x = ans.size()?ans.back():0; if(cur<=a[i]||cur<=x){ cur+=a[i]; }else{ ans.pb(cur); ans.pb(a[i]); if(sum(1,1,n,i+1,r)>a[i]) rez = max(rez,(ll)ans.size()+1); if(i+1<=r-1){ ll y = sum(1,1,n,i+1,r-1); if(y>a[r]&&y>a[i]) rez = max(rez,(ll)(ans.size())+2); } cur = 0; } } if(!cur) rez = max(rez,(ll)ans.size()); cout<<rez<<endl; } return 0; } /** 6 5 6 8 7 4 9 1 6 9 0 5 4 6 2 3 6 3 3 2 1 3 4 5 1 4 1 1 0 4 **/
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...