답안 #444388

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444388 2021-07-14T00:04:50 Z JvThunder 사탕 분배 (IOI21_candies) C++17
100 / 100
1455 ms 219280 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int MAXN = 1000005;
const int MAXQ = 1000005;
const ll INF = (ll)(1e18);

struct SegmentTree 
{
    int n;
    ll vmin[(MAXN + MAXQ) * 4] = {0};
    ll vmax[(MAXN + MAXQ) * 4] = {0};
    ll lazy[(MAXN + MAXQ) * 4] = {0};

    void init(int _n) { n = _n; }

    void lazy_update(int node, int from, int to)
    {
        vmin[node] += lazy[node]; vmax[node] += lazy[node];
        if (from < to) 
        {
            lazy[2*node] += lazy[node];
            lazy[2*node+1] += lazy[node];
        }
        lazy[node] = 0;
    }

    void update(int node, int from, int to, int L, int R, int add)
    {
        lazy_update(node, from, to);
        if (from > R || to < L) return;
        if (L <= from && to <= R) {
            lazy[node] += add;
            lazy_update(node, from, to);
            return;
        }
        int mid = (from + to) / 2;
        update(node * 2, from, mid, L, R, add);
        update(node * 2 + 1, mid + 1, to, L, R, add);
        vmin[node] = min(vmin[node * 2], vmin[node * 2 + 1]);
        vmax[node] = max(vmax[node * 2], vmax[node * 2 + 1]);
    }

    ll get(int node, int from, int to, int lowerbound) 
    {
        lazy_update(node, from, to);
        if (from == to) return vmin[node];
        int mid = (from + to) / 2;
        if (vmax[node * 2 + 1] + lazy[node * 2 + 1] >= lowerbound)
            return get(node * 2 + 1, mid + 1, to, lowerbound);
        return min( vmin[node * 2 + 1] + lazy[node * 2 + 1], get(node * 2, from, mid, lowerbound) );
    }

    void add_range(int L, int R, int add) 
    {
        update(1, 0, n - 1, L, R, add);
    }

    ll min_suffix(int lowerbound) 
    {
        if (vmax[1] < lowerbound) return -INF;
        return min(0LL, get(1, 0, n - 1, lowerbound));
    }
} T;

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> A(n);
    
    vector<vector<int>> begin_at(n,vector<int>()), end_at(n,vector<int>());
    for(int i=0;i<q;i++) 
    {
        begin_at[L[i]].push_back(i);
        end_at[R[i]].push_back(i);
    }

    T.init(q+1);
    vector<int> final_A(n);
    for(int i=0;i<n;i++)
    {
        if (i>0) 
        {
            T.add_range(0,0,-A[i-1]);
            for(int j:end_at[i-1]) T.add_range(0,1+j,-V[j]);
        }
        T.add_range(0,0,A[i]);
        for(int j : begin_at[i]) T.add_range(0,1+j,V[j]);

        int low = 1, high = C[i] + 1;
        while (low <= high) 
        {
            int mid = (low + high) / 2;
            ll smin = T.min_suffix(mid);
            if (-smin + mid > C[i]) high = mid - 1;
            else low = mid + 1;
        }
        final_A[i] = high;
    }

    return final_A;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 188100 KB Output is correct
2 Correct 88 ms 188052 KB Output is correct
3 Correct 79 ms 188188 KB Output is correct
4 Correct 80 ms 188228 KB Output is correct
5 Correct 83 ms 188356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1126 ms 217424 KB Output is correct
2 Correct 1208 ms 216648 KB Output is correct
3 Correct 1220 ms 216484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 188140 KB Output is correct
2 Correct 411 ms 198948 KB Output is correct
3 Correct 582 ms 202948 KB Output is correct
4 Correct 1455 ms 218612 KB Output is correct
5 Correct 1332 ms 218844 KB Output is correct
6 Correct 1451 ms 219280 KB Output is correct
7 Correct 802 ms 218672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 188148 KB Output is correct
2 Correct 79 ms 188092 KB Output is correct
3 Correct 221 ms 197432 KB Output is correct
4 Correct 332 ms 201964 KB Output is correct
5 Correct 653 ms 210696 KB Output is correct
6 Correct 683 ms 211360 KB Output is correct
7 Correct 815 ms 211952 KB Output is correct
8 Correct 617 ms 210588 KB Output is correct
9 Correct 1212 ms 212068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 188100 KB Output is correct
2 Correct 88 ms 188052 KB Output is correct
3 Correct 79 ms 188188 KB Output is correct
4 Correct 80 ms 188228 KB Output is correct
5 Correct 83 ms 188356 KB Output is correct
6 Correct 1126 ms 217424 KB Output is correct
7 Correct 1208 ms 216648 KB Output is correct
8 Correct 1220 ms 216484 KB Output is correct
9 Correct 79 ms 188140 KB Output is correct
10 Correct 411 ms 198948 KB Output is correct
11 Correct 582 ms 202948 KB Output is correct
12 Correct 1455 ms 218612 KB Output is correct
13 Correct 1332 ms 218844 KB Output is correct
14 Correct 1451 ms 219280 KB Output is correct
15 Correct 802 ms 218672 KB Output is correct
16 Correct 77 ms 188148 KB Output is correct
17 Correct 79 ms 188092 KB Output is correct
18 Correct 221 ms 197432 KB Output is correct
19 Correct 332 ms 201964 KB Output is correct
20 Correct 653 ms 210696 KB Output is correct
21 Correct 683 ms 211360 KB Output is correct
22 Correct 815 ms 211952 KB Output is correct
23 Correct 617 ms 210588 KB Output is correct
24 Correct 1212 ms 212068 KB Output is correct
25 Correct 78 ms 188112 KB Output is correct
26 Correct 310 ms 201976 KB Output is correct
27 Correct 405 ms 198468 KB Output is correct
28 Correct 960 ms 217128 KB Output is correct
29 Correct 1022 ms 217516 KB Output is correct
30 Correct 1029 ms 217580 KB Output is correct
31 Correct 1076 ms 217900 KB Output is correct
32 Correct 1097 ms 218116 KB Output is correct