제출 #1026984

#제출 시각아이디문제언어결과실행 시간메모리
1026984ricardsjansonsPilot (NOI19_pilot)C++14
89 / 100
1062 ms70204 KiB
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { long long n, q; cin >> n >> q; vector<pair<long long, long long>> h(n + 1); for (long long 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<long long, long long>> y(q); for (long long 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; long long j = 0; for (long long i = 1; i <= n; i++) { while (j < q && h[i].first > y[j].first) { res[y[j].second] = flights; j++; } long long 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...