Advertisement
Guest User

Untitled

a guest
May 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <vector>
  2. #include <string>
  3. #include <algorithm>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. string s;
  10. cin >> s;
  11. vector<pair<int, int>> word;
  12. int count_one = 0, count_all = 0;
  13. for (size_t i = 0; i != s.size(); ++i) {
  14. if ('a' <= s[i] && s[i] <= 'z') {
  15. if (count_one == 0 && i != 0)
  16. count_one = 1;
  17. count_all += count_one;
  18. count_one = 0;
  19. word.push_back({count_all, i});
  20. } else {
  21. count_one *= 10;
  22. count_one += s[i] - '0';
  23. }
  24. }
  25. int q;
  26. cin >> q;
  27. for (int i = 0; i != q; ++i) {
  28. int l, r;
  29. cin >> l >> r;
  30. auto it1 = lower_bound(word.begin(), word.end(), make_pair(l - 1, 0));
  31. auto it2 = lower_bound(word.begin(), word.end(), make_pair(r - 1, 0));
  32. size_t len = 0;
  33. if (it1->first != l) {
  34. len += to_string(it1->first - l + 1).size() + 1;
  35. }
  36. len += it2->second - it1->second;
  37. if (it2->first != r) {
  38. len -= to_string(it2->first - r + 1).size() + 1;
  39. }
  40. cout << len << '\n';
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement