QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#763272#9730. Elevator IIzqx#AC ✓209ms14672kbC++201.8kb2024-11-19 19:17:542024-11-19 19:17:55

Judging History

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

  • [2024-11-19 19:17:55]
  • 评测
  • 测评结果:AC
  • 用时:209ms
  • 内存:14672kb
  • [2024-11-19 19:17:54]
  • 提交

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 fa[100005];
int find(int x)
{
    if(x==fa[x])return x;
    return fa[x]=find(fa[x]);
}
void merge(int x,int y)
{
    x=find(x);y=find(y);
    fa[x]=y;
}
set<ss> s;
ss get(ss x)
{
    auto it=s.lower_bound(x);
    if(it==s.end())
    {
        it--;
        if(find(x.id)==find(it->id))
            it--;
        return *it;
    }
    else
    {
        if(find(x.id)==find(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=0;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=n;i++)
    {
        cin>>l[i].x>>r[i].x;
        nxt[i]=0;
        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;
        merge(t.id,l[i].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;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

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

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: 0
Accepted
time: 86ms
memory: 5840kb

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 3 13 19 5 17 6 12 11 18 
194
3 5 6 2 4 1 
397
4 10 13 5 2 6 15 12 14 8 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 11 4 14 12 5 10 6 8 
422
18 12 20 6 19 5 2 11 3 14 10 16 8 4 7 9 15 13 1 17 
104
1 3 4 2 
187
9 4 2 3 1 8 7 5 6 1...

result:

ok ok 6100 cases (6100 test cases)

Test #3:

score: 0
Accepted
time: 209ms
memory: 14608kb

input:

3
100000 9859
150464 951410
637107 897197
236268 936879
353406 403927
511229 999416
861211 958428
186246 446149
162388 805753
449016 817386
147119 604340
579101 926848
958992 987299
859662 907007
507058 690951
719158 856587
789149 927957
691705 707085
694110 845505
192759 616586
905489 935507
937041...

output:

24903933702
79516 24281 16079 72303 26274 32317 97148 70088 99228 36666 20575 46478 47702 87316 28986 96647 33026 3227 39766 35329 47875 19889 3996 28903 92004 30904 73997 53029 79556 54168 27422 72924 70625 53458 38825 72254 27571 14681 16186 80721 64708 27828 94411 28184 31312 9865 79396 9389 8081...

result:

ok ok 3 cases (3 test cases)

Test #4:

score: 0
Accepted
time: 193ms
memory: 14672kb

input:

3
100000 932101
80818 80823
538842 538844
406812 406818
625053 625054
511066 511073
667363 667365
527022 527023
621329 621331
855832 855852
796168 796169
268927 268929
650891 650895
312793 312794
873256 873260
424896 424929
266271 266272
902201 902209
842863 842864
361599 361610
647851 647855
148132...

output:

986597
59484 69750 82641 70352 47710 30352 11990 73429 41160 30498 44088 74602 34312 10872 13641 11660 99646 20276 70364 42804 6654 31129 72528 68730 60667 69688 16984 31364 9367 97033 83583 94175 72990 74178 77157 82305 60601 21546 76283 38324 21059 98950 61273 30010 90567 30718 44271 98946 75361 5...

result:

ok ok 3 cases (3 test cases)

Test #5:

score: 0
Accepted
time: 186ms
memory: 14592kb

input:

3
100000 375117879
637628712 637644704
788784579 788792294
804734775 804734822
332639566 332642798
143113598 143114045
132119073 132122341
684483097 684513821
484676670 484678332
661667340 661668818
777865379 777870254
142495696 142495995
101735856 101740588
906481102 906481965
360087766 360091064
1...

output:

872643717
43549 34676 31878 49124 12077 8140 13605 76831 10834 96613 83688 46028 65944 14511 56152 84791 1759 60404 73244 38124 93732 74294 8688 64153 56500 39213 27938 93350 21680 36926 8295 8832 69685 1025 22233 14796 83881 83105 72820 95432 90168 29163 20496 4937 51441 96515 46657 82775 90528 380...

result:

ok ok 3 cases (3 test cases)

Extra Test:

score: 0
Extra Test Passed