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 loop(i,n) for (ll i = 0; i < n; i++)
#define ll long long
#define INF 1e9+5
#define MAXN 1000005
#define MOD 1000000000007
#define pb push_back
#define mp make_pair
typedef pair<ll,ll> pii;
vector<ll>torre;
vector<ll>plane;
ll n;
bool sI(){
for(ll i=1;i<n;i++){
if(torre[i]<=torre[i-1])return false;
}
return true;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll q,y,k,ans,maxi=0;
cin>>n>>q;
loop(i,n){
cin>>k;
torre.pb(k);
}
loop(i,q){
cin>>k;
plane.pb(k);
maxi=max(maxi,k);
}
if(sI()){//bs
loop(i,q){
y=plane[i];
k=upper_bound(torre.begin(),torre.end(),y)-torre.begin();
ans=(k*(k+1))/2;
printf("%lld\n",ans);
}
}else{
ll dp[maxi+1];
memset(dp,-1,sizeof(dp));
loop(i,q){
y=plane[i];
if(dp[y]==-1){
ans=0; ll cur=0;
for(ll j=0;j<n;j++){
while(j<n && torre[j]<=y){j++; cur++;}
ans+=(cur*(cur+1))/2;
cur=0;
}
dp[y]=ans;
}
printf("%lld\n",dp[plane[i]]);
}
}
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... |