제출 #1026985

#제출 시각아이디문제언어결과실행 시간메모리
1026985ricardsjansonsPilot (NOI19_pilot)C++14
89 / 100
1020 ms42928 KiB
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

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

    vector<pair<int, int>> h(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> h[i].first;
        h[i].second = i;
    }
    sort(h.begin(), h.end());
    h.push_back({1e6 + 1, n + 1});

    vector<pair<int, int>> y(q);
    for (int i = 0; i < q; i++) {
        cin >> y[i].first;
        y[i].second = i;
    }
    sort(y.begin(), y.end());

    vector<long long> l(n + 2);
    vector<long long> r(n + 2);
    vector<long long> res(q);
    long long flights = 0;
    int j = 0;
    for (int i = 1; i <= n; i++) {
        while (j < q && h[i].first > y[j].first) {
            res[y[j].second] = flights;
            j++;
        }

        int index = h[i].second;

        l[index] = l[index - 1] + 1;
        r[index] = r[index + 1] + 1;

        if (r[index] > 1) {
            l[index + r[index] - 1] += l[index];
        }
        if (l[index] > 1) {
            r[index - l[index] + 1] += r[index];
        }

        flights += l[index] * r[index];
    }
    while (j < q) {
        res[y[j].second] = flights;
        j++;
    }

    for (long long f : res) {
        cout << f << endl;
    }
}
#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...