답안 #734019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734019 2023-05-01T13:43:39 Z benjaminkleyn 사탕 분배 (IOI21_candies) C++17
100 / 100
377 ms 31484 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma,bmi,bmi2")
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll M[1000000] = {0}, m[1000000] = {0}, lazy[1000000] = {0};

void push(int v)
{
    M[2 * v] += lazy[v];
    M[2 * v + 1] += lazy[v];

    m[2 * v] += lazy[v];
    m[2 * v + 1] += lazy[v];

    lazy[2 * v] += lazy[v];
    lazy[2 * v + 1] += lazy[v];
    lazy[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, ll dx)
{
    if (r < tl || tr < l)
        return;
    if (l <= tl && tr <= r)
    {
        M[v] += dx;
        m[v] += dx;
        lazy[v] += dx;
        return;
    }

    push(v);
    int tm = (tl + tr) / 2;
    update(2 * v, tl, tm, l, r, dx);
    update(2 * v + 1, tm + 1, tr, l, r, dx);
    M[v] = max(M[2 * v], M[2 * v + 1]);
    m[v] = min(m[2 * v], m[2 * v + 1]);
}

ll Find(int v, int tl, int tr, ll Mx, ll Mn, ll sum, int c)
{
    if (tl == tr)
    {
        if (Mx <= M[v])
            return sum - Mn;
        else
            return c - (Mx - sum);
    }

    push(v);
    int tm = (tl + tr) / 2;
    if (max(Mx, M[2 * v + 1]) - min(Mn, m[2 * v + 1]) <= c)
        return Find(2 * v, tl, tm, max(Mx, M[2 * v + 1]), min(Mn, m[2 * v + 1]), sum, c);
    return Find(2 * v + 1, tm + 1, tr, Mx, Mn, sum, c);
}

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) 
{
    int n = c.size(), q = v.size();
    vector<vector<pair<int,int>>> events(n+1);
    events[0].push_back({1000000000, -2});
    events[0].push_back({-1000000000, -1});
    for (int i = 0; i < q; i++)
    {
        events[l[i]].push_back({v[i], i});
        events[r[i]+1].push_back({-v[i], i});
    }
    ll sum = 0;
    vector<int> s(n);
    for (int i = 0; i < n; i++)
    {
        for (auto [val, time] : events[i])
        {
            sum += val;
            update(1, 0, q + 1, time + 2, q + 1, val);
        }
        s[i] = Find(1, 0, q + 1, sum, sum, sum, c[i]);
    }

    return s;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 355 ms 31472 KB Output is correct
2 Correct 356 ms 31484 KB Output is correct
3 Correct 367 ms 31412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 191 ms 21872 KB Output is correct
3 Correct 57 ms 7644 KB Output is correct
4 Correct 340 ms 31304 KB Output is correct
5 Correct 327 ms 31416 KB Output is correct
6 Correct 345 ms 31352 KB Output is correct
7 Correct 345 ms 31308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 92 ms 20644 KB Output is correct
4 Correct 76 ms 7456 KB Output is correct
5 Correct 175 ms 27484 KB Output is correct
6 Correct 174 ms 27476 KB Output is correct
7 Correct 180 ms 27480 KB Output is correct
8 Correct 167 ms 27540 KB Output is correct
9 Correct 167 ms 27468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 355 ms 31472 KB Output is correct
7 Correct 356 ms 31484 KB Output is correct
8 Correct 367 ms 31412 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 191 ms 21872 KB Output is correct
11 Correct 57 ms 7644 KB Output is correct
12 Correct 340 ms 31304 KB Output is correct
13 Correct 327 ms 31416 KB Output is correct
14 Correct 345 ms 31352 KB Output is correct
15 Correct 345 ms 31308 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 92 ms 20644 KB Output is correct
19 Correct 76 ms 7456 KB Output is correct
20 Correct 175 ms 27484 KB Output is correct
21 Correct 174 ms 27476 KB Output is correct
22 Correct 180 ms 27480 KB Output is correct
23 Correct 167 ms 27540 KB Output is correct
24 Correct 167 ms 27468 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 60 ms 7632 KB Output is correct
27 Correct 197 ms 21880 KB Output is correct
28 Correct 349 ms 31432 KB Output is correct
29 Correct 335 ms 31308 KB Output is correct
30 Correct 377 ms 31412 KB Output is correct
31 Correct 352 ms 31416 KB Output is correct
32 Correct 358 ms 31312 KB Output is correct