이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
* 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];
SegmentTree s;
s.build(0,0,n-1,a);
while(q--) {
int h;
int ans = 0;
cin >> h;
for(int i = 1; i <= n; ++i) {
for(int j = 0; j < n - i + 1; ++j) {
if(s.query(0,0,n-1,j,j+i-1) <= h) {
ans++;
}
}
}
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... |