QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#361046 | #8142. Elevator | xianjing | TL | 0ms | 3596kb | C++14 | 854b | 2024-03-22 18:30:41 | 2024-03-22 18:30:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
set<int>c;
int countLessThanX(int x,const std::set<int>& mySet=c ) {
auto it = mySet.lower_bound(x); // 找到第一个大于或等于 x 的元素的迭代器
return std::distance(mySet.begin(), it);
}
void solve(){
int n,m;
cin>>n>>m;
pair<int,int>a[n];
int b[n+1]={0};
int ans[n];
for(int i=0;i<n;i++){
cin>>a[i].first;
a[i].second=i;
}
sort(a,a+n);
for(int i=0;i<n;i++){
b[i+1]=b[i]+a[i].first;
}
ans[a[0].second]=0;
for(int i=1;i<n;i++){
ans[a[i].second]=i*a[i].first-b[i]+countLessThanX(a[i].second)+1;
if(ans[a[i].second]>m-2) ans[a[i].second]=-1;
c.insert(a[i].second);
}
for(int i=0;i<n;i++){
cout<<ans[i]<<"\n";
}
return;
}
signed main(){
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
6 20 3 8 12 6 9 9
output:
0 8 -1 4 13 14
result:
ok 6 lines
Test #2:
score: -100
Time Limit Exceeded
input:
500000 1000000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...