Advertisement
updown

Untitled

Feb 23rd, 2023
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. // typedef long long int;
  6.  
  7. const int MAXN = 100000, MAXB = 100000;
  8.  
  9. map<int, int> m;
  10. int v[MAXN];
  11. int vals[MAXN + MAXB];
  12. pair<int, int> boots[MAXB];
  13. vector<int> tiles[MAXN + MAXB];
  14. set<int> r;
  15. int mi[MAXN + MAXB];
  16.  
  17.  
  18. int main() {
  19.     freopen("snowboots.in", "r", stdin);
  20.     freopen("snowboots.out", "w", stdout);
  21.  
  22.  
  23.     int n, b;
  24.     cin >> n >> b;
  25.  
  26.    
  27.     for (int i = 0; i < n; i++) {
  28.         cin >> v[i];
  29.         vals[i]=v[i];
  30.     }
  31.  
  32.  
  33.  
  34.     for (int i = 0; i < b; i++) {
  35.         cin >> boots[i].first >> boots[i].second;
  36.         vals[n + i] = (boots[i].first);
  37.     }
  38.  
  39.     sort(vals, vals + (n+b) );
  40.     int cur = 0;
  41.     m[vals[0]]=cur;
  42.     for (int i = 1; i < n + b; i++) {
  43.         if (vals[i]!=vals[i-1])cur++;
  44.         m[vals[i]]=cur;
  45.     }
  46.  
  47.  
  48.  
  49.     for (int i = 0; i < n; i++) {
  50.         v[i]=m[v[i]];
  51.     }
  52.     for (int i = 0; i < n; i++) {
  53.         // cout << boots[i].second << m[boots[i].second] << endl;
  54.         boots[i].first=m[boots[i].first];
  55.     }
  56.  
  57.     for (int i = 1; i < n-1; i++) {
  58.         tiles[v[i]].push_back(i);
  59.     }
  60.  
  61.    
  62.     for (int i = 0; i < n; i++) r.insert(i);
  63.     int ans = 1;
  64.  
  65.     // for (auto val: v) cout << val << ' ';
  66.     // cout << endl;    
  67.     for (int d = n + b - 1; d >= 0; d--) {
  68.         // cout << d << ans << endl;
  69.         mi[d]=ans;
  70.         for (auto val: tiles[d]) {
  71.             auto it = r.find(val);
  72.             if (it == r.begin() || it == r.end() || next(it, 1) == r.end()) {
  73.  
  74.                 continue;
  75.             }
  76.             auto nextt = next(it, 1);
  77.             auto prevv = prev(it, 1);
  78.  
  79.             r.erase(it);
  80.             ans=max(ans, *nextt - *prevv);
  81.         }
  82.        
  83.        
  84.     }
  85.     for (int i = 0; i < b; i++) {
  86.         // cout << boots[i].first << boots[i].second << endl;
  87.         if (boots[i].second >= mi[boots[i].first]) {
  88.             cout << 1 << endl;
  89.         } else cout << 0 << endl;
  90.     }
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement