Submission #581229

# Submission time Handle Problem Language Result Execution time Memory
581229 2022-06-22T12:01:44 Z adrilen Distributing Candies (IOI21_candies) C++17
0 / 100
99 ms 9280 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);
    } 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)
{
    int n = c.size(), q = v.size();
    vector <int> s = positive(c, l, r, v);

    return s;
}

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:56:9: warning: unused variable 'n' [-Wunused-variable]
   56 |     int n = c.size(), q = v.size();
      |         ^
candies.cpp:56:23: warning: unused variable 'q' [-Wunused-variable]
   56 |     int n = c.size(), q = v.size();
      |                       ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 99 ms 9280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -