QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#755052 | #9521. Giving Directions in Harbin | ANIG# | RE | 0ms | 0kb | C++14 | 2.1kb | 2024-11-16 16:21:09 | 2024-11-16 16:21:11 |
answer
#include<bits/stdc++.h>
using namespace std;
int L,R;
int k,idx=1;
vector<int> rec[1111];
vector<pair<int,int>> ver[1111];
vector<pair<int,int>> tmp;
void solve(int l,int r,int dep=0,int now=1){
if(L<=l&&r<=R){
//cerr<<"at "<<l<<' '<<r<<' '<<dep<<endl;
if(l!=r) rec[dep].emplace_back(now);
return ;
}
int mid=(l+r)>>1;
if(L<=mid){
if(!l){
if(l!=mid) solve(l,mid,dep+1,now);
else tmp.emplace_back(now,0);
}
else{
if(l!=mid){
idx++;
ver[now].emplace_back(idx,0);
}else tmp.emplace_back(now,0);
solve(l,mid,dep+1,idx);
}
}
if(mid<R){
if(mid+1!=r){
idx++;
ver[now].emplace_back(idx,1);
}else tmp.emplace_back(now,1);
solve(mid+1,r,dep+1,idx);
}
}
int main(){
cin>>L>>R;
int mx=R+1;
while((mx&-mx)!=mx) mx++;
k=__lg(mx);
cerr<<k<<endl;
solve(0,mx-1);
mx=-1;
for(int i=0; i<1000; i++){
if(rec[i].size()){
mx=i;
break;
}
}
assert(mx!=-1);
int Lim=k-mx;
for(int i=idx+1; i<idx+Lim; i++){
ver[i].emplace_back(i+1,0);
ver[i].emplace_back(i+1,1);
}
for(int i=0; i<1000; i++){
for(auto pt:rec[i]){
ver[pt].emplace_back(idx+i-mx+1,0);
ver[pt].emplace_back(idx+i-mx+1,1);
}
}
for(auto pt:tmp){
ver[pt.first].emplace_back(idx+Lim,pt.second);
}
int T=0;
for(int i=1; i<1000; i++){
if(ver[i].size()){
T=i;
for(auto p:ver[i]) T=max(T,p.first);
}
}
assert(T==idx+Lim);
cout<<T<<'\n';
for(int i=1; i<=T; i++){
cout<<ver[i].size()<<' ';
for(auto pt:ver[i]){
cout<<pt.first<<' '<<pt.second<<' ';
}
cout<<'\n';
}
return 0;
}
/*
6 13
4
9
2 2 1 4 1
1 3 1
2 9 0 9 1
2 5 0 6 1
2 8 0 8 1
1 7 0
2 9 0 9 1
2 9 0 9 1
0
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
1 2 S 2 E 1