제출 #1025737

#제출 시각아이디문제언어결과실행 시간메모리
1025737HappyCapybara사탕 분배 (IOI21_candies)C++17
8 / 100
149 ms17744 KiB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long

int n;
vector<ll> st;

void update(int pos, ll val, int node=1, int tl=0, int tr=n-1){
    if (tl == tr){
        st[node] += val;
        return;
    }
    int tm = (tl+tr)/2;
    if (pos <= tm) update(pos, val, node*2, tl, tm);
    else update(pos, val, node*2+1, tm+1, tr);
    st[node] = st[node*2]+st[node*2+1];
}

ll query(int l, int r, int node=1, int tl=0, int tr=n-1){
    if (l <= tl && tr <= r) return st[node];
    int tm = (tl+tr)/2;
    ll res = 0;
    if (l <= tm) res += query(l, r, node*2, tl, tm);
    if (tm+1 <= r) res += query(l, r, node*2+1, tm+1, tr);
    return res;
}
 
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v){
    n = c.size();
    int q = l.size();
    st.resize(4*n, 0);
    for (int i=0; i<q; i++){
        update(l[i], v[i]);
        if (r[i] < n-1) update(r[i]+1, -v[i]);
    }
    vector<int> s(n);
    for (int i=0; i<n; i++) s[i] = min((ll) c[i], query(0, i));
    return s;
}
#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...