Submission #1048996

# Submission time Handle Problem Language Result Execution time Memory
1048996 2024-08-08T11:53:48 Z nisanduu Distributing Candies (IOI21_candies) C++17
8 / 100
205 ms 28756 KB
//#include "candies.h"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll maxi = 1e12;
class SGT{
    public: vector<ll> seg,arr,lazy;
    public:
        SGT(ll n,vector<ll>v){
            seg.resize(4*n + 3);
            lazy.resize(4*n + 3);
            arr = v;
        }
        void build(ll l,ll r,ll ind){
            if(l==r){
                seg[ind] = arr[l];
                return;
            }
            ll mid = (l+r)/2;
            build(l,mid,2*ind+1);
            build(mid+1,r,2*ind+2);
            seg[ind] = seg[2*ind+1]+seg[2*ind+2];
        }
        ll query(ll l,ll r,ll ind,ll pos){
            if(lazy[ind]!=0){
                if(lazy[ind]>1e9) lazy[ind]=1e9;
                ll am = 1LL*(r-l+1)*lazy[ind];
                seg[ind]+=am;
                if((seg[ind]/(r-l+1))>1e9) seg[ind] = 1LL*(r-l+1)*1e9;
                if(l!=r){
                    lazy[2*ind+1] += lazy[ind];
                    lazy[2*ind+2] += lazy[ind];
                }
                lazy[ind]=0;
            }
            if(l==r){
                return seg[ind];
            }
            ll mid = (l+r)/2;
            if(mid>=pos) return query(l,mid,2*ind+1,pos);
            else return query(mid+1,r,2*ind+2,pos);
        }
        void update(ll l,ll r,ll ind,ll left,ll right,ll val){
            if(lazy[ind]!=0){
                if(lazy[ind]>1e9) lazy[ind]=1e9;
                ll am = 1LL*(r-l+1)*lazy[ind];
                seg[ind]+=am;
                if((seg[ind]/(r-l+1))>1e9) seg[ind] = 1LL*(r-l+1)*1e9;
                if(l!=r){
                    lazy[2*ind+1] += lazy[ind];
                    lazy[2*ind+2] += lazy[ind];
                }
                lazy[ind]=0;
            }
            if(r<left||l>right) return;
            if(r<=right&&l>=left){
                if(lazy[ind]>1e9) lazy[ind]=1e9;
                ll am = 1LL*(r-l+1)*val;
                lazy[ind]=0;
                seg[ind]+=am;
                if((seg[ind]/(r-l+1))>1e9) seg[ind] = 1LL*(r-l+1)*1e9;
                if(l!=r){
                    lazy[2*ind+1] += val;
                    lazy[2*ind+2] += val;
                }
                return;
            }
            ll mid = (l+r)/2;
            update(l,mid,2*ind+1,left,right,val);
            update(mid+1,r,2*ind+2,left,right,val);
            seg[ind]=seg[2*ind+1]+seg[2*ind+2];
        }
};


vector<int> distribute_candies(vector<int> c, vector<int> l,
                                    vector<int> r, vector<int> v) {
    int n = c.size();
    int q = l.size();
    vector<int> s(n);
    vector<ll> vec(n+1);
    SGT sg(n,vec);
    sg.build(0,n-1,0);
    ll tot = 0;
    for(ll i=0;i<q;i++){
        sg.update(0,n-1,0,l[i],r[i],v[i]);
    }
    for(ll i=0;i<n;i++){
        s[i] = sg.query(0,n-1,0,i);
        s[i] = min(s[i],c[i]);
    }
    
    return s;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:86:8: warning: unused variable 'tot' [-Wunused-variable]
   86 |     ll tot = 0;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 166 ms 24660 KB Output is correct
2 Correct 205 ms 28756 KB Output is correct
3 Correct 157 ms 28496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -