Submission #344420

#TimeUsernameProblemLanguageResultExecution timeMemory
344420NursikPilot (NOI19_pilot)C++14
40 / 100
54 ms7300 KiB
#include <bits/stdc++.h> #define f first #define s second #define ll long long #define pb push_back #define all(v) v.begin(),v.end() #define ld long double using namespace std; void data() { #ifdef NURS freopen("main.in", "r", stdin); freopen("main.out", "w", stdout); #endif } void win() { ios_base::sync_with_stdio(0), cin.tie(0),cout.tie(0); } const ld eps = 1e-6; const int N = 1e6 + 500; const int mod = 1e9 + 7; const ll hh = 100010683; const ll hh2 = 150005819; int n, q; int a[N], pref[N], pref2[N]; void rec(int l = 1, int r = n) { if (l == r) { pref2[a[l]]++; return; } int mid = (l + r) / 2; rec(l, mid); rec(mid + 1, r); for (int i = mid; i >= l; i--) { pref[i] = max(pref[i + 1], a[i]); } int cur = 0, uk = mid + 1; for (int i = mid + 1; i <= r; i++) { cur = max(cur, a[i]); while (cur >= pref[uk - 1] && uk - 1 >= l) { uk--; } pref2[cur] += max(mid - uk + 1, 0); } for (int i = mid; i >= l; i--) { pref[i] = 0; } cur = 0; for (int i = mid + 1; i <= r; i++) { pref[i] = max(pref[i - 1], a[i]); } uk = mid; for (int i = mid; i >= l; i--) { cur = max(cur, a[i]); while (cur > pref[uk + 1] && uk + 1 <= r) { uk++; } pref2[cur] += max(uk - mid , 0); } for (int i = mid + 1; i <= r; i++) { pref[i] = 0; } } int main() { data(); win(); cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> a[i]; } rec(); pref2[0] = 0; for (int i = 1; i <= 1e6; i++) { pref2[i] += pref2[i - 1]; } for (int i = 1; i <= q; i++) { int x; cin >> x; cout << pref2[x] << '\n'; } }
#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...