답안 #535743

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535743 2022-03-11T05:37:28 Z MurotY 사탕 분배 (IOI21_candies) C++17
0 / 100
174 ms 11452 KB
#include "candies.h"
#include <bits/stdc++.h>
#include <vector>
#define ll long long
using namespace std;
vector <ll> tree;
int sz=1, ans;
bool ok=0;
void init(ll n){
    while (sz < n) sz*=2;
    tree.assign(2*sz, 0);
    return ;
}

void add(ll l, ll r, ll v, ll x, ll lx, ll rx){
//    cout << l <<" " << r <<"\n";
    if (lx >= r || rx <= l) return ;
    if (l <= lx && rx <= r) {
        tree[x]+=v;
        return ;
    }
    ll m=(lx+rx)/2;
    add(l, r, v, 2*x+1, lx, m);
    add(l, r, v, 2*x+2, m, rx);
    return ;
}
void help(ll i, ll x, ll lx, ll rx, ll res=0){

    if (rx-lx == 1){
        if (!ok) ans=res+tree[x];
        ok=1;
        return;
    }
    ll m=(lx+rx)/2;
    ll x1=x;
    if (i < m) help(i, 2*x+1, lx, m, res+tree[x1]);
    else help(i, 2*x+2, m, rx, res+tree[x1]);
    return ;
}
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();
    init(n);
    vector<int> s(n);
    s=c;
    for (int i=0;i<l.size();i++){
        add(l[i], r[i]+1, v[i], 0, 0, sz);
    }
    for (int i=0;i<n;i++){
        ok=0;
        help(i, 0, 0, sz);
    //    cout << ans <<" ";
        s[i]=min(c[i], ans);
    }
    return s;
}

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:46:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i=0;i<l.size();i++){
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 174 ms 11452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -