本文整理汇总了C++中vi类的典型用法代码示例。如果您正苦于以下问题:C++ vi类的具体用法?C++ vi怎么用?C++ vi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了vi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HLD
HLD(vvi &childs, vi &p) : V(p.size()), T(0), p(p), childs(childs),
pr(V,-1), size(V,-1), heavy(V,-1), t_in(V,-1), t_out(V,-1) {
dfs(0); set_pr(0,0);
}
示例2: conv
vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; }
示例3: SegmentTree
SegmentTree(vi &_A){
size = (int)_A.size();
A = _A;
tree.assign(size*4,0);
build(1,0,size-1);
}
示例4: print
// print function
// the number is stored in a vector with the 0th position being the least
// significant 'bits' -> go from last to first and concatenate to print
// the correct output
void print(const vi &v) {
for (vi::const_reverse_iterator rit = v.rbegin(); rit != v.rend(); ++rit) {
(rit != v.rbegin()) ? printf("%04d", *rit) : printf("%d", *rit);
}
printf("\n");
}
示例5: SegmentTree
SegmentTree(const vi &_A){
A = _A; n = (int) A.size();
st.assign(n * 4, 0);
lazy.assign(n * 4, -1);
build(1, 0, n - 1);
}
示例6: contains
bool contains(int N){
vi::iterator it = lower_bound(marks.begin(), marks.end(), N);
if(*it == N)return true;
return false;
}
示例7: main
int main(){
FASTER;
cin >> n >> q;
vi W(3000000,0);
ft.assign(6000000,0);
for (int i = 0; i < n; ++i) {
int t;
cin >> t;
v.push_back(t);
W[t]++;
if(query(t,t) == 0){
update(t,1);
}
}
st1.assign(20000000,0);
st2.assign(20000000,0);
buildMax(1,0,v.size()-1);
buildMin(1,0,v.size()-1);
for (int i = 0; i < q; ++i) {
char c;
int x,y;
cin >> c >>x >> y;
if(c == 'Q'){
y--;
int maxi = queryMax(1,0,v.size()-1, x,y);
int mini = queryMin(1,0,v.size()-1, x,y);
printf("range (%d,%d) = %lld %lld\n",mini,maxi, v[mini], v[maxi]);
ll cnt = query(v[mini],v[maxi]);
cout << cnt << endl;
}else{
ll val = v[x];
if(W[val]){
printf("remove %lld\n", val);
W[val]--;
if(W[val] == 0 && query(val,val) == 1){
update(val,-1);
}
}
W[y]++;
if(query(y,y) == 0){
update(y,1);
}
updateMax(1,x,0,(int)v.size()-1,y);
updateMin(1,x,0,(int)v.size()-1,y);
}
}
return 0;
}
示例8: make_set
inline void make_set(vi& set,int size) {
set.resize(size);
rep(i,size)set[i]=i;
}
示例9: conv
using vi = vector<int>; using vvi = vector<vi>; vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; }
示例10: main
int main(){
scanf("%d %d %d %d",&n, &l, &x, &y);
for (int i = 0,t; i < n; ++i) {
scanf("%d", &t);
marks.push_back(t);
}
// sort(mea.begin(), mea.end());
bool containsX = false,containsY = false;
if(containsCut(x)){
containsX = true;
}
if(containsCut(y)){
containsY = true;
}
vi new_mark;
// Solve both
if(!containsX && !containsY){
for (int i = 0; i < n; ++i) {
int u = marks[i];
// printf("u + x + y = %d\n",u + x + y);
if(u + x + y <= l && contains(u + x + y)){
new_mark.push_back(u+x);
containsX = containsY = true;
break;
}
if(u - x - y >= 0 && contains(u - x - y)){
new_mark.push_back(u-x);
containsX = containsY = true;
break;
}
if(u + x <= l && contains(u + x - y)){
new_mark.push_back(u+x);
containsX = containsY = true;
break;
}
if(u + y <= l && contains(u + y - x)){
new_mark.push_back(u+y);
containsX = containsY = true;
break;
}
if(u - x >= 0 && contains(u - x + y)){
new_mark.push_back(u-x);
containsX = containsY = true;
break;
}
if(u - y >= l && contains(u - y + x)){
new_mark.push_back(u-y);
containsX = containsY = true;
break;
}
}
}
if(!containsX){
new_mark.push_back(x);
}
if(!containsY){
new_mark.push_back(y);
}
printf("%d", (int)new_mark.size());
for (int i = 0; i < new_mark.size(); ++i) {
if(i)printf(" ");
else printf("\n");
printf("%d",new_mark[i]);
}
printf("\n");
return 0;
}
示例11: st_create
void st_create(vi &st, const vi &a)
{
int size = (int)(2 * pow(2.0, floor((log((double)a.size()) / log(2.0) + 1))));
st.assign(size, 0);
st_build(st, a, 1, 0, (int)a.size() - 1);
}
示例12:
SegmentTree(const vector<int> &_A){
A = _A; n = (int)A.size();
st.assign(4 * n, 0);
build(1, 0, n-1);
}
示例13:
UnionFind(int n){
rank.resize(n,0);
parent.resize(n);
size.resize(n,1);
for(int i=0;i<n;++i)parent[i]=i;
}
示例14: rep
rep(i,N){
int t; cin >> t;
dist.pb(t);
}
示例15: update
void update(int p, int val){
for(;p<ft.size();p += (p&(-p))){
ft[p] += val;
}
}