提交记录 10468


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah router32. 测测你的路由器 Runtime Error 25 196.692 ms 1074680 KB C++11 1.15 KB
提交时间 评测时间
2019-09-18 12:06:19 2020-08-01 02:15:57
#pragma GCC optimize("Ofast,no-stack-protector")
#include "router.h"
#include <bits/stdc++.h>
#include <arpa/inet.h>
using namespace std;

const int GG = 21;

const int IGG = 32 - GG;
const unsigned IGGM = (1u << IGG) - 1;

struct VEntry
{
    unsigned son;
    unsigned nexthop;
} table[1 << GG];

int top = 0;
unsigned shop[1 << (GG - 4)][1 << IGG];

void ins(unsigned addr, int len, unsigned nexthop)
{
    if(len <= GG)
    {
        addr >>= IGG;
        for(int T = 1 << (GG - len); T--; ++addr) table[addr].nexthop = nexthop;
    }
    else
    {
        unsigned &son = table[addr >> IGG].son;
        if(!son)
        {
            son = ++top;
            for(int i = 0; i < (1 << IGG); i++) shop[son][i] = table[addr >> IGG].nexthop;
        }
        addr &= IGGM;
        for(int T = 1 << (32 - len); T--; ++addr) shop[son][addr] = nexthop;
    }
}

void init(int n, int q, const RoutingTableEntry *a)
{
    for(int i = 0; i < n; i++) ins(htonl(a[i].addr), a[i].len, a[i].nexthop);
}

unsigned query(unsigned addr)
{
    addr = htonl(addr);
    VEntry &ent = table[addr >> IGG];
    if(ent.son) return shop[ent.son][addr & IGGM];
    else return ent.nexthop;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #136.44 us60 KBAcceptedScore: 25

Testcase #2196.692 ms1049 MB + 504 KBRuntime ErrorScore: 0

Testcase #3196.298 ms1049 MB + 504 KBRuntime ErrorScore: 0

Testcase #4196.292 ms1049 MB + 504 KBRuntime ErrorScore: 0


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