fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int MAX_N = 500005;
  6.  
  7. int n, k, numQuery;
  8. int a[MAX_N];
  9.  
  10. int main() {
  11. ios_base::sync_with_stdio(0);
  12. cin.tie(0);
  13. cout.tie(0);
  14.  
  15. freopen("XMAS.inp", "r", stdin);
  16. freopen("XMAS.out", "w", stdout);
  17.  
  18. cin >> n >> k;
  19. for (int i = 1; i <= n; i++) {
  20. cin >> a[i];
  21. }
  22. cin >> numQuery;
  23.  
  24. while (numQuery--) {
  25. int left, right;
  26. cin >> left >> right;
  27. stack<int> st;
  28.  
  29. for (int i = left; i <= right; i++) {
  30. if (st.empty()) {
  31. st.push(a[i]);
  32. } else if (st.top() + a[i] != k) {
  33. st.push(a[i]);
  34. } else {
  35. st.pop();
  36. }
  37. }
  38.  
  39. cout << (st.empty() ? "YES\n" : "NO\n");
  40. }
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty