主席树裸上就好了。。。不过写了一会儿。。。因为姿势比较厉(gui)害(chu)

 

  1 /**************************************************************
  2     Problem: 3932
  3     User: rausen
  4     Language: C++
  5     Result: Accepted
  6     Time:2868 ms
  7     Memory:98560 kb
  8 ****************************************************************/
  9  
 10 #include <cstdio>
 11 #include <algorithm>
 12  
 13 using namespace std;
 14 typedef long long ll;
 15 const int N = 1e5 + 5;
 16 const int P = 1e7;
 17  
 18 inline int read();
 19  
 20 struct chair_tree {
 21     chair_tree *ls, *rs;
 22     int sz;
 23     ll sum;
 24      
 25     #define Len (1 << 16)
 26     void* operator new(size_t, int x, ll y, chair_tree *L = NULL, chair_tree *R = NULL) {
 27         static chair_tree *mempool, *c;
 28         if (c == mempool)
 29             mempool = (c = new chair_tree[Len]) + Len;
 30         c -> ls = L, c -> rs = R, c -> sz = x, c -> sum = y;
 31         return c++;
 32     }
 33     void* operator new(size_t, chair_tree *p) {
 34         static chair_tree *mempool, *c;
 35         if (c == mempool)
 36             mempool = (c = new chair_tree[Len]) + Len;
 37         *c = *p;
 38         return c++;
 39     }
 40     #undef Len
 41      
 42     #define mid (l + r >> 1)
 43     void modify(int l, int r, int pos, int d_sz, ll d_sum) {
 44         this -> sz += d_sz, this -> sum += d_sum;
 45         if (l == r) return;
 46         if (pos <= mid) this -> ls = new(this -> ls)chair_tree, this -> ls -> modify(l, mid, pos, d_sz, d_sum);
 47         else this -> rs = new(this -> rs)chair_tree, this -> rs -> modify(mid + 1, r, pos, d_sz, d_sum);
 48     }
 49      
 50     ll kth(int l, int r, int k) {
 51         if (l == r) return 1ll * mid * min(k, this -> sz);
 52         if (k <= this -> ls -> sz) return this -> ls -> kth(l, mid, k);
 53         else return this -> rs -> kth(mid + 1, r, k - this -> ls -> sz) + this -> ls -> sum;
 54     }
 55     #undef mid
 56 } *chair[N];
 57  
 58 struct data {
 59     int t, v, del;
 60     data(int _t = 0, int _v = 0, int _d = 0) : t(_t), v(_v), del(_d) {}
 61      
 62     inline bool operator < (const data &p) const {
 63         return t < p.t;
 64     }
 65 } a[N << 1];
 66  
 67 int n, m, k;
 68 ll ans;
 69  
 70 int main() {
 71     int i, j, A, B, C, x, y, z;
 72     m = read(), n = read();
 73     for (i = 1; i <= m; ++i) {
 74         x = read(), y = read(), z = read();
 75         a[i * 2 - 1] = data(x, z, 1);
 76         a[i * 2] = data(y + 1, z, -1);
 77     }
 78     sort(a + 1, a + m * 2 + 1);
 79     chair[0] = new(0, 0)chair_tree;
 80     chair[0] -> ls = chair[0] -> rs = chair[0];
 81      
 82     for (i = j = 1; i <= n; ++i) {
 83         chair[i] = new(chair[i - 1])chair_tree;
 84         for (; j <= m << 1 && a[j].t == i; ++j)
 85             chair[i] -> modify(1, P, a[j].v, a[j].del, a[j].v * a[j].del);
 86     }
 87     for (i = ans = 1; i <= n; ++i) {
 88         x = read(), A = read(), B = read(), C = read();
 89         k = (A * ans + B) % C + 1;
 90         printf("%lld\n", ans = chair[x] -> kth(1, P, k));
 91     }
 92     return 0;
 93 }
 94  
 95 inline int read() {
 96     static int x;
 97     static char ch;
 98     x = 0, ch = getchar();
 99     while (ch < '0' || '9' < ch)
100         ch = getchar();
101     while ('0' <= ch && ch <= '9') {
102         x = x * 10 + ch - '0';
103         ch = getchar();
104     }
105     return x;
106 }
View Code

 

posted on 2015-04-25 23:00  Xs酱~  阅读(251)  评论(0编辑  收藏  举报