QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#865213#9730. Elevator IItsaiCompile Error//C++141.9kb2025-01-21 16:06:452025-01-21 16:06:45

Judging History

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

  • [2025-01-21 16:06:45]
  • 评测
  • [2025-01-21 16:06:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=200005;
struct node{
	ll l;
	ll r;
	int p;
	int okp;//上一个走谁
	ll okl;//之前最左边
}a[N];
bool cmp(node n1,node n2){
	if(n1.r!=n2.r){
		return n1.r>n2.r;
	}
	return  n1.l>n2.l;
}
ll sum[N]={0};
bool vis[N]={0};
void solve(int tt){
	int n;
	ll f;
	scanf("%d %lld",&n,&f);
	ll all=0;
	for(int i=1;i<=n;i++){
		vis[i]=0;
		sum[i]=0;
		ll x,y;
		scanf("%lld %lld",&x,&y);
		a[i]={x,y,i,-1,y};
		all+=(y-x);
	}
	if(tt==13){
		cout<<n<<"nf"<<f;
		for(int i=1;i<=n;i++){
			cout<<"l"<<l<<"r"<<r;
		}
	}
	sort(a+1,a+1+n,cmp);
	sum[a[1].p]=0;
	for(int i=2;i<=n;i++){
		if(a[i].r>=a[i-1].l){//往上无伤
			if(a[i-1].l<a[i-1].okl){//左边更小
				a[i].okl=a[i-1].l;
				a[i].okp=i-1;
			}else{
				a[i].okl=a[i-1].okl;
				a[i].okp=a[i-1].okp;
			}
			sum[a[i].p]=sum[a[i-1].p];
		}else{//往上有伤
			if(a[i-1].l<a[i-1].okl){//左边更小
				a[i].okl=a[i-1].l;
				a[i].okp=i-1;			
				sum[a[i].p]=sum[a[i-1].p]+a[i-1].l-a[i].r;
			}else{
				a[i].okl=a[i-1].okl;
				a[i].okp=a[i-1].okp;
				sum[a[i].p]=sum[a[i-1].okp]+max(0ll,a[i-1].okl-a[i].r);
			}
		}
	}
	ll mini=1e17;
	int st=-1;
	for(int i=1;i<=n;i++){
		if(max(0ll,a[i].l-f)+sum[a[i].p]<mini){
			mini=max(0ll,a[i].l-f)+sum[a[i].p];
			st=i;//逻辑标号
		}
	}
	all+=mini;
	printf("%lld\n",all);
	int s=0;
	for(int i=st;i!=-1;i=a[i].okp){
		if(s==1){
			printf(" ");
		}
		s=1;
		printf("%d",a[i].p);
		vis[a[i].p]=1;
	}
	for(int i=1;i<=n;i++){
		if(!vis[a[i].p]){
			if(s==1){
				printf(" ");
			}
			s=1;
			printf("%d",a[i].p);
			vis[a[i].p]=1;
		}
	}
}
int main(){
	int t=1;
	scanf("%d",&t);
	int tt=1;
	while(t--){
		solve(tt);
		tt++;
		printf("\n");
	}
	return 0;
}
/*
6 1
5 10
1 9
1 8
2 3
4 7
6 7
*/

Details

answer.code: In function ‘void solve(int)’:
answer.code:37:36: error: ‘l’ was not declared in this scope
   37 |                         cout<<"l"<<l<<"r"<<r;
      |                                    ^
answer.code:37:44: error: ‘r’ was not declared in this scope
   37 |                         cout<<"l"<<l<<"r"<<r;
      |                                            ^
answer.code:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |         scanf("%d %lld",&n,&f);
      |         ~~~~~^~~~~~~~~~~~~~~~~
answer.code:30:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |                 scanf("%lld %lld",&x,&y);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:96:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   96 |         scanf("%d",&t);
      |         ~~~~~^~~~~~~~~