Skip to content

Instantly share code, notes, and snippets.

@htfy96
Created April 6, 2016 15:49
Show Gist options
  • Save htfy96/faedbafdd5c471c5ae24b32cd4a649b3 to your computer and use it in GitHub Desktop.
Save htfy96/faedbafdd5c471c5ae24b32cd4a649b3 to your computer and use it in GitHub Desktop.
/* **********************************
* 精简版头文件 修改自岛娘的头文件
* By lz96@foxmail.com
* 复制到你的代码头部即可使用
* **********************************/
#define T_ long long //各种循环变量的类型,特殊情况可以改成long long
#define fuck(s_) {cout<<s_<<endl;return 0;} //输出s_的内容并结束程序:fuck("NO");
/*************************
* 各种循环函数
* re:3个参数:循环变量,起始值,终止值
* rep: 2个参数:循环变量,终止值/初始值
* 后缀2/3:二维、三维
* 后缀0:有则初始值/终止值为0 否则为1
* 前缀r:有则从大到小循环,否则从小到大循环
* ***********************/
#define printarr(a_,x_) rep(i_,x_)cout<<a_[i_]<<" ";cout<<endl; //输出一维数组 输出a[1] ~ a[5] printarr(a,5)
#define printarr0(a_,x_) rep0(i_,x_)cout<<a_[i_]<<" ";cout<<endl; // 输出a[0] ~ a[4] printarr0(a,5)
#define printarr2(a_,x_,y_) rep(i_,x_){rep(j_,y_)cout<<a_[i_][j_]<<' ';cout<<endl;} //输出二维数组
#define printarr20(a_,x_,y_) rep0(i_,x_){rep0(j_,y_)cout<<a[i_][j_]<<' ';cout<<endl;} //输出二维数组,下标从0开始
#define rep2o(a_,b_,n_) rep(a_,n_) re(b_,a_+1,n_) // for(T_ a_=1;a_<=n_;++a_) for(T_ b_=a_+1;b_<=n_;++b_)
#define rep20o(a_,b_,n_) rep0(a_,n_) re0(b_,a_+1,n_) // for(T_ a_=0;a_<n_;++a_) for(T_ b_=a_+1;b_<n_;++b_)
#define rep2(a_,b_,p_,q_) rep(a_,p_) rep(b_,q_)// for(T_ a_=1;a_<=n_;++a_) for(T_ b_=1;b_<=n_;++b_)
#define rep20(a_,b_,p_,q_) rep0(a_,p_) rep0(b_,q_) // for(T_ a_=0;a_<n_;++a_) for(T_ b_=0;b_<n_;++b_)
#define rrep2(a_,b_,p_,q_) rrep(a_,p_) rrep(b_,q_)
#define rrep20(a_,b_,p_,q_) rrep0(a_,p_) rrep0(b_,q_)
#define rep3(a_,b_,c_,p_,q_,r_) rep(a_,p_) rep(b_,q_) rep(c_,r_)
#define rep30(a_,b_,c_,p_,q_,r_) rep0(a_,p_) rep0(b_,q_) rep0(c_,r_)
#define rrep3(a_,b_,c_,p_,q_,r_) rrep(a_,p_) rrep(b_,q_) rrep(c_,r_)
#define rrep30(a_,b_,c_,p_,q_,r_) rrep0(a_,p_) rrep0(b_,q_) rrep0(c_,r_)
#define rep(a_,x_) re(a_,1,x_) //rep(i,5) == for(T_ i=1;i<=5;++i)
#define rep0(a_,x_) re0(a_,0,x_) //rep0(i,5) == for(T_ i=0;i<5;++i)
#define rrep(a_,x_) rre(a_,x_,1) //rrep(i,5) == for(T_ i=5;i>=1;--i)
#define rrep0(a_,x_) rre(a_,x_-1,0) //rrep0(i,5) == for(T_ i=4;i>=0;--i)
#define re(a_,s_,t_) for(T_ a_=s_;a_<=t_;++a_) // re(i,2,4) == for(T_ i=2;i<=4;++i)
#define re0(a_,s_,t_) for(T_ a_=s_;a_<t_;++a_) // re0(i,2,4) == for(T_ i=2;i<4;++i)
#define rre(a_,s_,t_) for(T_ a_=s_;a_>=t_;--a_)
#define rre0(a_,s_,t_) for(T_ a_=s_;a_>t_;--a_)
#define repit(a_,c_) for(__typeof__(a_.begin()) c_=a_.begin();c_!=a_.end();++c_) // 只在GCC上可用:repit(容器,迭代器)
#define nosync std::ios::sync_with_stdio(false);std::cin.tie(0);ios_base::sync_with_stdio(0) //加在main的第一行,加快输入输出,但之后不能用scanf/printf
#define DE false //是否在调试模式?
#define de(s_) if(DE){s_ } // de(仅仅想在调试时执行的语句) de(cout<<n<<m<<endl;)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <numeric>
#include <bitset>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <ctime>
#include <stack>
#include <queue>
#include <cassert>
#pragma GCC optimize("O2")
using namespace std;
#define endl '\n'
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1}; //十字方向的所有坐标 (basex+dx4[i] , basey+dy4[i])
const long long modb=1000000007; //取模的数 ModBase
const long inf=0x3f3f3f3f; //很大的整数
const double oo=1e15; //很大的实数
const double eps=1e-8; //很小的实数,计算几何用
const double pi=acos(-1.0); //pi
template<typename T> void clr(T* a_,int n_=0,size_t s_=-1) {if (s_==-1) s_=sizeof(a_); memset(a_,n_,sizeof(a_[0])*s_); } // clr(a):将a清空为0 clr(a,0xff)将a每个字节清成0xff clr(a,0xff,4) 将a[0]~a[3]的每一个字节填成0xff
template<typename T> T sqr(T a_) { return a_*a_; } //平方
template<typename T> T cub(T a_) { return a_*a_*a_; } //立方
inline T_ mf(T_ n_) {return ((n_<0)?n_+(modb<<2):n_)%modb; } //mf(n) = n%modb,加上了负数判断,ModFunction
template<typename T>T max(T a_,T b_,T c_) { return max(a_,max(b_,c_)); } //三个参数的max
template<typename T>T min(T a_,T b_,T c_) { return min(a_,min(b_,c_)); } //三个参数的min
inline int dbcmp(double a_, double b_) { return (fabs(a_-b_)<eps)?0:(a_<b_?-1:1); } //允许误差的cmp,< : -1 == : 0 > : 1
inline double dbdiv(T_ a_, T_ b_) { return static_cast<double>(a_) / b_; } //实数除 dbdiv(3,5)=0.6
inline double angle(double x_, double y_) { if (x_==0.0) return y_>0?pi/2:3*pi/2; else { double t_=atan2(y_,x_); return (t_<0.0?t_+pi:t_) + y_<0?pi:0.0; }} //计算(x_,y_)的幅角 [0,2*pi)
/******************************************************************************************/
map<long , pair<bool, int> > m[33];
long getip()
{
long x = 0, t; char c;
cin >> t;
x = t;
cin >> c;
cin >> t;
x = (x << 8) + t;
cin >> c;
cin >>t;
x = (x<<8 )+ t;
cin >>c;
cin >> t;
x = (x<<8) + t;
return x;
}
inline long gethead(long x, long len)
{
if (len == 0) return 0;
return
x & (0xfffffffful - ((0x80000000ul >> (len-1)) - 1));
}
void printl(long x)
{
cout << bitset<32>(x) << endl;
}
int n,mm;
int main()
{
nosync;
cin >> n >> mm;
rep0(i,n)
{
string s;
cin >> s;
long t = 0;
long x = getip();
if (cin.peek()=='/')
{
cin.get();
cin >> t;
long mask = gethead(x, t);
if (m[t].find(mask) == m[t].end())
{
m[t][mask] = make_pair(s=="allow", i);
}
//cout << "x=";
//printl(x);
//cout << "t=";
//printl(mask);
} else
{
if (m[32].find(x) == m[32].end())
{
m[32].insert(make_pair(x, make_pair(s=="allow", i)));
}
}
}
rep0(i,mm)
{
long x = getip();
int mincnt = 1000000;
bool result = true;
rep0(j, 33)
{
long y = gethead(x, j);
//printl(x);
//printl(y);
if (m[j].find(y) != m[j].end())
{
pair<bool, int> p = m[j][y];
if (p.second < mincnt)
{
mincnt = p.second;
result = p.first;
}
}
}
cout << (result ? "YES" : "NO") << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment