답안 #1011187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011187 2024-06-30T04:32:38 Z 김은성(#10855) 사탕 분배 (IOI21_candies) C++17
8 / 100
158 ms 21708 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll tree[1<<19], lazy[1<<19], ans[200009];
void update(int v, int l, int r, int s, int e, int val){
    if(lazy[v]){
        tree[v] += lazy[v];
        if(l != r){
            lazy[2*v] += lazy[v];
            lazy[2*v+1] += lazy[v];
        }
        lazy[v] = 0;
    }
    if(e<l || r<s)
        return;
    if(s<=l && r<=e){
        tree[v] += val;
        if(l != r){
            lazy[2*v] += val;
            lazy[2*v+1] += val;
        }
    }
    else{
        int mid = (l+r)/2;
        update(2*v, l, mid,s, e, val);
        update(2*v+1, mid+1, r, s, e, val);
        tree[v] = tree[2*v] + tree[2*v+1];
    }
}
void solve(int v, int l, int r){
    if(lazy[v]){
        tree[v] += lazy[v];
        if(l != r){
            lazy[2*v] += lazy[v];
            lazy[2*v+1] += lazy[v];
        }
        lazy[v] = 0;
    }
    if(l==r){
        ans[l] = tree[v];
        return;
    }
    int mid = (l+r)/2;
    solve(2*v, l, mid);
    solve(2*v+1, mid+1, r);
}

std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    int n = c.size(), q = l.size(), i, j;
    for(i=0; i<q; i++){
        update(1, 0, n-1, l[i], r[i], v[i]);
    }
    solve(1, 0, n-1);
    vector<int> ret;
    for(i=0; i<n; i++)
        ret.push_back(min(ans[i], (ll)c[i]));
    return ret;
}

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:51:40: warning: unused variable 'j' [-Wunused-variable]
   51 |     int n = c.size(), q = l.size(), i, j;
      |                                        ^
# 결과 실행 시간 메모리 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 Correct 152 ms 21708 KB Output is correct
2 Correct 132 ms 21704 KB Output is correct
3 Correct 158 ms 21508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 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 -