제출 #1187445

#제출 시각아이디문제언어결과실행 시간메모리
1187445oguzhan09Pilot (NOI19_pilot)C++20
55 / 100
1095 ms7748 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long n, m; cin >> n >> m; vector<long long> l(n); for (int i = 0; i < n; i++) cin >> l[i]; vector<pair<long long, int>> tests(m); for (int i = 0; i < m; i++) { long long a; cin >> a; tests[i] = {a, i}; } sort(tests.begin(), tests.end()); // Testleri sırala vector<long long> answers(m); set<int> blocked_positions; for (int i = 0; i < m; i++) { long long T = tests[i].first; long long total = 0; long long count = 0; if (i == 0) { for (int j = 0; j < n; j++) { if (l[j] <= T) { count++; } else { total += count * (count + 1) / 2; blocked_positions.insert(j); count = 0; } } total += count * (count + 1) / 2; } else { // Yeni T ile birlikte daha fazla pozisyon aktif hale gelir for (auto it = blocked_positions.begin(); it != blocked_positions.end(); ) { if (l[*it] <= T) { it = blocked_positions.erase(it); // aktif oldu, artık engelli değil } else { ++it; } } // Şimdi tüm engelli pozisyonlara göre segmentleri bulup say int last = -1; for (int pos : blocked_positions) { long long len = pos - last - 1; if (len > 0) total += len * (len + 1) / 2; last = pos; } // Son segment long long len = n - last - 1; if (len > 0) total += len * (len + 1) / 2; } answers[tests[i].second] = total; } for (auto x : answers) cout << x << '\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...