답안 #855446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855446 2023-10-01T08:57:33 Z nonono 사탕 분배 (IOI21_candies) C++17
0 / 100
306 ms 31808 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 ++) {
        a[i] = get(1, 1, n, i).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], r[i], 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:75:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for(int i = 0; i < a.size(); i ++) {
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 306 ms 31808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 147 ms 17660 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -