-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.cpp~
executable file
·146 lines (143 loc) · 2.56 KB
/
test.cpp~
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
#include <iostream>
#define m l + (r - l) / 2
#define lson rx * 2, l, m
#define rson rx * 2 + 1, m + 1, r
#define MAXN 10005
using namespace std;
int tree[MAXN], add[MAXN];
void Pushdown(int rx, int l, int r)
{
if(add[rx])
{
add[rx * 2] += add[rx];
add[rx * 2 + 1] += add[rx];
tree[rx * 2] += (m - l + 1) * add[rx];
tree[rx * 2 + 1] += (r - m) * add[rx];
add[rx] = 0;
}
}
void Bulid(int rx, int l, int r)
{
add[rx] = 0;
if(l == r)
{
cin >> tree[rx];
return ;
}
Bulid(lson);
Bulid(rson);
tree[rx] = tree[rx * 2] + tree[rx * 2 + 1];
}
void Update_point(int rx, int l, int r, int pos, int v)
{
if(l > pos || r < pos) return;
if(l == r)
{
tree[rx] = v;
return ;
}
Update_point(lson, pos, v);
Update_point(rson, pos, v);
tree[rx] = tree[rx * 2] + tree[rx * 2 + 1];
}
void Update_section(int rx, int l, int r, int L, int R, int v)
{
if(R < l || L > r) return;
if(L <= l && r <= R)
{
tree[rx] += (r - l + 1) * v;
add[rx] += v;
return ;
}
Update_section(lson, L, R, v);
Update_section(rson, L, R, v);
tree[rx] = tree[rx * 2] + tree[rx * 2 + 1];
}
int Query(int rx, int l, int r, int L, int R)
{
if(R < l || L > r) return 0;
Pushdown(rx, l, r);
if(L <= l && r <= R) return tree[rx];
return Query(lson, L, R) + Query(rson, L, R);
}
int main()
{
int n, q;
cin >> n >> q;
Bulid(1, 1, n);
while(q--)
{
int op;
cin >> op;
if(op == 1)
{
int pos, v;
cin >> pos >> v;
Update_point(1, 1, n, pos, v);
}
else if(op == 2)
{
int L, R, v;
cin >> L >> R >> v;
Update_section(1, 1, n, L, R, v);
}
else
{
int L, R;
cin >> L >> R;
cout << Query(1, 1, n, L, R) << endl;
}
}
return 0;
}
*/
/*
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
struct node
{
node *next[26];
int cnt;
node()
{
for(int i = 0; i < 26; ++i)
next[i] = NULL;
cnt = 0;
}
};
void insert(node *root, char ch[], int pos)
{
if(ch[pos] == '\0') return;
if(root -> next[ch[pos] - 'a'] == NULL)
{
node *temp = new node;
root -> next[ch[pos] - 'a'] = temp;
}
root -> next[ch[pos] - 'a'] -> cnt++;
insert(root -> next[ch[pos] - 'a'], ch, pos + 1);
}
int query(node *root, char ch[], int pos)
{
if(root -> next[ch[pos] - 'a'] == NULL) return 0;
if(ch[pos + 1] == '\0') return root -> next[ch[pos] - 'a'] -> cnt;
return query(root -> next[ch[pos] - 'a'], ch, pos + 1);
}
int main()
{
node *root = new node;
char word[100];
while(true)
{
gets(word);
if(strlen(word) == 0) break;
insert(root, word, 0);
}
while(~scanf("%s", word))
printf("%d\n", query(root, word, 0));
return 0;
}
*/