fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int MAX_N = 500005;
  6.  
  7. int n, k, a[MAX_N], p[MAX_N], ip[MAX_N];
  8. int numQuery, l[MAX_N], r[MAX_N];
  9. bool ans[MAX_N];
  10. vector<int> ids[MAX_N];
  11. map<int, int> mark[MAX_N];
  12. map<int, bool> reach[MAX_N];
  13.  
  14. int main() {
  15. ios_base::sync_with_stdio(0);
  16. cin.tie(0);
  17. cout.tie(0);
  18.  
  19. freopen("XMAS.inp", "r", stdin);
  20. freopen("XMAS.out", "w", stdout);
  21.  
  22. cin >> n >> k;
  23. for (int i = 1; i <= n; i++) {
  24. cin >> a[i];
  25. }
  26. cin >> numQuery;
  27. for (int i = 1; i <= numQuery; i++) {
  28. cin >> l[i] >> r[i];
  29. ids[r[i]].push_back(i);
  30. }
  31.  
  32. a[0] = -1;
  33. reach[0][0] = true;
  34. for (int i = 1; i <= n; i++) {
  35. p[i] = mark[i - 1][k - a[i]];
  36. ip[p[i]] = i;
  37. if (p[i]) {
  38. swap(mark[i], mark[p[i] - 1]);
  39. swap(reach[i], reach[p[i] - 1]);
  40. }
  41. mark[i][a[i]] = i;
  42. reach[i][i] = true;
  43. for (int id : ids[i]) {
  44. ans[id] = reach[r[id]][l[id] - 1];
  45. }
  46. }
  47.  
  48. for (int i = 1; i <= numQuery; i++) {
  49. cout << (ans[i] ? "YES\n" : "NO\n");
  50. }
  51.  
  52. return 0;
  53. }
Success #stdin #stdout 0.02s 64908KB
stdin
Standard input is empty
stdout
Standard output is empty