답안 #1083130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083130 2024-09-02T15:57:34 Z ZeroCool 사탕 분배 (IOI21_candies) C++17
100 / 100
991 ms 43764 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ar array
#define ll long long

const ll LOG = 20;
const ll N = 2e5 + 20;
const ll MOD = 1e9 + 7;
const ll INF = 1e17;

namespace seggy{
    ll mn[4 * N], mx[4 * N], lz[4 * N];

    void push(ll k,ll tl,ll tr){
        mn[k] += lz[k], mx[k] += lz[k];
        if(tl != tr)lz[k * 2] += lz[k], lz[k *2 + 1] += lz[k];
        lz[k]  =0;
    }

    void upd(ll k,ll tl,ll tr,ll l,ll r,ll v){
        push(k, tl, tr);
        if(tl > r || l > tr)return;
        if(l <= tl && tr <= r){
            lz[k] += v;
            push(k, tl, tr);
            return;
        }
        ll tm = (tl + tr) / 2;
        upd(k *2, tl, tm, l, r, v);
        upd(k * 2 + 1, tm + 1, tr ,l, r, v);
        mn[k] = min(mn[k *2], mn[k *2 + 1]);
        mx[k] = max(mx[k * 2], mx[k *2 + 1]);
    }

    ll qry(ll k,ll tl,ll tr,ll v){
        push(k, tl, tr);
        if(tl == tr)return mn[k];
        ll tm = (tl + tr) / 2;
        if(mx[k *2 + 1] + lz[k *2 + 1]>= v)return qry(k * 2 + 1, tm + 1, tr, v);
        else return min(mn[k *2 + 1] + lz[k *2 + 1], qry(k * 2, tl, tm, v));
    }
};


vector<int> distribute_candies(vector<int> C, vector<int> L,vector<int> R, vector<int> V) {
    ll n = C.size(), q = L.size();
    vector<ll> be[n], en[n];
    for(ll i = 0;i < q;i++){
        be[L[i]].push_back(i);
        en[R[i]].push_back(i);
    }
    vector<int> res(n);
    for(ll i = 0;i < n;i++){
        for(auto j: be[i])seggy::upd(1, 0, q - 1, 0, j, V[j]);
       // cout<<i<<endl;

        ll lo = 1, hi = C[i] + 1;
        ll ans;
        while(lo <= hi){
            ll tm = (lo + hi) / 2;
            ll mn = min(0ll, seggy::qry(1, 0, q - 1, tm));
            if(seggy::mx[1] < tm)mn = -INF;
            if(tm - mn > C[i]){
                ans = tm;
                hi = tm - 1;
            }else lo = tm + 1;
        }
        res[i] = ans - 1;
        for(auto j: en[i])seggy::upd(1, 0, q - 1, 0, j, -V[j]);

    }
    return res;
}

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:70:22: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   70 |         res[i] = ans - 1;
      |                  ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 646 ms 36948 KB Output is correct
2 Correct 589 ms 41228 KB Output is correct
3 Correct 637 ms 41044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 183 ms 25988 KB Output is correct
3 Correct 374 ms 15648 KB Output is correct
4 Correct 846 ms 43092 KB Output is correct
5 Correct 793 ms 43348 KB Output is correct
6 Correct 746 ms 43764 KB Output is correct
7 Correct 991 ms 43092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 131 ms 23448 KB Output is correct
4 Correct 188 ms 13636 KB Output is correct
5 Correct 406 ms 35768 KB Output is correct
6 Correct 434 ms 36552 KB Output is correct
7 Correct 443 ms 37196 KB Output is correct
8 Correct 467 ms 35540 KB Output is correct
9 Correct 733 ms 37084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 646 ms 36948 KB Output is correct
7 Correct 589 ms 41228 KB Output is correct
8 Correct 637 ms 41044 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 183 ms 25988 KB Output is correct
11 Correct 374 ms 15648 KB Output is correct
12 Correct 846 ms 43092 KB Output is correct
13 Correct 793 ms 43348 KB Output is correct
14 Correct 746 ms 43764 KB Output is correct
15 Correct 991 ms 43092 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 131 ms 23448 KB Output is correct
19 Correct 188 ms 13636 KB Output is correct
20 Correct 406 ms 35768 KB Output is correct
21 Correct 434 ms 36552 KB Output is correct
22 Correct 443 ms 37196 KB Output is correct
23 Correct 467 ms 35540 KB Output is correct
24 Correct 733 ms 37084 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 215 ms 13664 KB Output is correct
27 Correct 172 ms 25760 KB Output is correct
28 Correct 612 ms 41556 KB Output is correct
29 Correct 547 ms 41936 KB Output is correct
30 Correct 533 ms 42068 KB Output is correct
31 Correct 540 ms 42304 KB Output is correct
32 Correct 574 ms 42580 KB Output is correct