답안 #831841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831841 2023-08-20T15:57:35 Z andrey27_sm 사탕 분배 (IOI21_candies) C++17
0 / 100
280 ms 32172 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sum[800001];
ll max_pref[800001];
ll min_pref[800001];
void update(int v,int l,int r,int t,int val){
    if(r < t or t < l) return;
    if(l == r){
        sum[v]+=val;
        max_pref[v] = sum[v];
        min_pref[v] = sum[v];
        return;
    }
    int m = (l+r)>>1;
    update(v<<1,l,m,t,val);
    update(v<<1|1,m+1,r,t,val);
    sum[v] = sum[v<<1]+sum[v<<1|1];
    max_pref[v] = max(max_pref[v<<1],sum[v<<1]+max_pref[v<<1|1]);
    min_pref[v] = max(min_pref[v<<1],sum[v<<1]+min_pref[v<<1|1]);
}
ll get(int v,int l,int r,int val_max){
    if(l == r){
        if(sum[v] > val_max) return val_max;
        if(sum[v] < 0) return 0;
        return val_max;
    }
    int m = (l+r)/2;
    if(max_pref[v<<1|1]-min_pref[v<<1|1] > val_max) return get(v<<1|1,m+1,r,val_max);
    ll tmp_val = get(v<<1,l,m,val_max);
    if(tmp_val+min_pref[v<<1|1] < 0) return sum[v<<1|1]-min_pref[v<<1|1];
    if(tmp_val+max_pref[v<<1|1] > val_max) return val_max+sum[v<<1|1]-max_pref[v<<1|1];
    return tmp_val+sum[v<<1|1];
}
vector<pair<int,int>> ev[200001];
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    vector<int> ans;
    int n = c.size();
    int q = l.size();
    for (int i = 0; i < q; ++i) {
        ev[l[i]].push_back({i,v[i]});
        ev[r[i]+1].push_back({i,-v[i]});
    }
    for (int i = 0; i < n; ++i) {
        for(auto e:ev[i]) update(1,0,q-1,e.first,e.second);
        ans.push_back(get(1,0,q-1,c[i]));
    }
    return ans;
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 2 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 280 ms 32172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 2 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -