Advertisement
a53

subsir

a53
Aug 23rd, 2022
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define mod 1000000007
  6. ifstream fin("subsir.in");
  7. ofstream fout("subsir.out");
  8.  
  9. int main()
  10. {
  11. int c,n,nr;
  12. fin>>c>>n;
  13. vector<int> s(n);
  14. for (int i=0; i<n; ++i)
  15. fin>>s[i];
  16. fin>>nr;
  17. vector<vector<int>> p(10, vector<int>(n+2)); /// p[i][j] - first i after j
  18. for (int i=0; i<10; ++i)
  19. {
  20. p[i][n-1] = s[n-1] == i ? n-1 : n;
  21. p[i][n] = p[i][n+1] = n;
  22. for (int j=n-2; j>=0; --j)
  23. p[i][j] = s[j] == i ? j : p[i][j+1];
  24. }
  25. /// q[i] - min prefix where i is in s
  26. /// pf[i] - how many numbers up to i are in s
  27. vector<int> q(10000001), pf(10000001);
  28. for (int i=0; i<=10000000; ++i)
  29. {
  30. q[i] = i/10 ? p[i%10][q[i/10]+1] : p[i%10][0];
  31. pf[i] = i>0 ? pf[i-1] + (q[i] < n) : (q[i] < n);
  32. }
  33. for (int i=0; i<nr; ++i)
  34. {
  35. if (c == 1)
  36. {
  37. int x, j;
  38. fin>>x>>j;
  39. --j;
  40. fout<<(q[x] <= j)<<'\n';
  41. }
  42. else
  43. {
  44. int a,b;
  45. fin>>a>>b;
  46. fout<<(a == 0 ? pf[b] : pf[b]-pf[a-1])<<'\n';
  47. }
  48. }
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement