Korotkodul

div2_C_15.07_ОТКУДА WA на 2м тесте?

Jul 15th, 2022 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17.     for (auto x: v) cout<<x<<' ';
  18.     cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22.     for (auto x: v) cout<<x<<' ';
  23.     cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28.     for (auto x: v) cv(x);
  29.     cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33.     for (bool x: v) cout<<x<<' ';
  34.     cout<<"\n";
  35. }
  36.  
  37. void cvs(vector <string>  v){
  38.     for (auto a: v){
  39.         cout<<a<<"\n";
  40.     }
  41. }
  42.  
  43. bool sh = 0;
  44.  
  45. int main()
  46. {
  47.     ios::sync_with_stdio(0);
  48.     cin.tie(0);
  49.     cout.tie(0);
  50.     int t; cin>>t;
  51.     for (int go=0;go<t;++go){
  52.         int c,n,q;
  53.         cin>>n>>c>>q;
  54.         string s; cin>>s;
  55.         vector <pii> bnd  = {  {1, n}   };
  56.         for (int i=0;i<c;++i){
  57.             int l,r; cin>>l>>r;
  58.             //l--; r--;
  59.             bnd.push_back({l,r});
  60.         }
  61.         vector <int> pf(c+1);
  62.         pf[0] = n;
  63.         for (int i=1;i<c+1;++i){
  64.             pf[i] = pf[i-1] + bnd[i].second - bnd[i].first + 1;
  65.         }
  66.         for (int look = 0; look < q; ++look){
  67.             int k; cin>>k;
  68.             while (k > n){
  69.                 if (sh) cout<<"k = "<<k<<"\n";
  70.                 int L = -1, R = c,M;
  71.                 //cout<<"L R = "<<L<<' '<<R<<"\n";
  72.                 //cout<<"(L + R) / 2 = "<<((L+R)/2)<<"\n";
  73.                 while (L+1<R){
  74.  
  75.                     M = (L + R) / 2;
  76.                     if (sh) cout<<"M = "<<M<<"\n";
  77.                     if (M == 0 && pf[M] >= k){
  78.                         if (sh) cout<<"R = 0 - here is k\n";
  79.                         R = 0;
  80.                         break;
  81.                     }
  82.                     if (k > pf[M]){
  83.                         if (sh) cout<<"less than k\n";
  84.                         L = M;
  85.                     }
  86.                     else {
  87.                         if (sh) cout<<"<= than k\n";
  88.                         R = M;
  89.                     }
  90.                 }
  91.                 if (sh) cout<<"R = "<<R<<"\n";
  92.                 //k-й символ в R-й ячейке {l,r}
  93.                 int id = k;
  94.                 if (sh) cout<<"id = "<<id<<"\n";
  95.                 if (R > 0){
  96.                     id -= pf[R-1];
  97.                     //id++;
  98.                 }
  99.                 if (sh) cout<<"id = "<<id<<"\n";
  100.                 if (sh) cout<<"bnd[R] = "<<bnd[R].first<<' '<<bnd[R].second<<"\n";
  101.                 id = id + bnd[R].first - 1;
  102.                 if (sh) cout<<"id = "<<id<<"\n";
  103.                 k = id;
  104.             }
  105.             if (sh) cout<<"res k = "<<k<<"\n";
  106.             cout<<s[k-1]<<"\n";
  107.         }
  108.  
  109.     }
  110. }
  111. /*
  112. 1
  113. 4 3 3
  114. mark
  115. 1 4
  116. 5 7
  117. 3 8
  118. 1
  119. 10
  120. 12
  121.  
  122.  
  123.  
  124. 1
  125. 4 3 1
  126. mark
  127. 1 4
  128. 5 7
  129. 3 8
  130. 10
  131.  
  132. 1
  133. 5 2 12
  134. hello
  135. 1 2 3 4 5 6 7 8 9 10 11 12
  136.  
  137.  
  138. 1
  139. 4 3 18
  140. fuck
  141. 1 2
  142. 4 6
  143. 1 9
  144. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  145. */
  146.  
Add Comment
Please, Sign In to add comment