답안 #545322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545322 2022-04-04T09:03:40 Z someone 사탕 분배 (IOI21_candies) C++17
27 / 100
313 ms 48704 KB
#include "candies.h"
 
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

struct Node {
    int deb, fin;
    ll a, b, x;
};

const int M = 1 << 18, N = M << 1;

struct Segtree {
    int cap;
    Node node[N];
    
    void init(int c) {
        cap = c;
        for(int i = 0; i < M; i++)
            node[i + M].deb = i,
            node[i + M].fin = i+1;
        for(int i = M-1; i > 0; i--)
            node[i].deb = node[i*2].deb,
            node[i].fin = node[i*2+1].fin;
        for(int i = M; i < N; i++)
            node[i].a = node[i].x = 0;
        for(int i = 0; i < N; i++)
            node[i].b = cap;
    }
    
    void update(int i, ll x) {
        i += M;
        node[i].a = -x, node[i].b = cap - x, node[i].x = x;
        while(i > 1) {
            i >>= 1;
            node[i].x = node[i*2].x + node[i*2+1].x;
            ll a2 = node[i*2+1].a - node[i*2].x,
               b2 = node[i*2+1].b - node[i*2].x;
            node[i].a = max(a2, min(b2, node[i*2].a));
            node[i].b = max(a2, min(b2, node[i*2].b));
        }
    }
    
    int getVal() {
        return (int)(min(max(0ll, node[1].a), node[1].b) + node[1].x);
    }
};

Segtree tree;
vector<int> id[N];

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    tree.init(c[0]);
    int n = (int)c.size(), q = (int)l.size();
    for(int i = 0; i < q; i++) {
        id[l[i]].push_back(i);
        id[r[i]+1].push_back(-i-1);
    }
    vector<int> ans;
    for(int i = 0; i < n; i++) {
        for(int j : id[i]) {
            if(j >= 0) {
                tree.update(j, v[j]);
            } else {
                tree.update(-j-1, 0);
            }
        }
        ans.push_back(tree.getVal());
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 29012 KB Output is correct
2 Incorrect 16 ms 28928 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 273 ms 41996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 29012 KB Output is correct
2 Correct 167 ms 38912 KB Output is correct
3 Correct 71 ms 35004 KB Output is correct
4 Correct 289 ms 47872 KB Output is correct
5 Correct 279 ms 48320 KB Output is correct
6 Correct 313 ms 48704 KB Output is correct
7 Correct 282 ms 48048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 29012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 29012 KB Output is correct
2 Incorrect 16 ms 28928 KB Output isn't correct
3 Halted 0 ms 0 KB -