QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#853901#9730. Elevator IIucup-team3474#RE 1ms9980kbC++231.7kb2025-01-11 20:03:222025-01-11 20:03:30

Judging History

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

  • [2025-01-11 20:03:30]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:9980kb
  • [2025-01-11 20:03:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1919810;
typedef long long ll;
typedef pair<ll,ll> PII;
int n,m,k;
int a[N],b[N];
int l[N],r[N];
// vector<int> e[N];

typedef struct{
    int l,r,id;
}Node;
bool operator<(const Node &a,const Node &b){
    if(a.l==b.l) return a.r<b.r;
    return a.l<b.l;
}
Node e[N];
bool tf[N];
// vector<Node> v; 


void __(){
    scanf("%d%d",&n,&k);
    vector<int> ans;

    for(int i=1;i<=n;i++){
        scanf("%d%d",&l[i],&r[i]);
        tf[i]=0;
        e[i]={l[i],r[i],i};
    }
    ans.push_back(0);
    sort(e+1,e+1+n);
    int now=k;
    priority_queue<PII> q;
    int j=1;
    while(j<=n&&e[j].l<=now){
         q.push({e[j].r,e[j].id});
         j++;
    }
    
        // cout<<j<<" "<<now<<endl;
    while(j<=n){
        auto t=q.top();
        if(t.first<=now){
            now=e[j].l;
            while(j<=n&&e[j].l<=now){
                q.push({e[j].r,e[j].id});
                j++;
            }
        }else{
            
            q.pop();
            ans.push_back(t.second);
            tf[t.second]=1;
            now=t.first;
            while(j<=n&&e[j].l<=now){
                q.push({e[j].r,e[j].id});
                j++;
            }
        }
    }
    for(int i=n;i>=1;i--){
        if(!tf[e[i].id]) ans.push_back(e[i].id);
    }
    ll tot=0;
    l[0]=0,r[0]=k;
    for(int i=1;i<=n;i++){
        ll ad=(r[ans[i]]-l[ans[i]])+max(0,l[ans[i]]-r[ans[i-1]]);
        tot+=ad;
    }
    printf("%lld\n",tot);
    for(int i=1;i<=n;i++) printf("%d ",ans[i]);
    printf("\n");

    
}


int main(){
    int _=1;
    cin>>_;
    while(_--){
        __();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9980kb

input:

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

output:

11
3 4 1 2 
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: