hiho week 149 register

Ended

Participants:261

Verdict:Accepted
Score:100 / 100
Submitted:2017-05-12 23:48:17

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <vector>
#include <string>
#include <iostream>
using namespace std;
struct TRIE {
    int p[2];
    char mask;
    int rank;
} tries[990000] = {0};
int num = 1;
void add(unsigned int ip,int l,int f,int rank) {
    int p = 0;
    for(int i = 0; i < l; i++) {
        int q = (ip>>31);
        ip<<=1;
        if(tries[p].p[q]==0) {
            tries[p].p[q] = num;
            num++;
        }
        p = tries[p].p[q];
    }
    if(tries[p].mask==0) {
        tries[p].mask = 2|f;
        tries[p].rank = rank;
    }
}
bool search(unsigned int ip,int l = 32) {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX