QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#771233#9730. Elevator IIshinonomezhou#RE 0ms3664kbC++231.2kb2024-11-22 10:58:532024-11-22 10:58:55

Judging History

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

  • [2024-11-22 10:58:55]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3664kb
  • [2024-11-22 10:58:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+2e2;
using pll=pair<ll,ll>;
#define pb push_back
struct Floor{
	ll l,r,id;
}fl[N];
bool cmpl(Floor a,Floor b){
	return a.l<b.l;
}
bool cmpr(Floor a,Floor b){
	return a.r<b.r;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int tt;
	cin>>tt;
	while(tt--){
		ll n,f;
		cin>>n>>f;
		ll ans=0;
		for(ll i=1;i<=n;i++){
			ll l,r;
			cin>>l>>r;
			ans+=r-l;
			fl[i]={l,r,i};
		}
		vector<int>flag(n+10);
		vector<ll>p;
		sort(fl+1,fl+1+n,cmpl);
		priority_queue<pll,vector<pll>,greater<pll>>pq;
		for(ll i=1;i<=n;i++){
			if(fl[i].l<=f){
				pq.push({fl[i].r,fl[i].id});
			}
			else {
				if(pq.top().first>f){
					f=pq.top().first;
					ll id=pq.top().second;
					p.pb(id);flag[id]=1;
				}
				if(f<=fl[i].l){
					ans+=fl[i].l-f;
					f=fl[i].r;
					p.pb(fl[i].id);flag[fl[i].id]=1;
				}
				else {
					pq.push({fl[i].r,fl[i].id});
				}
				
			}
			
		}
		cout<<ans<<'\n';
		sort(fl+1,fl+1+n,cmpr);
		for(int i=n;i>=1;i--){
			ll id=fl[i].id;
			if(!flag[id])p.pb(id);
		}
		for(auto it:p)cout<<it<<' ';cout<<'\n';
		
		
		
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3664kb

input:

2
4 2
3 6
1 3
2 7
5 6
2 5
2 4
6 8

output:

11
2 1 3 4 
5
2 1 

result:

ok ok 2 cases (2 test cases)

Test #2:

score: -100
Runtime Error

input:

6100
19 52
51 98
2 83
40 58
96 99
39 55
72 94
15 17
4 15
48 99
2 99
77 78
35 77
44 62
79 81
30 31
1 48
48 76
68 99
60 66
6 19
44 53
64 92
17 28
67 98
9 99
40 65
16 27
99 100
15 56
4 6
24 97
84 96
47 49
37 38
77 79
13 40
13 92
71 100
47 93
90 91
72 81
15 48
32 71
19 17
95 99
10 23
18 100
90 93
52 92
...

output:


result: