Submission #855455

# Submission time Handle Problem Language Result Execution time Memory
855455 2023-10-01T09:09:36 Z nonono Distributing Candies (IOI21_candies) C++17
27 / 100
331 ms 33748 KB
//#include "candies.h"

#include <bits/stdc++.h>
using namespace std;

struct Query {
    int l, r, v;
};

struct F {
    int l, r, x;
};

vector<F> ST;
int C;

F composition(F f, F g) { // compute x(y())
    return {
        min(f.r, max(f.l, g.l + f.x)),
        min(f.r, max(f.l, g.r + f.x)),
        f.x + g.x
    };
}

void build(int id, int l, int r) {
    ST[id] = {0, C, 0};
    if(l == r) return ;
    
    int mid = (l + r) / 2;
    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);
}

void down(int id) {
    F x = ST[id];
    
    ST[id * 2] = composition(x, ST[id * 2]);
    ST[id * 2 + 1] = composition(x, ST[id * 2 + 1]);
    
    ST[id] = {0, C, 0};
}

void update(int id, int l, int r, int u, int v, F x) {
    if(r < u || v < l) return ;
    
    if(u <= l && r <= v) {
        ST[id] = composition(x, ST[id]);
        return ;
    }
    
    down(id);
    int mid = (l + r) / 2;
    update(id * 2, l, mid, u, v, x);
    update(id * 2 + 1, mid + 1, r, u, v, x);
}

F get(int id, int l, int r, int x) {
    if(l == r) {
        return ST[id];
    }
    
    int mid = (l + r) / 2;
    if(x <= mid) 
        return composition(ST[id * 2], get(id * 2, l, mid, x));
    else 
        return composition(ST[id * 2 + 1], get(id * 2 + 1, mid + 1, r, x));
}

vector<int> sub3(int n, int q, vector<int> c, vector<Query> queries) {
    ST.resize(4 * n + 4);
    C = c[0];
    for(auto [l, r, v] : queries) {
        update(1, 1, n, l, r, {0, C, v});
    }
    vector<int> a(n);
    for(int i = 0; i < a.size(); i ++) {
        F f = composition(ST[1], get(1, 1, n, i + 1));
        a[i] = f.l;
    }
    return a;
}

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<Query> queries(q);
    for(int i = 0; i < q; i ++) {
        queries.push_back({l[i] + 1, r[i] + 1, v[i]});
    }
    return sub3(n, q, c, queries);
}

Compilation message

candies.cpp: In function 'std::vector<int> sub3(int, int, std::vector<int>, std::vector<Query>)':
candies.cpp:76:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for(int i = 0; i < a.size(); i ++) {
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 300 ms 27060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 143 ms 14648 KB Output is correct
3 Correct 90 ms 15740 KB Output is correct
4 Correct 331 ms 32960 KB Output is correct
5 Correct 317 ms 33356 KB Output is correct
6 Correct 313 ms 33748 KB Output is correct
7 Correct 323 ms 33088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -