Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define F first
- #define S second
- #define ll long long
- #define ull unsigned long long
- #define ld long double
- #define SELO ""
- #define openfiles ifstream cin("input" SELO ".txt"); ofstream cout("output" SELO ".txt");
- #define faster ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
- #define all(x) x.begin(), x.end()
- using namespace std;
- vector <pair <pair <ll, ll>, char > > v;
- vector <ll> symbols_Count;
- int main()
- {
- openfiles
- string s;
- cin >> s;
- ll t = 0;
- for(int i = 0; i < s.size(); i++)
- {
- int kol = 0;
- int j = i;
- while(s[j] >= '0' && s[j] <= '9')
- {
- kol = 10 * kol + (s[j] - '0');
- j++;
- }
- char cur_Letter = s[j];
- kol = max(kol, 1);
- v.push_back({{0, kol - 1}, cur_Letter});
- if(v.size() > 1)
- {
- v[v.size() - 1].F.F += v[v.size() - 2].F.S + 1;
- v[v.size() - 1].F.S += v[v.size() - 2].F.S + 1;
- }
- t = j;
- symbols_Count.push_back(t);
- i = j;
- }
- int q;
- cin >> q;
- while(q--)
- {
- ll l, r;
- cin >> l >> r;
- l--;
- r--;
- pair <pair <ll, ll>, char> zzz = {{l, 1000000000000000ll}, 'z'};
- int j1 = (int)(upper_bound(all(v), zzz) - v.begin()) - 1;
- zzz.F.F = r;
- int j2 = (int)(upper_bound(all(v), zzz) - v.begin()) - 1;
- ll ans = 0;
- if(j2 != j1)
- {
- ans = symbols_Count[j2 - 1] - symbols_Count[j1];
- ll kol1 = v[j1].F.S - l + 1;
- int jjj = 0;
- if(kol1 != 1)
- while(kol1)
- {
- jjj++;
- kol1 /= 10;
- }
- ans += 1 + jjj;
- kol1 = r - v[j2].F.F + 1;
- jjj = 0;
- if(kol1 != 1)
- while(kol1)
- {
- jjj++;
- kol1 /= 10;
- }
- ans += 1 + jjj;
- }
- else
- {
- ll kol1 = r - l + 1;
- int jjj = 0;
- if(kol1 != 1)
- while(kol1)
- {
- jjj++;
- kol1 /= 10;
- }
- ans += 1 + jjj;
- }
- cout << ans << '\n';
- }
- }
Add Comment
Please, Sign In to add comment