답안 #1028342

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1028342 2024-07-19T16:56:25 Z Swee Pilot (NOI19_pilot) C++14
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>

using namespace std;

struct mountain {
    int height;
    int index;
};

vector<long long> count(vector<int> h, vector<int> y) {
    h.push_back(1000001); // last border

    vector<mountain> border;
    border.push_back({1000002, -1}); // blocker 

    vector<long long> allPlanes(1000001);
    for (int i = 0; i < h.size(); i++) {
        for (;h[i] >= border.back().height; border.pop_back()) { // remove last border
            long long a = (i - border.back().index), b = (border.back().index - border[border.size() - 2].index);
            allPlanes[border.back().height] += a * b; // add possible flights to last border mountain height velocity plane
            // starting before or with last border * ending after or with last border
        }
        border.push_back({h[i], i}); // add border
    }

    for (int i = 2; i < allPlanes.size(); i++) { // partial sum of possible flights
        allPlanes[i] += allPlanes[i - 1];
    }

    vector<long long> result;

    for (int Y : y) { // filling up queries
        if (Y >= allPlanes.size()) {
            result.push_back(allPlanes.back());
        }else {
            result.push_back(allPlanes[Y]);
        }
    }

    return result;
}

int main() {
    int n, q;
    cin >> n >> q;

    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    vector<int> y(q);
    for (int i = 0; i < q; i++) {
        cin >> y[i];
    }

    vector<int> result = count(h, y);

    for (int r : result) {
        cout << r << endl;
    }

    return 0;
}

Compilation message

pilot.cpp: In function 'std::vector<long long int> count(std::vector<int>, std::vector<int>)':
pilot.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 0; i < h.size(); i++) {
      |                     ~~^~~~~~~~~~
pilot.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i = 2; i < allPlanes.size(); i++) { // partial sum of possible flights
      |                     ~~^~~~~~~~~~~~~~~~~~
pilot.cpp:34:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         if (Y >= allPlanes.size()) {
      |             ~~^~~~~~~~~~~~~~~~~~~
pilot.cpp: In function 'int main()':
pilot.cpp:58:31: error: conversion from 'vector<long long int>' to non-scalar type 'vector<int>' requested
   58 |     vector<int> result = count(h, y);
      |                          ~~~~~^~~~~~