-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchefAug6.cpp
More file actions
88 lines (85 loc) · 1.46 KB
/
chefAug6.cpp
File metadata and controls
88 lines (85 loc) · 1.46 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<bits/stdc++.h>
#define test int t;scanf("%d",&t);while(t--)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,long int>
#define ll long long int
#define pli pair<ll ,int>
#define CHARTOKEY(p) (key[p]-'0')
using namespace std;
int power[1000001];
ll cnt;
class Trienode
{
public:
Trienode* children[2];
bool isLeaf;
Trienode()
{
isLeaf = false;
children[0]=children[1]=NULL;
}
};
void insert(Trienode * root,long int n)
{
int index;
Trienode* pCrawl =root;
for(long int level=n-1;level>=0;level--)
{
index=power[level];
if(pCrawl->children[index]==NULL)
{
pCrawl->children[index]=new Trienode();
cnt++;
}
pCrawl = pCrawl->children[index];
}
pCrawl->isLeaf = true;
}
void convertpower(long int c,long int n)
{
while(power[c]!=0&&c<n)
{
power[c]=0;
c++;
}
if(c==n)
return;
power[c]=1;
}
int main()
{
test
{
memset(power,0,sizeof(power));
long int n,q,c;cnt=0;char ch;
scanf("%ld %ld",&n,&q);
string query;
Trienode* root=new Trienode();
while(q--)
{
scanf("\n%c",&ch);
if(ch=='!')
{
scanf("%ld",&c);
convertpower(c,n);
insert(root,n);
}
else
printf("%lld\n",cnt+1);
}
}
return 0;
}
/*bool search(Trienode *root,const char *key)
{
int length=strlen(key),index;
Trienode* pCrawl =root;
loop(level,0,length)
{
index=CHARTOINDEX(key[level]);
if(!pCrawl->children[index])
return false;
pCrawl = pCrawl->children[index];
}
return (pCrawl != NULL && pCrawl->isLeaf);
}*/