提交记录 10423


用户 题目 状态 得分 用时 内存 语言 代码长度
wys router32. 测测你的路由器 Wrong Answer 0 1.675 s 87776 KB C++11 1.13 KB
提交时间 评测时间
2019-09-17 21:12:55 2020-08-01 02:14:30
#include <unordered_map>
#include <arpa/inet.h>
#include "router.h"

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

const unsigned neg_pow[33] = {
	-1u, -2u, -4u, -8u, -16u, -32u, -64u, -128u,
	-256u, -512u, -1024u, -2048u, -4096u, -8192u, -16384u,
	-(1u << 15), -(1u << 16), -(1u << 17), -(1u << 18),
	-(1u << 19), -(1u << 20), -(1u << 21), -(1u << 22),
	-(1u << 23), -(1u << 24), -(1u << 25), -(1u << 26),
	-(1u << 27), -(1u << 28), -(1u << 29), -(1u << 30),
	-(1u << 31), 0
};

inline void ins(const RoutingTableEntry *e, int req_len) {
	if (e->len != req_len) return;
	unsigned addr = htonl(e->addr);
	for (int i = e->len; i >= 0; i--) {
		M[i][addr & neg_pow[32 - i]] = e->nexthop;
	}
}

void init(int n, int q, const RoutingTableEntry *tbl) {
	for (int len = 32; len >= 0; len--) {
		for (int i = 0; i < n; i++) {
			ins(tbl + i, len);
		}
	}
	
	if (M[0].count(0) == 0) {
		M[0][0] = 0;
	}
}

unsigned query(unsigned addr) {
	addr = htonl(addr);
	
	int l = 0, r = 32;
	while (l < r) {
		int mid = (l + r + 1) >> 1;
		if (M[mid].count(addr & neg_pow[32 - mid]) > 0) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	
	return M[l][addr & neg_pow[32 - l]];
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #116.71 us28 KBWrong AnswerScore: 0

Testcase #2828.327 ms85 MB + 736 KBWrong AnswerScore: 0

Testcase #31.251 s85 MB + 736 KBWrong AnswerScore: 0

Testcase #41.675 s85 MB + 736 KBWrong AnswerScore: 0


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