提交记录 10789


用户 题目 状态 得分 用时 内存 语言 代码长度
duck router32. 测测你的路由器 Accepted 100 5.105 s 48488 KB C++ 1.16 KB
提交时间 评测时间
2019-09-30 01:25:23 2020-08-01 02:30:32
#include <map>
#include <arpa/inet.h>
#include "router.h"
#include <algorithm>

std::map<unsigned, unsigned> M[33];

void ins(const RoutingTableEntry *e) {
    M[e->len][e->addr] = e->nexthop;
}

int nn;
RoutingTableEntry *a;
bool cmp(const RoutingTableEntry &u, const RoutingTableEntry &v){
    return u.addr<v.addr || u.addr==v.addr && u.len<v.len;
}
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);
    }
    for (int i = 0; i < n; i++) {
        ins(tbl + i);
    }
}
unsigned query(unsigned addr) {
    addr = htonl(addr);

    for (int i = 32; i >= 0; i--) {
        RoutingTableEntry tmp;
        tmp.addr=addr;
        tmp.len=i;
        int lo=std::lower_bound(a,a+nn,tmp,cmp)-a;
        int hi=std::upper_bound(a,a+nn,tmp,cmp)-a;
        for (int j=lo;j<nn;j++){
            if (a[j].addr==addr){
                if (a[j].len==i){
                    return a[j].nexthop;
                }
            }else{
                break;
            }
        }
        addr &= ~(1u << (32 - i));
        unsigned addr0=~(1u<<((i-1)/8*8+7-(i-1)%8));
    }

    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #114.23 us24 KBAcceptedScore: 25

Testcase #2100.442 ms47 MB + 360 KBAcceptedScore: 25

Testcase #32.602 s47 MB + 360 KBAcceptedScore: 25

Testcase #45.105 s47 MB + 360 KBAcceptedScore: 25


Judge Duck Online | 评测鸭在线
Server Time: 2026-03-28 22:18:54 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠