记录编号 382176 评测结果 AAAAAAAAAA
题目名称 [CQOI2015]任务查询系统 最终得分 100
用户昵称 Gravatarsxysxy 是否通过 通过
代码语言 C++ 运行时间 2.463 s
提交时间 2017-03-13 10:43:30 内存使用 2.47 MiB
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <cctype>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
namespace IO{
  char buf[1<<18], *fs, *ft;
  inline char readc(){
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<18,stdin)),fs==ft)?EOF:*fs++;
  }
  inline int readint(){
    char c; int r;
    while(c = readc()){if(c >= '0' && c <= '9'){r = c^0x30;break;}}
    while(isdigit(c = readc()))r = (r<<3)+(r<<1)+(c^0x30);
    return r;
  }
  inline int read_string(char *str){
    int len = 1;char c;
    while(!isalpha(c = readc()));str[0] = c;
    while(isalpha(c = readc()))str[len++] = c;
    str[len] = 0;
    return len;
  }
};using IO::read_string; using IO::readint;
typedef long long LL;
const int MAXM = 1e5+5;
struct que{
  int pos; //position
  int val; //value
  int tag; //1 add, -1 del
  bool operator<(const que &q)const{return pos < q.pos;}
}; vector<que> qs;
struct node{
  node *ls, *rs;
  int size;
  LL sum;
  node(){
    memset(this, 0, sizeof(node));
  }
}; node *roots[MAXM<<2];
node *build(int l, int r){
  node *d = new node();
  if(l < r){
    int m = (l+r)>>1;
    d->ls = build(l, m);
    d->rs = build(m+1, r);
  }
  return d;
}
int a[MAXM];
node *insert(node *last, int p, int dv, int L, int R){
  if(!last)return NULL;
  node *d = new node();
  *d = *last;
  d->size += dv;
  d->sum += (LL)a[p]*dv;
  if(L < R){
    int M = (L+R)>>1;
    if(p <= M)d->ls = insert(last->ls, p, dv, L, M);
    else if(p > M)d->rs = insert(last->rs, p, dv, M+1, R);
  }
  return d;
}
LL query(node *x, int k, int L, int R){
  if(!x)return 0;
  if(L == R)return x->sum/x->size*k;
  int lsz = x->ls?x->ls->size:0;
  int M = (L+R)>>1;
  if(k <= lsz)return query(x->ls, k, L, M);
  else return (x->ls?x->ls->sum:0)+query(x->rs, k-lsz, M+1, R);
}
int main(){
//  freopen("test_data.txt", "r", stdin);
  freopen("cqoi15_query.in", "r", stdin);
  freopen("cqoi15_query.out", "w", stdout);
  int n = readint();
  int m = readint();
  for(int i = 1; i <= n; i++){
    int s, t, p; s = readint(); t = readint(); p = readint();
    qs.push_back((que){s, p, 1});
    qs.push_back((que){t+1, p, -1});
    a[i] = p;
  }
  sort(a+1, a+1+n);
  sort(qs.begin(), qs.end());
  roots[0] = build(1, m);
  for(int i = 1, j = 0; i <= m; i++){
    roots[i] = roots[i-1];
    for(; j < qs.size() && qs[j].pos == i; j++){
      int pos = lower_bound(a+1, a+1+n, qs[j].val)-a;
      roots[i] = insert(roots[i], pos, qs[j].tag, 1, m);
    }
  }
  LL ans = 1;
  for(int i = 1; i <= m; i++){
    int x = readint();
    int A = readint(); int B = readint(); int C = readint();
    int k = ((LL)A*ans+B)%C+1;
    if(k >= roots[x]->size)ans = roots[x]->sum;
    else ans = query(roots[x], k, 1, m);
    printf("%lld\n", ans);
  }
  return 0;
}