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;
#define LIFESUCKS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define ar array
#include<cstdio>
#define vt vector
#include<fstream>
ifstream fin("closing.in");
ofstream fout("closing.out");
#include<fstream>
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define fi first
#define se second
#define vt vector
using namespace std;
int main()
{
int n, q; cin >> n >> q;
ll a[n];
for(int i = 0; i < n; i++)cin >> a[i];
if(n <= 1000 || q == 1){
for(int i = 0; i < q; i++){
ll x; cin >> x;
ll res = 0;
ll cr = 0;
for(int j = 0; j < n; j++){
if(a[j] <= x)cr++;
else{
res += (cr * (cr + 1)) / 2; cr = 0;
}
}
res += (cr * (cr + 1)) / 2;
cout << res << "\n";
}
}else{
for(int i =0; i < q; i++){
int x; cin >> x;
ll id = upper_bound(a, a + n, x) - a;
ll res = id * (id + 1) / 2;
cout << res << "\n";
}
}
return 0;
}
# | 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... |