예제 #1
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;	
}
int bfs(int x1, int y1, int x2, int y2) {
    if (x1 == x2 && y1 == y2) return 0;

    for (int i = 1; i <= r; i++)
        for (int j = 1; j <= c; j++) {
            dist[i][j] = INF;
            P[i][j] = 1;
        }

    priority_queue < pair < int, pii > > fila;
    dist[x1][y1] = V[x1][y1];
    fila.push(make_pair(-dist[x1][y1], make_pair(x1, y1)));

    visited.init();
    visited.build_x(1, 1, r);
    visited.update_x(1, 1, r, x1, y1, 0);

    int a1, b1, a2, b2;
    Node aux;
    while (!fila.empty()) {
        pii u = fila.top().second;
        fila.pop();
        if (abs(u.first - x2) <= R[u.first][u.second] && abs(u.second - y2) <= C[u.first][u.second]) return dist[u.first][u.second];

        a1 = max(1, u.first - R[u.first][u.second]);
        b1 = max(1, u.second - C[u.first][u.second]);
        a2 = min(r, u.first + R[u.first][u.second]);
        b2 = min(c, u.second + C[u.first][u.second]);

        while (1) {
            aux = visited.query_x(1, 1, r, a1, b1, a2, b2);
            if (aux.val < 1) break;

            dist[aux.x][aux.y] = dist[u.first][u.second] + V[aux.x][aux.y];
            fila.push(make_pair(-dist[aux.x][aux.y], make_pair(aux.x, aux.y)));
            visited.update_x(1, 1, r, aux.x, aux.y, 0);
        }
    }
    return -1;
}
예제 #3
0
파일: rip.cpp 프로젝트: M4573R/pc-code
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;
}