Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- bool sh = 0;
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int t; cin>>t;
- for (int go=0;go<t;++go){
- int c,n,q;
- cin>>n>>c>>q;
- string s; cin>>s;
- vector <pii> bnd = { {1, n} };
- for (int i=0;i<c;++i){
- int l,r; cin>>l>>r;
- //l--; r--;
- bnd.push_back({l,r});
- }
- vector <int> pf(c+1);
- pf[0] = n;
- for (int i=1;i<c+1;++i){
- pf[i] = pf[i-1] + bnd[i].second - bnd[i].first + 1;
- }
- for (int look = 0; look < q; ++look){
- int k; cin>>k;
- while (k > n){
- if (sh) cout<<"k = "<<k<<"\n";
- int L = -1, R = c,M;
- //cout<<"L R = "<<L<<' '<<R<<"\n";
- //cout<<"(L + R) / 2 = "<<((L+R)/2)<<"\n";
- while (L+1<R){
- M = (L + R) / 2;
- if (sh) cout<<"M = "<<M<<"\n";
- if (M == 0 && pf[M] >= k){
- if (sh) cout<<"R = 0 - here is k\n";
- R = 0;
- break;
- }
- if (k > pf[M]){
- if (sh) cout<<"less than k\n";
- L = M;
- }
- else {
- if (sh) cout<<"<= than k\n";
- R = M;
- }
- }
- if (sh) cout<<"R = "<<R<<"\n";
- //k-й символ в R-й ячейке {l,r}
- int id = k;
- if (sh) cout<<"id = "<<id<<"\n";
- if (R > 0){
- id -= pf[R-1];
- //id++;
- }
- if (sh) cout<<"id = "<<id<<"\n";
- if (sh) cout<<"bnd[R] = "<<bnd[R].first<<' '<<bnd[R].second<<"\n";
- id = id + bnd[R].first - 1;
- if (sh) cout<<"id = "<<id<<"\n";
- k = id;
- }
- if (sh) cout<<"res k = "<<k<<"\n";
- cout<<s[k-1]<<"\n";
- }
- }
- }
- /*
- 1
- 4 3 3
- mark
- 1 4
- 5 7
- 3 8
- 1
- 10
- 12
- 1
- 4 3 1
- mark
- 1 4
- 5 7
- 3 8
- 10
- 1
- 5 2 12
- hello
- 1 2 3 4 5 6 7 8 9 10 11 12
- 1
- 4 3 18
- fuck
- 1 2
- 4 6
- 1 9
- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
- */
Add Comment
Please, Sign In to add comment