#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define deb(x) cerr << #x << " = " << x << "\n";
#define deb2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << "\n";
#define deb3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << "\n";
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
using ordered_multiset = tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
ll binpow(ll a, ll b) {
//a = a % mod;
ll res = 1;
while ( b > 0) {
if (b&1) {
res = (a*res);//%mod;
}
a = (a*a);//%mod;
b >>= 1;
}
return res;
}
void solve(int tc) {
ll n, q;
cin >> n >> q;
vector<ll> v(n);
for (auto &x : v) cin >> x;
if (q<=1000) {
while (q--) {
ll ans = 0;
ll h;
cin >> h;
ll last = 0;
for (ll i = 0; i < n; ++i) {
if (v[i] > h) {
ll cur = i-last;
ans += ((cur+1)*cur)/2;
last = i+1;
}
}
ll cur = n-last;
ans += ((cur+1)*cur)/2;
cout << ans << '\n';
}
return;
}
while(q--) {
ll a;
cin >> a;
ll cur = upper_bound(all(v), a) - v.begin();
cout << ((cur+1)*cur)/2 << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) {
solve(i);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
3 ms |
364 KB |
Output is correct |
22 |
Correct |
4 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
4 ms |
364 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1388 KB |
Output is correct |
2 |
Correct |
10 ms |
1388 KB |
Output is correct |
3 |
Correct |
9 ms |
1388 KB |
Output is correct |
4 |
Correct |
9 ms |
1388 KB |
Output is correct |
5 |
Correct |
11 ms |
1388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
2536 KB |
Output is correct |
2 |
Correct |
38 ms |
2668 KB |
Output is correct |
3 |
Correct |
40 ms |
2660 KB |
Output is correct |
4 |
Correct |
38 ms |
2660 KB |
Output is correct |
5 |
Correct |
37 ms |
2540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
2540 KB |
Output is correct |
2 |
Correct |
42 ms |
2576 KB |
Output is correct |
3 |
Correct |
43 ms |
2532 KB |
Output is correct |
4 |
Correct |
42 ms |
2536 KB |
Output is correct |
5 |
Correct |
45 ms |
2660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
10 ms |
1388 KB |
Output is correct |
12 |
Correct |
10 ms |
1388 KB |
Output is correct |
13 |
Correct |
9 ms |
1388 KB |
Output is correct |
14 |
Correct |
9 ms |
1388 KB |
Output is correct |
15 |
Correct |
11 ms |
1388 KB |
Output is correct |
16 |
Correct |
9 ms |
1644 KB |
Output is correct |
17 |
Correct |
11 ms |
1772 KB |
Output is correct |
18 |
Correct |
10 ms |
1772 KB |
Output is correct |
19 |
Correct |
9 ms |
1644 KB |
Output is correct |
20 |
Correct |
10 ms |
1772 KB |
Output is correct |
21 |
Correct |
11 ms |
1644 KB |
Output is correct |
22 |
Correct |
10 ms |
1644 KB |
Output is correct |
23 |
Correct |
10 ms |
1772 KB |
Output is correct |
24 |
Correct |
10 ms |
1644 KB |
Output is correct |
25 |
Correct |
10 ms |
1644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
3 ms |
364 KB |
Output is correct |
22 |
Correct |
4 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
4 ms |
364 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
10 ms |
1388 KB |
Output is correct |
27 |
Correct |
10 ms |
1388 KB |
Output is correct |
28 |
Correct |
9 ms |
1388 KB |
Output is correct |
29 |
Correct |
9 ms |
1388 KB |
Output is correct |
30 |
Correct |
11 ms |
1388 KB |
Output is correct |
31 |
Correct |
38 ms |
2536 KB |
Output is correct |
32 |
Correct |
38 ms |
2668 KB |
Output is correct |
33 |
Correct |
40 ms |
2660 KB |
Output is correct |
34 |
Correct |
38 ms |
2660 KB |
Output is correct |
35 |
Correct |
37 ms |
2540 KB |
Output is correct |
36 |
Correct |
42 ms |
2540 KB |
Output is correct |
37 |
Correct |
42 ms |
2576 KB |
Output is correct |
38 |
Correct |
43 ms |
2532 KB |
Output is correct |
39 |
Correct |
42 ms |
2536 KB |
Output is correct |
40 |
Correct |
45 ms |
2660 KB |
Output is correct |
41 |
Correct |
9 ms |
1644 KB |
Output is correct |
42 |
Correct |
11 ms |
1772 KB |
Output is correct |
43 |
Correct |
10 ms |
1772 KB |
Output is correct |
44 |
Correct |
9 ms |
1644 KB |
Output is correct |
45 |
Correct |
10 ms |
1772 KB |
Output is correct |
46 |
Correct |
11 ms |
1644 KB |
Output is correct |
47 |
Correct |
10 ms |
1644 KB |
Output is correct |
48 |
Correct |
10 ms |
1772 KB |
Output is correct |
49 |
Correct |
10 ms |
1644 KB |
Output is correct |
50 |
Correct |
10 ms |
1644 KB |
Output is correct |
51 |
Incorrect |
33 ms |
3300 KB |
Output isn't correct |
52 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
3 ms |
364 KB |
Output is correct |
22 |
Correct |
4 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
4 ms |
364 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
10 ms |
1388 KB |
Output is correct |
27 |
Correct |
10 ms |
1388 KB |
Output is correct |
28 |
Correct |
9 ms |
1388 KB |
Output is correct |
29 |
Correct |
9 ms |
1388 KB |
Output is correct |
30 |
Correct |
11 ms |
1388 KB |
Output is correct |
31 |
Correct |
38 ms |
2536 KB |
Output is correct |
32 |
Correct |
38 ms |
2668 KB |
Output is correct |
33 |
Correct |
40 ms |
2660 KB |
Output is correct |
34 |
Correct |
38 ms |
2660 KB |
Output is correct |
35 |
Correct |
37 ms |
2540 KB |
Output is correct |
36 |
Correct |
42 ms |
2540 KB |
Output is correct |
37 |
Correct |
42 ms |
2576 KB |
Output is correct |
38 |
Correct |
43 ms |
2532 KB |
Output is correct |
39 |
Correct |
42 ms |
2536 KB |
Output is correct |
40 |
Correct |
45 ms |
2660 KB |
Output is correct |
41 |
Correct |
9 ms |
1644 KB |
Output is correct |
42 |
Correct |
11 ms |
1772 KB |
Output is correct |
43 |
Correct |
10 ms |
1772 KB |
Output is correct |
44 |
Correct |
9 ms |
1644 KB |
Output is correct |
45 |
Correct |
10 ms |
1772 KB |
Output is correct |
46 |
Correct |
11 ms |
1644 KB |
Output is correct |
47 |
Correct |
10 ms |
1644 KB |
Output is correct |
48 |
Correct |
10 ms |
1772 KB |
Output is correct |
49 |
Correct |
10 ms |
1644 KB |
Output is correct |
50 |
Correct |
10 ms |
1644 KB |
Output is correct |
51 |
Incorrect |
33 ms |
3300 KB |
Output isn't correct |
52 |
Halted |
0 ms |
0 KB |
- |