提交记录 10799


用户 题目 状态 得分 用时 内存 语言 代码长度
duck router32. 测测你的路由器 Accepted 100 1.733 s 9716 KB C++ 871 B
提交时间 评测时间
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;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #113.82 us24 KBAcceptedScore: 25

Testcase #22.839 ms9 MB + 500 KBAcceptedScore: 25

Testcase #3867.573 ms9 MB + 500 KBAcceptedScore: 25

Testcase #41.733 s9 MB + 500 KBAcceptedScore: 25


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:22:59 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠