Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- int main() {
- string s;
- cin >> s;
- vector<pair<int, int>> word;
- int count_one = 0, count_all = 0;
- for (size_t i = 0; i != s.size(); ++i) {
- if ('a' <= s[i] && s[i] <= 'z') {
- if (count_one == 0 && i != 0)
- count_one = 1;
- count_all += count_one;
- count_one = 0;
- word.push_back({count_all, i});
- } else {
- count_one *= 10;
- count_one += s[i] - '0';
- }
- }
- int q;
- cin >> q;
- for (int i = 0; i != q; ++i) {
- int l, r;
- cin >> l >> r;
- auto it1 = lower_bound(word.begin(), word.end(), make_pair(l - 1, 0));
- auto it2 = lower_bound(word.begin(), word.end(), make_pair(r - 1, 0));
- size_t len = 0;
- if (it1->first != l) {
- len += to_string(it1->first - l + 1).size() + 1;
- }
- len += it2->second - it1->second;
- if (it2->first != r) {
- len -= to_string(it2->first - r + 1).size() + 1;
- }
- cout << len << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement