제출 #1021109

#제출 시각아이디문제언어결과실행 시간메모리
1021109ReLiceFish 3 (JOI24_fish3)C++17
55 / 100
962 ms70064 KiB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
template<class S,class T>
bool chmin(S &a,const T &b) {
	return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
	return a<b?(a=b)==b:false;
}
//void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=1e18;
const ll mod=998244353;
const ll N=3e5+7;
const ll M=1e5+7;
const ld eps=1e-9;
ll d;
struct ST{
    pll t;
    vll add;
    void init(){
        t.assign(N*4,{0,0});
        add.assign(N*4,0);
    }
    void push(ll v,ll tl,ll tr){
        if(tl!=tr){
            add[v*2]+=add[v];
            add[v*2+1]+=add[v];
        }
        t[v].fr-=add[v]*d;
        t[v].sc+=(tr-tl+1)*add[v];
        add[v]=0;
    }
    void upd(ll id,ll l,ll r,ll val,ll v=1,ll tl=1,ll tr=N){
        push(v,tl,tr);
        if(tl>r || tr<l)return;
        if(l<=tl && tr<=r){
            if(id==0)t[v].fr=val;
            else{
                add[v]=val;
                push(v,tl,tr);
            }
            return;
        }ll tm=(tl+tr)/2;
        upd(id,l,r,val,v*2,tl,tm);
        upd(id,l,r,val,v*2+1,tm+1,tr);
        t[v].sc=t[v*2].sc+t[v*2+1].sc;
    }
    ll get(ll id,ll l,ll r,ll v=1,ll tl=1,ll tr=N){
        push(v,tl,tr);
        if(tl>r || tr<l)return 0;
        if(l<=tl && tr<=r) return (id==0 ? t[v].fr : t[v].sc);
        ll tm=(tl+tr)/2;
        return get(id,l,r,v*2,tl,tm)+get(id,l,r,v*2+1,tm+1,tr);
    }
}t;
void solve(){
    ll i,j;
    ll n;
    cin>>n>>d;
    t.init();
    for(i=1;i<=n;i++){
        ll x;
        cin>>x;
        t.upd(0,i,i,x);
    }
    ll q;
    cin>>q;
    vector<pll> qq(n+5);
    ll ans[q+5];
    for(i=0;i<q;i++){
        ll l,r;
        cin>>l>>r;
        qq[r].pb({l,i});
    }
    pll v;
    v.pb({1,1});
    for(auto i : qq[1]){
        ans[i.sc]=0;
    }
    for(i=2;i<=n;i++){
        ll l=i,r=i;
        while(v.sz){
            ll x=v.bc.fr,y=v.bc.sc;
            ll k=t.get(0,y,y);
            ll m=t.get(0,l,l);
            if(k<m){
                if(m-k>=d){v.pb({l,r});break;}
                else l=x;
            }else{
                t.upd(1,x,y,(k-m+d-1)/d);
                l=x;
            }
            v.pob;
        }
        v.pb({l,r});
        for(auto j : qq[i]){
            if(t.get(0,j.fr,j.fr)<0)ans[j.sc]=-1;
            else ans[j.sc]=t.get(1,j.fr,i);
        }
    }
    for(i=0;i<q;i++) cout<<ans[i]<<endl;
}
signed main(){
    start();
    ll t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}
/*
7 10
1 2
1 3
4 2
100 1
100 2
100 3
300 2


*/

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

Main.cpp: In function 'void solve()':
Main.cpp:87:10: warning: unused variable 'j' [-Wunused-variable]
   87 |     ll i,j;
      |          ^
#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...