Exemple #1
0
int main() {
	ios_base::sync_with_stdio(false);

	int n, m, k;
	int x, y;

	cin >> n >> m >> k;	

	op.init(m+10);
	a.init(n+10);

	for (int i=1; i<=n; ++i) {
		cin >> x;
		a.add_interval(i, i, x);
	}
	for (int i=1; i<=m; ++i) cin >> l[i] >> r[i] >> d[i];
	for (int i=0; i<k; ++i) {
		cin >> x >> y;	
		op.add_interval(x, y, 1);
	}
	for (int i=1; i<=m; ++i) a.add_interval(l[i], r[i], op.sum(i)*d[i]);
	for (int i=1; i<=n; ++i) cout << a.sum(i) << (i < n ? " " : "\n");

	return 0;
}
Exemple #2
0
	void init(Graph *g)
	{
		G=g;
		bit.init(G->ndn);
		dfst=0; dept[1] = 0; fath[1] = 0;
		CLR(dfsn); CLR(bson); CLR(ntop);
		dfs1(1);
		dfs2(1,1);
	}
Exemple #3
0
int main() {
    while (~sf("%d", &n)) {
        REP(i, n) {
            sf("%s", op[i]);
            if (op[0] == 'D' || op[0] == 'Q') {
                sf("%d%d", &seg[i][0], &seg[i][1]);
                b.pb(seg[i][0]);
                b.pb(seg[i][1]);
            }
            else {
                sf("%d", &seg[i][0]);
                b.pb(seg[i][0]);
            }
        }
        sort(all(b));
        b.resize(unique(all(b))-b.begin());
        le.init(b.size());
        ri.init(b.size());
    }
Exemple #4
0
int main()
{
	#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	#endif
	
	int T;
	scanf("%d", &T);
	for(int ck=1; ck<=T; ck++)
	{
		scanf("%d", &Q);
		D.siz=0;
		CLR(ans);
		
		int scnt=0;
		for(int i=1; i<=Q; i++)
		{
			int opt,l,r;
			scanf("%d%d", &opt, &l);
			arry[i].t=i;
			if(!opt)
			{
				scanf("%d", &r);
				scnt++;
				inpt[scnt][0] = l;
				inpt[scnt][1] = r;
				inpt[scnt][2] = i;
				arry[i].l = l;
				arry[i].r = r;
				arry[i].v = 1;
				D.add(l); D.add(r);
			}
			else
			{
				arry[i].l = inpt[l][0];
				arry[i].r = inpt[l][1];
				arry[i].v = -1;
			}
		}
		D.init();
		bit.init(D.siz);
		for(int i=1; i<=Q; i++)
		{
			arry[i].l = D.id(arry[i].l);
			arry[i].r = D.id(arry[i].r);
		}
		
		CDQ(1,Q);
		
		for(int i=1; i<=scnt; i++) printf("%d\n", ans[ inpt[i][2] ]);
	}
	return 0;
}
	int getMinimumInversions(vector <int> A, vector <int> B, vector <int> V, int K) {
		n = (int)A.size();
		edge = IVV(n);
		vertex = V;
		for (int i = 0; i < n; ++i) {
			edge[A[i]].push_back(B[i]);
			edge[B[i]].push_back(A[i]);
		}

		int ans = 1e6;
		for (int i = 0; i < n; ++i) {
			memset(visited, 0, sizeof(visited));
			bit.init(1001);
			ans = min(ans, dfs(i, K));
		}
		return (ans < 1e6) ? ans : -1;
	}
int main() {
	int C = 0, T, q, x, y;
	scanf("%d", &T);
	while (++C <= T) {
		bit.init();
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) {
			scanf("%d", &x);
			bit.modify(i, x);
		}
		scanf("%d", &q);
		while (q--) {
			scanf("%d %d", &x, &y);
			printf("%d\n", bit.query(x, y));
		}
	}
}
Exemple #7
0
int calc(int p) {
  printf("calc(%d)\n", p);
  int cnt[20];
  memset(cnt, 0, sizeof cnt);
  int max_power = 0;
  memset(power, 0, sizeof power);
  for(int i = 0; i < n; i++) {
    int num = v[i];
    while(num % p == 0) {
      power[i]++;
      num /= p;
    }
    cnt[power[i]]++;
    max_power = max(max_power, power[i]);
  }
  printf("max_power=%d ", max_power);
  bit.init();
  for(int i = 1; i <= max_power; i++) {
    bit.add(i, cnt[i]);
  }
  int ans = 0;
  int cur = p;
  int base[20];
  for(int i = 1; cur <= maxa; i++) {
    base[i] = cur;
    cur = (cur * 1LL * p) % mod;
  }
  for(int i = 0; i < n; i++) {
    if(power[i] == 0)
      continue;
    printf("total(%d - %d)=%d ", bit.sum(max_power), bit.sum(power[i] - 1), total(bit.sum(max_power) - bit.sum(power[i] - 1)));
    ans = (ans + (base[power[i]] * 1LL * total(bit.sum(max_power) - bit.sum(power[i] - 1))) % mod) % mod;
    printf("i=%d ans=%d ", i, ans);
    for(int j = power[i] - 1; j >= 1; j--) {
      ans = (ans + (base[j] * 1LL * total(cnt[j])) % mod) % mod;
      printf("cnt[%d]=%d ans=%d ", j, cnt[j], ans);
    }
    printf("ans=%d\n", ans);
    cnt[power[i]]--;
    bit.add(power[i], -1);
  }
  return ans;
}
Exemple #8
0
int main() {

  int x, r, h;
  int a, b;

  scanf("%d%d", &N, &Q);
  bit.init(MAX_X + MAX_H);
  for (int i = 0; i < N; i++) {
    scanf("%d%d%d", &x, &r, &h);
    for (int j = 0; j < h; j++) {
      bit.add(x + j + 1, (double)r * r * M_PI * h * 1.0/3.0 * (pow(h - j, 3) - pow(h - j - 1, 3)) / pow(h, 3));
    }
  }

  for (int i = 0; i < Q; i++) {
    scanf("%d%d", &a, &b);
    ans = bit.sum(b) - bit.sum(a);
    printf("%lf\n", ans);
  }

  return 0;

}
Exemple #9
0
 void init() {
   bit.init();
   REP(i,MXN) col[i].clear();
 }
Exemple #10
0
int main()
{
    int T, ca=0, ti = 0, a, bb, sum, le, ri;
    char op[10];
    vi p1, p2;
    scanf("%d", &T);
    while (T--)
    {
          scanf("%d%d%d", &n, &Q, &t);
        //  n+=2;
          ans.init();
          seg.init();
          point.clear();
          ti=0;
          printf("Case %d:\n", ++ca);
          for (int i=0; i<Q; i++)
          {
              scanf("%s", op);
              if (op[0]=='A')
              {
                  ti++;
                  scanf("%d%d", &que[ti][0], &que[ti][1]);
                  que[ti][0] += 2; que[ti][1] += 2;
              //    cout <<ti << " "<<t<<endl;
                  if (ti-t>=1) 
                  {
                      seg.insert_seg(que[ti-t][0], que[ti-t][1], -1);
                      point.erase(lower_bound(point.begin(), point.end(), que[ti-t][0]));
                      point.erase(lower_bound(point.begin(), point.end(), que[ti-t][1]));                                                         
                  }
                  if (point.size()>=2){
                  vi pp = point.end();
                  pp--;
                  le = max(*point.begin(), que[ti][0]); 
                  ri = min(*pp, que[ti][1]);
                  if (le > ri)
                  {
                     le = que[ti][0];
                     ri = que[ti][1];                         
                  }
                  cout <<le-2 <<" "<<ri-2 <<"----"<<*point.begin() <<" "<<*pp <<endl;
                  ans.updata(ri-2, 1);
                  ans.updata(le-1-2, -1);
                  }
                  point.insert(que[ti][0]);
                  point.insert(que[ti][1]);                  
                  if (ti-t>=1)
                  {
                     le = max(que[ti-t][0], le);
                     ri = min(ri, que[ti-t][1]);
                     cout <<le-2 <<" "<<ri-2<<"  recovery" <<endl;
                     ans.updata(ri-2, -1);
                     ans.updata(le-1-2, 1);                             
                         
                   le = n+2; ri = 2;
                   if (ti-t-1>=1){
                      for (int j=ti-t-1; j+t>=ti-t && j+t<ti; j--)
                      {
                        //  if (j < 1) break;
                          le = min(le, que[j][0]);
                          ri = max(ri, que[j][1]);    
                      }
                      le = max(le, que[ti-t][0]);
                      ri = min(ri, que[ti-t][1]);
                   //   cout <<le-2 <<" "<<ri-2<<" add" <<endl;
                      ans.updata(ri-2, 1);
                      ans.updata(le-1-2, -1);        
                      }                         
                  
                  }
              }
              else
              {
                  scanf("%d", &bb);
                  printf("%d\n", ans.query(bb));
              }
          }
    }
    system("pause");
    return 0;
    }