QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#361047#8142. ElevatorxianjingTL 1ms3696kbC++141.1kb2024-03-22 18:32:282024-03-22 18:32:29

Judging History

你现在查看的是最新测评结果

  • [2024-03-22 18:32:29]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3696kb
  • [2024-03-22 18:32:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
set<int>c;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
        x=x*10+ch-'0',ch=getchar();
    return x*f;
}
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++){
		a[i].first=read();
		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: 1ms
memory: 3696kb

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 ...

output:


result: