Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int maxn = 200500;
- int n, m;
- int a[maxn], b[maxn], c[maxn], KEK[maxn];
- void f(int& from, int &to) {
- for (int kek = 30; kek >= 0; --kek) {
- if (from&(1<<kek)) {
- if (to&(1<<kek)) ; else return;
- } else if (to&(1<<kek)) {
- from = to;
- }
- }
- }
- int main() {
- cin >> n >> m;
- for (int kek = 0; kek < n; ++kek) {
- cin >> a[kek];
- }
- for (int kek = 0; kek < m; ++kek) {
- cin >> b[kek] >> c[kek];
- }
- priority_queue<pair<int, int>> q;
- for (int i = 0; i < m; ++i) {
- q.emplace(b[i] - 1, i);
- }
- while (!q.empty()) {
- int cost, d;
- tie(cost, d) = q.top();
- q.pop();
- f(KEK[d], a[cost++]);
- if (cost < c[d]) q.emplace(cost, d);
- }
- for (int kek = 0; kek < m; ++kek) {
- cout << KEK[kek] << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement