Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int maxn = 200500;
  5.  
  6. int n, m;
  7. int a[maxn], b[maxn], c[maxn], KEK[maxn];
  8.  
  9. void f(int& from, int &to) {
  10.     for (int kek = 30; kek >= 0; --kek) {
  11.         if (from&(1<<kek)) {
  12.             if (to&(1<<kek)) ; else return;
  13.         } else if (to&(1<<kek)) {
  14.             from = to;
  15.         }
  16.     }
  17. }
  18.  
  19. int main() {
  20.     cin >> n >> m;
  21.     for (int kek = 0; kek < n; ++kek) {
  22.         cin >> a[kek];
  23.     }
  24.     for (int kek = 0; kek < m; ++kek) {
  25.         cin >> b[kek] >> c[kek];
  26.     }
  27.     priority_queue<pair<int, int>> q;
  28.     for (int i = 0; i < m; ++i) {
  29.         q.emplace(b[i] - 1, i);
  30.     }
  31.     while (!q.empty()) {
  32.         int cost, d;
  33.         tie(cost, d) = q.top();
  34.         q.pop();
  35.         f(KEK[d], a[cost++]);
  36.         if (cost < c[d]) q.emplace(cost, d);
  37.     }
  38.     for (int kek = 0; kek < m; ++kek) {
  39.         cout << KEK[kek] << endl;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement