提交记录 13359
提交时间 |
评测时间 |
2020-08-01 11:39:38 |
2020-08-01 11:39:40 |
#include <arpa/inet.h>
#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(const RoutingTableEntry *i=a,*e=a+n;i!=e;++i){
unsigned cur=0,val=htonl(i->addr);
for(register char b=31,b_end=31-i->len;b!=b_end;--b){
if((val>>b)&1){
if(!T[cur].rs)T[cur].rs=++t;
cur=T[cur].rs;
}
else{
if(!T[cur].ls)T[cur].ls=++t;
cur=T[cur].ls;
}
}
T[cur].end=true;
T[cur].nexthop=i->nexthop;
}
}
unsigned query(unsigned addr) {
unsigned cur=0,ans=0,val=htonl(addr);
if(T[cur].end)ans=T[cur].nexthop;
for(register char b=31;~b;--b){
if((val>>b)&1)cur=T[cur].rs;
else cur=T[cur].ls;
if(!cur)break;
else if(T[cur].end)
ans=T[cur].nexthop;
}
return ans;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 12.38 us | 28 KB | Accepted | Score: 25 | 显示更多 |
Testcase #2 | 57.458 ms | 37 MB + 852 KB | Accepted | Score: 25 | 显示更多 |
Testcase #3 | 180.723 ms | 37 MB + 852 KB | Accepted | Score: 25 | 显示更多 |
Testcase #4 | 302.509 ms | 37 MB + 852 KB | Accepted | Score: 25 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:29:35 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠