답안 #545320

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545320 2022-04-04T09:01:28 Z someone 사탕 분배 (IOI21_candies) C++17
컴파일 오류
0 ms 0 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));
        }
    }
    
    ll getVal(ll cap) {
        return 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<ll> 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(c[i]));
    }
    return ans;
}

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:71:12: error: could not convert 'ans' from 'vector<long long int>' to 'vector<int>'
   71 |     return ans;
      |            ^~~
      |            |
      |            vector<long long int>