답안 #1048950

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1048950 2024-08-08T11:31:07 Z nisanduu 사탕 분배 (IOI21_candies) C++17
0 / 100
207 ms 27216 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){
                ll am = 1LL*(r-l+1)*lazy[ind];
                seg[ind]+=am;
                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){
                ll am = 1LL*(r-l+1)*lazy[ind];
                seg[ind]+=am;
                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){
                ll am = 1LL*(r-l+1)*val;
                lazy[ind]=0;
                seg[ind]+=am;
                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:80:8: warning: unused variable 'tot' [-Wunused-variable]
   80 |     ll tot = 0;
      |        ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 207 ms 27216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -