提交记录 14036
| 提交时间 |
评测时间 |
| 2020-08-24 14:37:13 |
2020-08-24 14:37:15 |
// 24-8 naive, ~17.3ns
#include <stdint.h>
#include <arpa/inet.h>
#include <algorithm>
#include "router.h"
const uint32_t TABLE_SIZE = 16384;
uint32_t table_cnt = 0;
uint32_t table_32[TABLE_SIZE][1 << 8] __attribute__((aligned(4096)));
uint32_t table_24[1 << 24] __attribute__((aligned(4096)));
inline void fill(uint32_t *a, int n, uint32_t val) {
while (n >= 4) {
a[0] = val;
a[1] = val;
a[2] = val;
a[3] = val;
n -= 4;
a += 4;
}
while (n) {
a[0] = val;
n--;
a++;
}
}
inline void ins(uint32_t addr, int len, uint32_t nexthop) {
if (len <= 24) {
fill(table_24 + (addr >> 8), 1u << (24 - len), nexthop);
} else {
uint32_t &tmp = table_24[addr >> 8];
addr &= 255u;
if (tmp < -TABLE_SIZE) {
uint32_t *tmp2 = table_32[--table_cnt + TABLE_SIZE];
fill(tmp2, addr, tmp);
fill(tmp2 + addr, 1u << (32 - len), nexthop);
fill(tmp2 + addr + (1u << (32 - len)), 256 - addr - (1u << (32 - len)), tmp);
tmp = table_cnt;
} else {
uint32_t *tmp2 = table_32[tmp + TABLE_SIZE];
fill(tmp2 + addr, 1u << (32 - len), nexthop);
}
}
}
void init(int n, int q, const RoutingTableEntry *tbl) {
for (int i = 0; i < n; i++) {
ins(htonl(tbl[i].addr), tbl[i].len, tbl[i].nexthop);
}
}
unsigned query(unsigned addr) {
addr = htonl(addr);
uint32_t tmp = table_24[addr >> 8];
if (tmp >= -TABLE_SIZE) {
return table_32[tmp + TABLE_SIZE][addr & 255u];
} else {
return tmp;
}
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 13.38 us | 36 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #2 | 20.521 ms | 77 MB + 632 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #3 | 37.882 ms | 77 MB + 632 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #4 | 54.993 ms | 77 MB + 632 KB | Accepted | Score: 25 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-03-23 06:14:01 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠