提交记录 10799
提交时间 |
评测时间 |
2019-09-30 01:52:25 |
2020-08-01 02:30:55 |
#include "router.h"
#include <arpa/inet.h>
#include <algorithm>
int nn;
RoutingTableEntry *a;
bool addrcmp(const RoutingTableEntry &u, const RoutingTableEntry &v){
return u.addr<v.addr;
}
void init(int n, int q, const RoutingTableEntry *tbl) {
nn=n;a=(RoutingTableEntry *)tbl;
for (int i=0;i<n;i++){
a[i].addr=htonl(a[i].addr);
}
}
unsigned query(unsigned addr) {
unsigned addr0=addr;
for (int i=32;i>=0;i--){
addr=htonl(addr0);
RoutingTableEntry tmp;
tmp.addr=addr;
int lo=std::lower_bound(a,a+nn,tmp,addrcmp)-a;
for (int j=lo;j<nn;j++){
if (a[j].addr==addr){
if (a[j].len==i){
return a[j].nexthop;
}
}else{
break;
}
}
addr0&=~(1u<<((i-1)/8*8+7-(i-1)%8));
}
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 13.82 us | 24 KB | Accepted | Score: 25 | 显示更多 |
Testcase #2 | 2.839 ms | 9 MB + 500 KB | Accepted | Score: 25 | 显示更多 |
Testcase #3 | 867.573 ms | 9 MB + 500 KB | Accepted | Score: 25 | 显示更多 |
Testcase #4 | 1.733 s | 9 MB + 500 KB | Accepted | Score: 25 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:22:59 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠