File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` cpp
2+ #include < bits/stdc++.h>
3+ using namespace std ;
4+ using ll = long long ;
5+
6+ int Q;
7+ multiset<string> a, b;
8+
9+ int main () {
10+ cin.tie(0)->sync_with_stdio(0);
11+
12+ cin>>Q;
13+ for(string o, s;Q--;) {
14+ cin>>o>>s;
15+ if(o == "find") {
16+ ll ans = 0;
17+ string tmp = "";
18+ int acnt[1000]{};
19+ for(int i=0;i<s.size()-1;i++) {
20+ tmp += s[i];
21+ acnt[i] = a.count(tmp);
22+ }
23+ tmp = "";
24+ reverse (s.begin(), s.end());
25+ for(int i=0;i<s.size()-1;i++) {
26+ tmp += s[ i] ;
27+ ans += acnt[ s.size()-2-i] * b.count(tmp);
28+ }
29+ cout<<ans<<'\n';
30+ }
31+ else {
32+ bool rev = s == "B";
33+ bool add = o == "add";
34+ auto &c = rev ? b : a;
35+ cin>>s;
36+ if(rev) reverse(s.begin(), s.end());
37+
38+ string tmp = "";
39+ for(char j: s ) {
40+ tmp += j;
41+ if(add) c.insert(tmp);
42+ else c.erase(c.find(tmp));
43+ }
44+ }
45+ }
46+
47+ }
48+ ```
You can’t perform that action at this time.
0 commit comments