QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#763190 | #9730. Elevator II | zqx# | WA | 76ms | 7832kb | C++20 | 1.6kb | 2024-11-19 18:46:10 | 2024-11-19 18:46:13 |
Judging History
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==(it->id))
it--;
return *it;
}
else
{
if(x.id==(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]=d[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;
//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: 5700kb
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: 76ms
memory: 7832kb
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 10 16 9 2 14 5 17 6 12 11 18 194 3 5 397 4 9 7 16 11 1 3 733 15 13 4 18 10 2 6 1 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 109 2 1 92 1 2 36 1 2 363 9 3 16 4 6 1 2 7 17 12 8 15 14 106 3 5 7 1 2 366 2 1 476 5 13 7 6 12 1 14 3 9 480 11 ...
result:
wrong answer Integer parameter [name=a_i] equals to 194, violates the range [1, 19] (test case 1)