QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#763260#9730. Elevator IIzqx#WA 73ms5784kbC++201.6kb2024-11-19 19:13:272024-11-19 19:13:29

Judging History

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

  • [2024-11-19 19:13:29]
  • 评测
  • 测评结果:WA
  • 用时:73ms
  • 内存:5784kb
  • [2024-11-19 19:13:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,f;
int nxt[100005];
struct ss{
    int x,id;
    bool operator <(const ss ot)const{
        if(x==ot.x)return id<ot.id;
        return x<ot.x;
    }
}l[100005],r[100005];
int d[100005];
set<ss> s;
ss get(ss x)
{
    auto it=s.lower_bound(x);
    if(it==s.end())
    {
        it--;
        if(x.id==d[(it->id)])
            it--;
        return *it;
    }
    else
    {
        if(x.id==d[(it->id)])
            it++;
        if(it==s.end())
        {
            it--;
            it--;
        }
        return *it;
    }
}
void solve(void)
{
    cin>>n>>f;
    s.clear();
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>l[i].x>>r[i].x;
        nxt[i]=0;d[i]=i;
        l[i].id=r[i].id=i;
        ans+=r[i].x-l[i].x;
        s.insert(r[i]);
    }
    sort(r+1,r+n+1);
    sort(l+1,l+n+1);
    s.insert((ss){f,0});
    int vis0=0;
    for(int i=n;i>=1;i--)
    {
        ss t=get(l[i]);
        if(i==1&&t.id!=0&&!vis0)
        {
            s.erase(t);
            t=get(l[i]);
        }
        if(!t.id)vis0=1;
        nxt[t.id]=l[i].id;
        d[l[i].id]=d[t.id];
        //cerr<<l[i].id<<" "<<t.id<<endl;
        ans+=max(l[i].x-t.x,0ll);
        s.erase(t);
    }
    cout<<ans<<'\n';
    int now=nxt[0];
    while(now)
   {
    cout<<now<<" ";
    now=nxt[now];
   }
   cout<<'\n';
   return;
}
signed main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    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: 5732kb

input:

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

output:

11
2 1 4 3 
5
2 1 

result:

ok ok 2 cases (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 73ms
memory: 5784kb

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:

524
1 4 15 8 7 10 16 9 2 14 5 17 6 12 11 18 
194
3 5 
397
4 10 13 5 9 7 16 11 1 3 
733
15 13 4 18 10 2 6 1 7 8 9 12 19 5 11 14 16 17 3 
244
13 7 9 1 15 3 2 
422
18 17 
104
1 3 4 2 
187
9 4 2 3 1 8 7 5 6 10 
111
2 1 
92
1 2 
36
1 2 
364
9 3 16 4 6 1 2 7 17 12 8 15 14 13 11 5 
125
3 5 7 1 2 6 4 8 
366...

result:

wrong answer Integer parameter [name=a_i] equals to 194, violates the range [1, 19] (test case 1)