提交记录 13335
| 提交时间 |
评测时间 |
| 2020-08-01 11:03:00 |
2020-08-01 11:03:02 |
#include "router.h"
struct Trienode{
unsigned nexthop;
unsigned ls,rs;
bool end;
}T[30100000];
int t;
void init(int n, int q, const RoutingTableEntry *a) {
for(register RoutingTableEntry *i=a,*e=a+n;i!=e;++i){
unsigned cur=0,val=i->addr;
for(register int b=31,r=31-i->len;l>r;--l){
if(val>>b&1){
if(!T[cur].ls)T[cur].ls=++t;
cur=T[cur].ls;
}
else{
if(!T[cur].rs)T[cur].rs=++t;
cur=T[cur].rs;
}
}
T[cur].end=true;
T[cur].nexthop=i->nexthop;
}
}
unsigned query(unsigned addr) {
unsigned cur=0,ans=0;
for(register int i=31;~i;--i){
if(addr>>i&1)cur=T[cur].rs;
else cur=T[cur].ls;
if(!cur)return ans;
else if(T[cur].end)ans=T[cur].nexthop;
}
return ans;
}
| Compilation | N/A | N/A | Compile Error | Score: N/A | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-03-24 12:56:05 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠