This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
* author: robosapien
* created: 2020-11-11 21:55:39
*/
#include<bits/stdc++.h>
using namespace std;
#define bs ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pii pair<int,int>
const int N = 100100;
struct SegmentTree{
ll seg[4*N];
void build(int node, int l, int r, int a[]){
if(l == r){
seg[node] = a[l];
return;
}
int m = (l + r) >> 1;
build(2*node + 1, l, m, a);
build(2*node + 2, m+1, r, a);
seg[node] = max( seg[2*node + 1], seg[2*node + 2] );
}
void update(int node, int i, int val, int l, int r){
if(l == r){
seg[node] = val;
return;
}
int m = (l + r) >> 1;
if(i <= m)
update(2*node + 1, i, val, l, m);
else update(2*node + 2, i, val, m+1, r);
seg[node] = max(seg[2*node + 1], seg[2*node + 2]);
}
int query(int node, int sl, int sr, int ql, int qr){
if(sl > qr or sr < ql)
return 0;
if(sl >= ql and sr <= qr)
return seg[node];
int m = (sl + sr) >> 1;
int l = query(2*node + 1, sl, m, ql, qr);
int r = query(2*node + 2, m+1, sr, ql, qr);
return max(l, r);
}
};
void solve(){
int n, q;
cin >> n >> q;
int a[n];
for(int i = 0; i < n; ++i) {
cin >> a[i];
}
// s.build(0,0,n-1,a);
while(q--) {
int h;
cin >> h;
ll ans = 0, cur = 0;
for(int i = 0; i < n; ++i) {
if(a[i] <= h)
cur++;
else {
ans += cur * (cur + 1) / 2;
cur = 0;
}
}
ans += cur * (cur + 1) / 2;
cout << ans << '\n';
}
}
int main()
{
bs;
int t = 1;
// cin >> t;
while(t--){
solve();
}
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |