Submission #1028356

#TimeUsernameProblemLanguageResultExecution timeMemory
1028356SweePilot (NOI19_pilot)C++14
89 / 100
1082 ms33024 KiB
#include <iostream>
#include <vector>

using namespace std;

struct mountain {
    int height;
    int index;
};

//vector<long long> count(vector<int> h, vector<int> y) { // i would have written like that, but ive had no idea, how to make it faster
void count(vector<int> h, int q) {
    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 Y;
    for (int i = 0; i < q; i++) { // filling up queries
        cin >> Y;
        if (Y >= allPlanes.size()) {
            cout << allPlanes.back() << endl;
        }else {
            cout << allPlanes[Y] << endl;
        }
    }

    return;
}

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

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

    count(h, q);

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

    for (long long r : count(h, y)) {
        cout << r << endl;
    }*/

    return 0;
}

Compilation message (stderr)

pilot.cpp: In function 'void count(std::vector<int>, int)':
pilot.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i < h.size(); i++) {
      |                     ~~^~~~~~~~~~
pilot.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i = 2; i < allPlanes.size(); i++) { // partial sum of possible flights
      |                     ~~^~~~~~~~~~~~~~~~~~
pilot.cpp:47:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         if (Y >= allPlanes.size()) {
      |             ~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...