답안 #581868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581868 2022-06-23T07:33:56 Z adrilen 사탕 분배 (IOI21_candies) C++17
0 / 100
99 ms 7628 KB
#include<bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
const int maxn = 2e5;
const int maxc = 1e9;

const int siz = (1 << 3);

int segment_tree[siz * 2 + 1] = { 0 };

void update(int pos, pii wan, pii sear, int val)
{
    if (wan.first > sear.second || sear.first > wan.second) return ;

    if (wan.first <= sear.first && sear.second <= wan.second) {
        segment_tree[pos] += val;
        return ;
    }

    int mid = (sear.first + sear.second) / 2;
    update(pos * 2, wan, pii(sear.first, mid), val);
    update(pos * 2 + 1, wan, pii(mid + 1, sear.second), val);
}

void calc(vector <int> &out, int pos, vector <int> &maxval, int val) 
{   
    if (pos >= siz) {
        out[pos - siz] = min(maxval[pos - siz], val + segment_tree[pos]);
    } else {
        val = min(maxc, val + segment_tree[pos]);
        calc(out, pos * 2, maxval, val);
        calc(out, pos * 2 + 1, maxval, val);
    }
}


vector <int> positive(vector <int> &c, vector<int> &l, vector<int> &r, vector<int> &v) 
{
    int n = c.size(), q = v.size();

    for (int i = 0; i < q; i++) {
        update(1, pii(l[i], r[i]), pii(0, siz - 1), v[i]);
    }

    vector <int> out(siz);
    calc(out, 1, c, 0);
    out.resize(n);

    return out;
}


vector<int> distribute_candies(vector <int> c, vector<int> l, vector<int> r, vector<int> v)
{
    vector <int> s = positive(c, l, r, v);

    return s;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 99 ms 7628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -