Submission #225113

#TimeUsernameProblemLanguageResultExecution timeMemory
225113tictaccatPilot (NOI19_pilot)C++14
3 / 100
117 ms5608 KiB
#include <bits/stdc++.h> using namespace std; typedef long long LL; int N,Q; int H[2000000], l[2000000], r[2000000], ans[2000000]; vector<pair<int,int>> QU, M; LL pairs(LL n) { return n*(n-1)/2 + n; } int main() { cin >> N >> Q; for (int i = 0; i < N; i++) { cin >> H[i]; M.emplace_back(H[i],i); l[i] = i+1; r[i] = i-1; } for (int i = 0; i < Q; i++) { int y; cin >> y; QU.emplace_back(y,i); } sort(QU.begin(), QU.end()); sort(M.begin(), M.end()); int k = 0; LL cnt = 0; for (auto m: M) { int h,i; tie(h,i) = m; while (k < Q && QU[k].first < h) { ans[k] = cnt; k++; } cnt += pairs(r[i]-l[i]-1); cnt -= pairs(r[i]-i-1); cnt -= pairs(i-l[i]-1); if (l[i] != -1) { l[r[i]] = l[i]; } if (r[i] != N) { r[l[i]] = r[i]; } } while (k < Q) { ans[k] = cnt; k++; } for (int i = 0; i < Q; i++) cout << ans[i] << "\n"; return 0; }
#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...