QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#795458#9730. Elevator IINlll#WA 80ms3692kbC++203.2kb2024-11-30 20:40:072024-11-30 20:40:08

Judging History

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

  • [2024-11-30 20:40:08]
  • 评测
  • 测评结果:WA
  • 用时:80ms
  • 内存:3692kb
  • [2024-11-30 20:40:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

struct node
{
    int l,r;
    int id;
};


void work()
{
    int n,f, mxr = 0;
    std::cin>>n>>f;
    std::vector<node > a(n+1);
    vector<bool> vis(n + 1); 
    ll ans=0;
    vector<int> Rg;
    vector<int> jump;
    Rg.push_back(f);
    for(int i=1;i<=n;i++)
    {
        int x,y;
        std::cin>>x>>y;
        ans += 1ll * y - x;
        a[i]={x,y,i};
        Rg.push_back(x);
        Rg.push_back(y);
    }
    sort(Rg.begin(), Rg.end());
    Rg.erase(unique(Rg.begin(), Rg.end()), Rg.end());
    int N = Rg.size();
    vector<int> di(N + 1);
    vector<int> nex (N + 1);
    f = lower_bound(Rg.begin(), Rg.end(), f) - Rg.begin() + 1;
    //cout << f<< " ";
    for(int i=1;i<=n;i++)
    {
        a[i].l = lower_bound(Rg.begin(), Rg.end(), a[i].l) - Rg.begin() + 1;
        a[i].r = lower_bound(Rg.begin(), Rg.end(), a[i].r) - Rg.begin() + 1;
        //cout << a[i].l <<" " << a[i].r<<"\n";
        if(a[i].r >= a[di[a[i].l]].r) di[a[i].l] = i;
        mxr = max(mxr, a[i].r);
    }
    int nexid = 0;
    for(int i = N; i >= 1; i--){
        if(di[i]) nexid = di[i];
        nex[i] = nexid;
        //cout << i<<":" <<di[i] <<" " <<nex[i]<<"\n";
    }
    vector<int> mx(4 * N + 1);
    auto build =[&] (auto self, int k, int l, int r) -> void{
        if(l == r){
            mx[k] = di[l];
            return;
        }
        int mid = l + r >> 1;
        self(self, k << 1, l, mid);
        self(self, k << 1 | 1, mid + 1, r);
        //cout << k <<" " << l <<" " << r << " " << a[mx[k << 1]].r <<" " << a[mx[k << 1 | 1]].r << "\n"; 
        if(a[mx[k << 1]].r >= a[mx[k << 1 | 1]].r) mx[k] = mx[k << 1];
        else mx[k] = mx[k << 1 | 1];
    };
    auto query =[&] (auto self, int k, int l, int r, int x, int y) -> int{
        //if(!k) return 0;
        //if(k > 4 * N) return 0;
        if(x <= l && r <= y) return mx[k];
        int mid = l + r >> 1;
        if(y <= mid) return self(self, k << 1, l, mid, x, y);
        else if(x > mid) return self(self, k << 1 | 1, mid + 1, r, x, y);
        else{
            int lc = self(self, k << 1, l, mid, x, y);
            int rc = self(self, k << 1 | 1, mid + 1, r, x, y);
            if(a[lc].r >= a[rc].r) return lc;
            else return rc;
        }
    };
    build(build, 1, 1, N);
    int pref = 0;
    while(f < mxr){
        int i = query(query, 1, 1, N, pref + 1, f);
        if(a[i].r <= f){
            i = nex[f];
            ans += 1ll * a[i].l - f;
        }
        pref = f;
        f = a[i].r;
        //cout <<pref<<" "<< f <<" " << i <<" " << mxr<<"\n";
        vis[i] = 1;
        jump.push_back(i);
    }
    auto cmp=[](node x,node y) ->bool
    {
        return x.l>y.l;
    };
    std::sort(a.begin()+1,a.end(),cmp);

    std::cout<<ans<<'\n';
    //reverse(jump.begin(), jump.end());
    for(auto i:jump) cout << i<<" ";

    for(int i=1;i<=n;i++)
        if(!vis[a[i].id]) std::cout<<a[i].id<<' ';
    std::cout<<'\n';
}

int main()
{
    std::cin.tie(0);
    std::cin.sync_with_stdio(0);
    int t=1;
    std::cin>>t;
    while(t--)
        work();
    return 0;
}
/*
3
4 2
3 6
1 3
2 7
5 6
2 5
2 4
6 8
4 3
4 6
7 8
2 5
1 3
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Wrong Answer
time: 80ms
memory: 3692kb

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

result:

wrong answer Participant declares the cost to be 111, but the plan actually costs 117 (test case 9)