提交记录 10448


用户 题目 状态 得分 用时 内存 语言 代码长度
user1 router32. 测测你的路由器 Runtime Error 0 44.542 ms 53248 KB C++11 1018 B
提交时间 评测时间
2019-09-18 10:19:23 2020-08-01 02:14:42
#include "router.h"
RoutingTableEntry ssssss[65536];
#include <arpa/inet.h>

struct pp {pp* left, *right; unsigned refer;} pool[9999999]; int ppcnt=0;
struct cachetype { pp* gp; unsigned gres; void set(unsigned addr) {
	unsigned res=0;pp* p=pool;
	for (int i=0; i<16; ++i) {
		if(p->refer)res=p->refer;p=addr&0x8000?p->right:p->left;
addr<<=1;
}
	while(p);gres=res;gp=p;

}} *cache;
pp* insert(pp*& pos) {if(!pos)pos=pool+ ++ppcnt; return pos;}
pp& insert(int depth, unsigned pos) {pp* p=pool; for(int i=0; i<depth;++i) {
p=insert(pos&0x80000000?p->right:p->left), pos<<=1;
}
return *p;
}
void init(int n, int q, const RoutingTableEntry *a) {
	for(int i=0; i<n; ++i) insert(a[i].len,htonl(a[i].addr)).refer=a[i].nexthop;
cache = (cachetype*)(n<60000?ssssss:a);
for(int i=0; i<65536; ++i) cache[i].set(i);
}

unsigned query(unsigned addr) {addr=htonl(addr);
	unsigned res=cache[addr>>16].gres;pp* p=cache[addr>>16].gp;
	do {
		if(p->refer)res=p->refer;p=addr&0x8000?p->right:p->left;
addr<<=1;
}
	while(p);return res;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #110.38 us28 KBRuntime ErrorScore: 0

Testcase #244.469 ms52 MBRuntime ErrorScore: 0

Testcase #344.542 ms52 MBRuntime ErrorScore: 0

Testcase #444.468 ms52 MBRuntime ErrorScore: 0


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