提交记录 11275
提交时间 |
评测时间 |
2019-11-12 10:58:20 |
2020-08-01 02:41:12 |
#include <stdint.h>
#include <cstdlib>
#include <utility>
#include <iostream>
#include "router.h"
struct Trie {
struct node_t {
node_t *ch[2];
RoutingTableEntry *entry;
node_t() {
ch[0] = ch[1] = nullptr;
entry = nullptr;
}
};
node_t *root = nullptr;
void insert(const RoutingTableEntry& entry) {
if (!root) root = new node_t;
auto u = root;
for (int i = 0; i < entry.len; i++) {
auto &v = u->ch[entry.addr >> i & 1];
if (!v) v = new node_t;
u = v;
}
delete u->entry;
u->entry = new RoutingTableEntry(entry);
}
const RoutingTableEntry *query(uint32_t addr) {
if (!root) return nullptr;
auto u = root;
const RoutingTableEntry *ret = nullptr;
for (int i = 0; i < 32; i++) {
u = u->ch[addr >> i & 1];
if (!u) break;
if (u->entry) {
ret = u->entry;
}
}
return ret;
}
};
static Trie trie;
void init(int n, int q, const RoutingTableEntry *a) {
for (int i = 0; i < n; i++) trie.insert(a[i]);
}
unsigned query(unsigned addr) {
auto entry = trie.query(addr);
return entry ? entry->nexthop : 0u;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 34.17 us | 36 KB | Accepted | Score: 25 | 显示更多 |
Testcase #2 | 58.168 ms | 95 MB + 432 KB | Wrong Answer | Score: 0 | 显示更多 |
Testcase #3 | 209.37 ms | 95 MB + 432 KB | Wrong Answer | Score: 0 | 显示更多 |
Testcase #4 | 359.458 ms | 95 MB + 432 KB | Wrong Answer | Score: 0 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-04-19 22:20:04 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用