제출 #765266

#제출 시각아이디문제언어결과실행 시간메모리
765266CookiePilot (NOI19_pilot)C++17
89 / 100
1064 ms92448 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; ifstream fin("VNOICUP.INP"); ofstream fout("VNOICUP.OUT"); #define sz(a) (int)a.size() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> const ld PI = 3.14159265359; const ll mod = 1e9 + 7; const int mxn = 1e6, mxm = 1e5; int n, q; int h[mxn + 1], y[mxn + 1]; ll a[mxn + 1], res[mxn + 1]; set<int>bad; ll ans = 0; ll sm(ll x){ return(x * (x + 1) / 2); } void rem(int id){ auto low = bad.lower_bound(id); --low; auto high = bad.upper_bound(id); ans -= sm(*high - *low - 1); ans += sm(id - *low - 1); ans += sm(*high - id - 1); bad.insert(id); } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q; ans = 1LL * n * (n + 1) / 2; vt<pii>comp; for(int i = 1; i <= n; i++){ cin >> a[i]; comp.pb(make_pair(a[i], i)); } bad.insert(0); bad.insert(n + 1); vt<pii>queries; forr(i, 0, q){ int y; cin >> y; queries.pb({y, i}); } sort(queries.rbegin(), queries.rend()); sort(comp.rbegin(), comp.rend()); int r = 0; for(auto [y, id]: queries){ while(r < sz(comp) && comp[r].fi > y){ rem(comp[r].se); r++; } res[id] = ans; } forr(i, 0, q){ cout << res[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...