Skip to content

Commit e798c12

Browse files
authored
Merge pull request #1170 from AlgorithmWithGod/khj20006
[20251020] BOJ / P5 / AB / 권혁준
2 parents d2e88ea + 3285c0b commit e798c12

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

khj20006/202510/20 BOJ P5 AB.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
```

0 commit comments

Comments
 (0)