本文整理汇总了C++中BIT::query方法的典型用法代码示例。如果您正苦于以下问题:C++ BIT::query方法的具体用法?C++ BIT::query怎么用?C++ BIT::query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BIT
的用法示例。
在下文中一共展示了BIT::query方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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));
}
}
}
示例2: main
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
//freopen("d.in", "r", stdin);
cin >> T;
while (T--){
cin >> N;
for (int i = 1 ; i <= N ; i++){
cin >> A[i];
B[i] = A[i];
}
sort(B + 1, B + N + 1);
for (int i = 1 ; i <= N ; i++)
ID[i] = lower_bound(B + 1, B + N + 1, A[i]) - B;
S[N + 1] = 0;
for (int i = N ; i >= 1 ; i--){
S[i] = 1;
if (ID[i] < ID[i + 1])
S[i] += S[i + 1];
}
int sol = 0;
BIT bit;
for (int i = 1 ; i <= N ; i++){
D[i] = 1;
if (ID[i] > ID[i - 1])
D[i] += D[i - 1];
bit.update(ID[i], D[i]);
int s = S[i] + bit.query(ID[i] - 1);
if (sol < s)
sol = s;
}
cout << sol << '\n';
}
return 0;
}
示例3: query
int query(int l, int r) {
// cout << bit.query(r,r) << " " << bit.query(l-1,r) << endl;
return bit.query(r, r) - bit.query(l-1, r);
}
示例4: main
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; ++i) {
int s;
scanf("%d", &s);
sect[s].push_back(i);
}
for (int i = 1; i <= n; ++i) scanf("%d", &need[i]);
scanf("%d", &k);
for (int q = 0; q < k; ++q) {
scanf("%d%d%d", &l[q], &r[q], &a[q]);
}
for (int i = 1; i <= n; ++i) {
lo[i] = 0;
hi[i] = k;
}
BIT bit;
while (!terminated()){
// clear tree
bit.reset();
// generate new check
for (int i = 1; i <= n; ++i) {
int mid = (lo[i]+hi[i])/2;
check[mid].push_back(i);
}
for (int q = 0; q < k; ++q) {
// apply query
if (l[q] <= r[q]) {
bit.update(l[q], a[q]);
bit.update(r[q]+1, -a[q]);
}
else {
bit.update(l[q], a[q]);
bit.update(1, a[q]);
bit.update(r[q]+1, -a[q]);
}
// check
for (auto &v: check[q]) {
long long sum = 0;
for (auto &s: sect[v]) {
sum += bit.query(s);
if (sum >= need[v]) break;
}
if (sum >= need[v]) {
hi[v] = q;
}
else {
lo[v] = q+1;
}
}
check[q].clear();
}
}
for (int i = 1; i <= n; ++i) {
if (lo[i] < k) printf("%d\n", lo[i]+1);
else puts("NIE");
}
return 0;
}
示例5: query
int HLD::query(int x)
{
return bit.query( dfsn[x] );
}
示例6: main
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;
}