답안 #731528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
731528 2023-04-27T13:50:36 Z grogu Mizuyokan 2 (JOI23_mizuyokan2) C++14
0 / 100
4000 ms 7940 KB
#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);
        i = l;
        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);
        }
        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
**/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 515 ms 7940 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Execution timed out 4072 ms 5996 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -