Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int main()
- {
- int n, q;
- string s;
- cin >> n >> s >> q;
- // map<char, int> count;
- vector<int> positions;
- int pos = 0, count = 0;
- while ((pos = s.find("PSU", pos)) != string::npos) {
- ++count;
- positions.push_back(pos);
- pos += 3;
- }
- cout << count << endl;
- char ch;
- for (int i = 0; i < q; i++)
- {
- cin >> pos >> ch;
- pos--;
- bool a = false, b = false, c = false;
- if (pos - 2 >= 0)
- {
- if (s.substr(pos - 2, 3) == "PSU")
- a = true;
- // cout << 0 << s.substr(pos - 2, 3) << endl;
- }
- if (pos - 1 >= 0)
- {
- if (s.substr(pos - 1, 3) == "PSU")
- b = true;
- // cout << 1 << s.substr(pos - 1, 3) << endl;
- }
- if (s.substr(pos, 3) == "PSU")
- c = true;
- // cout << 2 << s.substr(pos, 3) << endl;
- // cout << "CHANGE" << endl;
- s[pos] = ch;
- if (pos - 2 >= 0)
- {
- // cout << s.substr(pos - 2, 3) << endl;
- if (s.substr(pos - 2, 3) == "PSU" && !a)
- count++;
- else if (s.substr(pos - 2, 3) != "PSU" && a)
- count--;
- }
- if (pos - 1 >= 0)
- {
- // cout << s.substr(pos - 1, 3) << endl;
- if (s.substr(pos - 1, 3) == "PSU" && !b)
- count++;
- else if (s.substr(pos - 1, 3) != "PSU" && b)
- count--;
- }
- // cout << 2 << s.substr(pos, 3) << endl;
- if (s.substr(pos, 3) == "PSU" && !c)
- count++;
- else if (s.substr(pos, 3) != "PSU" && c)
- count--;
- // cout << s << endl;
- cout << count << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement