This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "
#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb emplace_back
struct UFDS {
vi link, sz;
int n;
UFDS(int N) {
init(N);
}
void init(int N) {
n = N;
link = vi(n);
iota(all(link), 0);
sz = vi(n, 1);
}
ll find(ll x) {
return (link[x] == x ? x : link[x] = find(link[x]));
}
void unite(ll a, ll b) {
a = find(a);
b = find(b);
if(a == b) return;
if(sz[a] < sz[b]) swap(a, b);
sz[a] += sz[b];
link[b] = a;
}
bool same(ll a, ll b){
return (find(a) == find(b));
}
};
void solve()
{
ll n, q;
cin >> n >> q;
ll a[n];
FOR(i, 0, n) {
cin >> a[i];
}
while(q--) {
ll x;
cin >> x;
ll ans = 0;
ll curr = 0;
FOR(i, 0, n) {
if(a[i] > x)
curr = 0;
else
++curr;
ans += curr;
}
cout << ans << nl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
// cin >> t;
while (t--)
{
solve();
}
}
# | 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... |