Advertisement
KiK0S

Untitled

Jan 24th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <set>
  5. #include <queue>
  6. #include <algorithm>
  7. #include <string>
  8. #include <cmath>
  9. #include <cstdio>
  10. #include <iomanip>
  11. #include <fstream>
  12. #include <cassert>
  13. #include <cstring>
  14. #include <unordered_set>
  15. #include <unordered_map>
  16. #include <numeric>
  17. #include <ctime>
  18. #include <bitset>
  19. #include <complex>
  20. using namespace std;
  21.  
  22. typedef long long ll;
  23.  
  24. #define int ll
  25.  
  26. #ifdef DEBUG
  27.     const int MAXN = 10;
  28. #else
  29.     const int MAXN = 1e2 + 100;
  30. #endif
  31. int n, m;
  32.  
  33. const int K = 1e18;
  34.  
  35. int a[MAXN];
  36. int b[MAXN];
  37. int c[MAXN];
  38. int d[MAXN];
  39. int t[4 * MAXN];
  40. int ans[MAXN];
  41.  
  42. void upd(int v, int tl, int tr, int pos, int x, int tb = 0) {
  43.     if (tb > 20) {
  44.         exit(1);
  45.     }
  46.     if (tl == tr) {
  47.         t[v] += x;
  48.         return;
  49.     }
  50.     int tm = (tl + tr) >> 1;
  51.     if (pos <= tm) {
  52.         upd(2 * v, tl, tm, pos, x, tb + 1);
  53.     }
  54.     else {
  55.         upd(2 * v + 1, tm + 1, tr, pos, x, tb + 1);
  56.     }
  57.     t[v] += x;
  58. }
  59.  
  60. int get(int v, int tl, int tr, int x, int y, int tb = 0) {
  61.     if (tb > 20) {
  62.         exit(1);
  63.     }
  64.     if (tl >= tr) {
  65.         if (c[tl] == 0 || x == 0) {
  66.             return tl;
  67.         }
  68.         int total = (x + c[tl] - 1) / c[tl];
  69.         // cerr << total << '\n';
  70.         if (y * total >= d[tl]) {
  71.             return tl + 1;
  72.         }
  73.         return tl;
  74.     }
  75.     int tm = (tl + tr) >> 1;
  76.     if (t[2 * v] > x) {
  77.         return get(2 * v, tl, tm, x, y, tb + 1);
  78.     }
  79.     else {
  80.         return get(2 * v + 1, tm + 1, tr, x - t[2 * v], y, tb + 1);
  81.     }
  82. }
  83.  
  84. void rebuild(int attack) {
  85.     memset(t, 0, sizeof(t));
  86.     for (int i = 0; i < m; i++) {
  87.         upd(1, 0, m, i, (d[i] + attack - 1) / attack * c[i]);
  88.     }
  89. }
  90.  
  91. struct ev {
  92.     int x;
  93.     int type;
  94.     int val;
  95.     ev(){}
  96.     ev(int _x, int _type, int _val) {
  97.         x = _x, type = _type, val = _val;
  98.     }
  99. };
  100.  
  101. inline void init() {
  102.  
  103. }
  104.  
  105. inline void solve() {
  106.     init();
  107.     vector<int> id(n);
  108.     for (int i = 0; i < n; i++) {
  109.         cin >> a[i] >> b[i];
  110.         id[i] = i;
  111.     }
  112.     for (int i = 0; i < m; i++) {
  113.         cin >> c[i] >> d[i];
  114.     }
  115.     sort(id.begin(), id.end(), [&] (int x, int y) {
  116.         return a[x] < b[x];
  117.     });
  118.     int current_attack = 0;
  119.     for (auto x : id) {
  120.         if (a[x] >= K * 100) {
  121.             break;
  122.         }
  123.         if (a[x] != current_attack) {
  124.             rebuild(a[x]);
  125.             current_attack = a[x];
  126.         }
  127.         ans[x] = get(1, 0, m, b[x], a[x]);
  128.     }
  129.     for (int i = 0; i < n; i++) {
  130.         cout << min(ans[i], m) << '\n';
  131.     }
  132. }
  133.  
  134. signed main() {
  135.     #ifdef DEBUG
  136.         freopen("D.in", "r", stdin);
  137.         freopen("D.out", "w", stdout);
  138.     #else
  139.    
  140.     #endif
  141.     ios_base::sync_with_stdio(0);
  142.     cin.tie(0);
  143.     cout.tie(0);
  144.     cin >> n >> m; 
  145.     solve();
  146.     return 0;
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement