Submission #581872

# Submission time Handle Problem Language Result Execution time Memory
581872 2022-06-23T07:34:46 Z adrilen Distributing Candies (IOI21_candies) C++17
0 / 100
173 ms 9188 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 << 18);

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;
}
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 2516 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 173 ms 9188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 2516 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 2548 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 2516 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -