本文整理汇总了C++中BIT::build方法的典型用法代码示例。如果您正苦于以下问题:C++ BIT::build方法的具体用法?C++ BIT::build怎么用?C++ BIT::build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BIT
的用法示例。
在下文中一共展示了BIT::build方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(void){
ios::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
char op[n];
long long val[n];
for(long long i = 0; i < n; i++)
cin >> op[i] >> val[i];
vector<long long> orig(val, val+n);
sort(val, val+n);
unordered_map<long long, long long> value, reval;
long long cur = 1;
value[val[0]] = cur;
reval[cur] = val[0];
for(long long i = 1; i < n; i++){
if(val[i] == val[i-1]) continue;
else {
value[val[i]] = ++cur;
reval[cur] = val[i];
}
}
for(long long i = 0; i < n; i++) orig[i] = value[orig[i]];
//for(long long i = 0; i < n; i++) cerr << orig[i] << endl;
tree.build(n+2);
for(long long i = 0; i < n; i++){
if(op[i] == 'I'){
//cerr << "inserting: " << orig[i] << endl;
insert(orig[i]);
}else if(op[i] == 'D'){
//cerr << "deleting: " << orig[i] << endl;
erase(orig[i]);
}else if(op[i] == 'K'){
long long ans = kth_smallest(reval[orig[i]]);
//cerr << "Kth: " << reval[orig[i]] << endl;
if(ans == -1) cout << "invalid" << endl;
else cout << reval[ans] << endl;
}else{
long long ans = Rank(orig[i]);
//cerr << "Count" << endl;
cout << ans << endl;
}
//tree.prlong long();
}
}
示例2: main
int main(int argc, const char * argv[]) {
int ff;
int v1, v2, t;
char query[20];
BIT bit;
scanf("%d", &ff);
for (int tt = 1; tt <= ff; tt++) {
printf("Case %d:\n", tt);
int n;
scanf("%d", &n);
bit.build(n+1);
for (int i = 1; i <= n; i++) {
scanf("%d", &t);
bit.modify(i, t);
}
bool fl = true;
while (fl) {
scanf("%s", query);
switch (query[0]) {
case 'Q':
scanf("%d %d", &v1, &v2);
printf("%d\n", bit.sum(v1, v2));
break;
case 'A':
scanf("%d %d", &v1, &v2);
bit.modify(v1, v2);
break;
case 'S':
scanf("%d %d", &v1, &v2);
bit.modify(v1, -v2);
break;
case 'E':
fl = false;
break;
}
}
}
}