提交记录 13404


用户 题目 状态 得分 用时 内存 语言 代码长度
Aegir test. 自定义测试 Compile Error 0 0 ns 0 KB C++11 1.28 KB
提交时间 评测时间
2020-08-01 19:54:01 2020-08-01 19:54:03
#include<bits/stdc++.h>
using namespace std;

typedef unsigned int ui;
const int MAXN = 1000010;

struct Node
{
	ui v;
	int a, b;
};

int n, id; vector<Node> q;
int cnt = 1, ch[MAXN * 32][2], tim[MAXN * 32];

ui trans(ui a, ui b, ui c, ui d)
{
	return (a << 24) | (b << 16) | (c << 8) | d;
}

void ins(ui v, int len)
{
	int x = 1;
	for(int i = 1; i <= len; ++i)
	{
		int to = (v >> (32 - i)) & 1;
		if(ch[x][to]) x = ch[x][to];
		else ch[x][to] = ++cnt, x = ch[x][to];
	}
	tim[x] = ++id;
}

int top, stk[MAXN];

int ask(ui v, int l, int r)
{
	top = 0; int x = 1;
	for(int i = 31; ~i; --i)
	{
		int to = (v >> i) & 1;
		if(!ch[x][to]) break;
		x = ch[x][to];
		if(tim[x])
		{
			while(top && tim[x] <= r && stk[top] > tim[x]) --top;
			stk[++top] = tim[x];
		}
	}
	int res = 0;
	for(int i = 1; i <= top; ++i)
		if(stk[i] >= l && stk[i] <= r) ++res;
	return res;
}

int main()
{
	scanf("%d", &n); char op[5];
	for(int i = 1; i <= n; ++i)
	{
		scanf("%s", op + 1);
		if(op[1] == 'A')
		{
			int a, b, c, d, len;
			scanf("%d.%d.%d.%d/%d", &a, &b, &c, &d, &len);
			ins(trans(a, b, c, d), len);
		}
		else
		{
			int a, b, c, d, l, r;
			scanf("%d.%d.%d.%d %d %d", &a, &b, &c, &d, &l, &r);
			q.push_back((Node){trans(a, b, c, d), l, r});
		}
	}
	for(Node u : q)
		printf("%d\n", ask(u.v, u.a, u.b));
	return 0;
}

CompilationN/AN/ACompile ErrorScore: N/A


Judge Duck Online | 评测鸭在线
Server Time: 2020-08-05 15:47:02 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用