Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- #include <set>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <cmath>
- #include <cstdio>
- #include <iomanip>
- #include <fstream>
- #include <cassert>
- #include <cstring>
- #include <unordered_set>
- #include <unordered_map>
- #include <numeric>
- #include <ctime>
- #include <bitset>
- #include <complex>
- using namespace std;
- typedef long long ll;
- #define int ll
- #ifdef DEBUG
- const int MAXN = 10;
- #else
- const int MAXN = 1e2 + 100;
- #endif
- int n, m;
- const int K = 1e18;
- int a[MAXN];
- int b[MAXN];
- int c[MAXN];
- int d[MAXN];
- int t[4 * MAXN];
- int ans[MAXN];
- void upd(int v, int tl, int tr, int pos, int x, int tb = 0) {
- if (tb > 20) {
- exit(1);
- }
- if (tl == tr) {
- t[v] += x;
- return;
- }
- int tm = (tl + tr) >> 1;
- if (pos <= tm) {
- upd(2 * v, tl, tm, pos, x, tb + 1);
- }
- else {
- upd(2 * v + 1, tm + 1, tr, pos, x, tb + 1);
- }
- t[v] += x;
- }
- int get(int v, int tl, int tr, int x, int y, int tb = 0) {
- if (tb > 20) {
- exit(1);
- }
- if (tl >= tr) {
- if (c[tl] == 0 || x == 0) {
- return tl;
- }
- int total = (x + c[tl] - 1) / c[tl];
- // cerr << total << '\n';
- if (y * total >= d[tl]) {
- return tl + 1;
- }
- return tl;
- }
- int tm = (tl + tr) >> 1;
- if (t[2 * v] > x) {
- return get(2 * v, tl, tm, x, y, tb + 1);
- }
- else {
- return get(2 * v + 1, tm + 1, tr, x - t[2 * v], y, tb + 1);
- }
- }
- void rebuild(int attack) {
- memset(t, 0, sizeof(t));
- for (int i = 0; i < m; i++) {
- upd(1, 0, m, i, (d[i] + attack - 1) / attack * c[i]);
- }
- }
- struct ev {
- int x;
- int type;
- int val;
- ev(){}
- ev(int _x, int _type, int _val) {
- x = _x, type = _type, val = _val;
- }
- };
- inline void init() {
- }
- inline void solve() {
- init();
- vector<int> id(n);
- for (int i = 0; i < n; i++) {
- cin >> a[i] >> b[i];
- id[i] = i;
- }
- for (int i = 0; i < m; i++) {
- cin >> c[i] >> d[i];
- }
- sort(id.begin(), id.end(), [&] (int x, int y) {
- return a[x] < b[x];
- });
- int current_attack = 0;
- for (auto x : id) {
- if (a[x] >= K * 100) {
- break;
- }
- if (a[x] != current_attack) {
- rebuild(a[x]);
- current_attack = a[x];
- }
- ans[x] = get(1, 0, m, b[x], a[x]);
- }
- for (int i = 0; i < n; i++) {
- cout << min(ans[i], m) << '\n';
- }
- }
- signed main() {
- #ifdef DEBUG
- freopen("D.in", "r", stdin);
- freopen("D.out", "w", stdout);
- #else
- #endif
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin >> n >> m;
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement