Esempio n. 1
0
int main(){
    int N,x;
    scanf("%d",&N);
    
    SegTree* ST = new SegTree(N);

    for(int i=1;i<=N;i++){
        scanf("%d",&x);
        ST->A[i] = x;
    }

    ST->initialize(1, 1, N);
    int Q;
    scanf("%d",&Q);
    int type, y;

    while(Q--) {
        scanf("%d %d %d", &type, &x, &y);
        if(type==0)
            ST->update(1, 1, N, x, y);
        else {
            Node* ans = ST->query(1, 1, N, x, y);
            printf("%d\n",ans->maxs);
        }
    }
}
Esempio n. 2
0
bool isYes(int s,int e){
  s--;
  e--;
  if((s+e+1)%2) return false;
  int l = segl.node[s+segl.n-1];
  int r = segr.node[e+segr.n-1];
  int o,c,q;
  if(s!=0){
    o = no[e]-no[s-1];
    c = nc[e]-nc[s-1];
    q = nq[e]-nq[s-1];
  }else{
    o = no[e]-no[s];
    c = nc[e]-nc[s];
    q = nq[e]-nq[s];
  }
  if(abs(o-c) > q) return false;
  cout << l << " " << segl.query(s,s+(e-s)/2+1) << endl;
  if(segl.query(s,s+(e-s)/2+1) < l) return false;
  cout << r << " " << segr.query(e-(e-s)/2-1,e) << endl;
  if(segr.query(e-(e-s)/2-1,e) < r) return false;
  return true;
}
Esempio n. 3
0
int main()
{


  int p,c,i,j,k,q,l,t,tt=1,sz;
  string str;
  char ch;
  SegTree tree;
  cin>>t;
  while(t--)
  {
  sz=0;
  cin>>p;
  
  while(p--)
  {
  	cin>>c>>str;
  	l=str.length();
    for(i=0;i<c;i++)
  	for(j=0;j<l;j++)
  	tree.A[sz++]=str[j]-'0';
  }
  tree.n=sz;
  tree.init();
  cin>>q;
  int qnum=0;
  printf("Case %d:\n",tt++);
  while(q--)
  {
   cin>>ch>>i>>j;
   if(ch=='F')tree.set(i,j);
   else if(ch=='E')tree.clear(i,j);
   else if(ch=='I')tree.flip(i,j);
   else printf("Q%d: %d\n",++qnum,tree.query(i,j));
  }
  
  tree.reset();
  }
return  0;	
}
Esempio n. 4
0
int main()
{
    Reader rr;

    N = rr.next_u32();
    tree.init(ARRAYSZ);

    char op;
    int i, j, x;
    while (N--) {
        op = rr.next_char();
        i = rr.next_u32();
        j = rr.next_u32();

        switch (op) {
        case 'A':
            tree.inc_left(i, j);
            break;

        case 'B':
            tree.inc_right(i, j);
            break;

        case 'C':
            x = rr.next_int();
            tree.set(i, j, x);
            break;

        case 'S':
            printf("%lld\n", tree.query(i, j));
            break;
        }
    }

    return 0;
}