本文整理汇总了C++中set::upper_bound方法的典型用法代码示例。如果您正苦于以下问题:C++ set::upper_bound方法的具体用法?C++ set::upper_bound怎么用?C++ set::upper_bound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类set
的用法示例。
在下文中一共展示了set::upper_bound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
#ifdef fn
freopen(fn ".in", "r", stdin);
freopen(fn ".out", "w", stdout);
#endif
cin >> s;
for (int i = 0; i + 1 < (int)s.size(); i++)
{
if (s[i] == 'A' && s[i + 1] == 'B')
ab.insert(i);
if (s[i] == 'B' && s[i + 1] == 'A')
ba.insert(i);
}
for (int i : ab)
{
auto it = ba.upper_bound(i + 1);
if (it != ba.end())
{
puts("YES");
return 0;
}
}
for (int i : ba)
{
auto it = ab.upper_bound(i + 1);
if (it != ab.end())
{
puts("YES");
return 0;
}
}
puts("NO");
}
示例2: main
int main()
{
// Open();
int n, q;
int cas = 0;
while(~scanf("%d%d", &n,&q))
{
cas++;
Tn = 0;
tot = 0;
for(int i = 0; i <= n; i++) G[i].clear();
for(int i = 1; i < n; i++)
{
int u, v;
scanf("%d%d", &u,&v);
G[u].push_back(v);
G[v].push_back(u);
}
dfs(1, -1, 0);
dfsSeg(1, -1);
int last = 0;
while(q--)
{
int k, p, t;
scanf("%d%d%d", &k, &p, &t);
t--;
S.clear();
p += last;
p = p%n+1;
for(int i = 0; i < k; i++)
{
int x;
scanf("%d", &x);
bool flag = true;
it = it1 = S.upper_bound(PII(st[x], 0));
it2 = S.upper_bound(PII(ed[x], 0));
if(it != S.begin()) it--;
else flag = false;
S.erase(it1, it2);
if(!flag || !(it->first <= st[x] && it -> second >= ed[x]))
S.emplace(st[x], ed[x]);
}
int pre = 1;
int ans = -1;
for(it1 = S.begin(); it1 != S.end(); it1++)
{
int l = it1->first;
if(pre < l) ans = res(ans, query(T[p], pre, l-1, t, 0), t);//, printf("%d, %d\n", pre, l-1);
pre = it1->second + 1;
}
if(pre <= Tn) ans = res(ans, query(T[p], pre, Tn, t, 0), t);//, printf("%d, %d\n", pre, Tn);
printf("%d\n", ans);
last = max(ans, 0);
}
}
return 0;
}
示例3: main
int main()
{
ios::sync_with_stdio(false);
cin >> n >> m;
for( int i = 0; i < n; i++ )
{
cin >> l[i] >> r[i];
ans[i] = -1;
}
for( int i = 0; i < m; i++ )
{
num aux; cin >> aux;
bridges.insert( make_pair(aux, i) );
needed[i] = -1;
}
for( int i = 0; i < n-1; i++ )
{
set< pair<num,int> >::iterator ub = bridges.upper_bound( make_pair(r[i+1]-l[i], INT_MAX)),
lb = bridges.lower_bound( make_pair(l[i+1]-r[i], INT_MIN)), aux;
aux = lb;
if( ++aux == ub )
{
ans[i] = lb->second;
used[lb->second] = 1;
needed[lb->second] = 0;
}
for(; lb != ub; ++lb) aval[i]++;
}
for( int i = 0; i < n-1; i++ )
{
if( ans[i] > 0 ) continue;
set< pair<num,int> >::iterator ub = bridges.upper_bound( make_pair(r[i+1]-l[i], INT_MAX)),
lb = bridges.lower_bound( make_pair(l[i+1]-r[i], INT_MIN)), aux;
for( ; lb != ub; ++lb )
if( used[lb->second] == 0 && needed[lb->second] > aval[i] )
{
ans[i] = lb->second;
used[lb->second] = 1;
break;
}
if( ans[i] == -1 )
{
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for( int i = 0; i < n-1; i++ )
cout << ans[i]+1 << " ";
cout << endl;
}
示例4: main
int main(){
int n,x;
cin>>n;
for (int i=0;i<n;++i){
cin>>x;
arr.push_back({x,i});
}
sort(arr.begin(),arr.end());
// for (int i=0;i<n;++i){
// cout<<arr[i].num<<" "<<arr[i].x<<endl;
// }
for (int i=0;i<n;++i){
set<node1>::iterator it = a.upper_bound({0,arr[i].num});
if (it == a.end()) up[arr[i].num] = n-1;
else up[arr[i].num] = it->num - 1;
a.insert({arr[i].x,arr[i].num});
}
for (int i=0;i<n;++i){
set<node2>::iterator it = b.upper_bound({0,arr[i].num});
if (it == b.end()) down[arr[i].num] = 0;
else down[arr[i].num] = it->num + 1;
b.insert({arr[i].x,arr[i].num});
}
// for (int i=0;i<n;++i){
// cout<<up[i]<<" ";
// }
// cout<<endl;
//
// for (int i=0;i<n;++i){
// cout<<down[i]<<" ";
// }
// cout<<endl;
//cout<<"hhh"<<endl;
for (int i=0;i<n;++i)
ans[up[arr[i].num]+1-down[arr[i].num]] = max(arr[i].x,ans[up[arr[i].num]+1-down[arr[i].num]]);
int anst[MAXSIZE];
anst[n] = ans[n];
for (int i=n-1;i>=1;--i){
anst[i] = max(anst[i+1],ans[i]);
}
for (int i=1;i<n;++i)
cout<<anst[i]<<" ";
cout<<anst[n]<<endl;
return 0;
}
示例5: main
int main(){
solve1();
s.insert(pi(-1,1e9+1));
for (int i=0; i<n; i++) {
set<pi> ::iterator it = s.upper_bound(pi(l[i],1e9+1));
it--;
pi tmp = *it;
if(tmp.second < r[i]) continue;
int r1 = assign(tmp.first,tmp.second);
int r2 = assign(tmp.first,l[i]-1) + assign(r[i]+1,tmp.second) + 1;
if(r1 != r2) continue;
s.erase(it);
if(tmp.first <= l[i] - 1){
s.insert(pi(tmp.first,l[i]-1));
}
if(r[i]+1 <= tmp.second){
s.insert(pi(r[i]+1,tmp.second));
}
res.push_back(i+1);
}
printf("%d\n",(int)res.size());
for (int i=0; i<res.size(); i++) {
printf("%d ",res[i]);
}
}
示例6: main
int main()
{
freopen("4444.in","r",stdin);
n=sc(),m=sc();
for(int i=1;i<=n;i++)
{
a[++tot].l=sc(),a[tot].r=sc(),a[tot].p=i;
if(a[tot].r<a[tot].l)a[tot].r+=m;
++tot;
a[tot].l=a[tot-1].l+m;
a[tot].r=a[tot-1].r+m;
}
sort(a+1,a+tot+1,cmp);
st.insert(make_pair(a[tot].l,tot));
for(int i=tot-1;i;i--)
{
fa[i][0]=(--st.upper_bound(make_pair(a[i].r,0x7FFFFFFF)))->second;
st.insert(make_pair(a[i].l,i));
}
for(int i=1;i<=18;i++)
for(int j=tot;j;j--)
fa[j][i]=fa[fa[j][i-1]][i-1];
for(int i=1;i<=tot;i++)
if(a[i].p)
solve(i);
for(int i=1;i<=n;i++)
printf("%d ",ans[i]+2);
return 0;
}
示例7: main
int main(int argc, char const *argv[])
{
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%I64d", A + i);
s += A[i];
ps[i + 1] = ps[i] + A[i];
}
sum.insert(s);
qu.insert(Pii(n, 0));
for (int i = 0, p; i < n; ++i) {
scanf("%d", &p); --p;
auto it = qu.upper_bound(Pii(p, 0));
// cout << it->second << " " << it->first << endl;
ll tmp = ps[it->first] - ps[it->second];
// cout << "tmp " << tmp << endl;
sum.erase(sum.lower_bound(tmp));
tmp = ps[p] - ps[it->second];
// cout << "tmp " << tmp << endl;
sum.insert(tmp); qu.insert(Pii(p, it->second));
tmp = ps[it->first] - ps[p + 1];
// cout << "tmp " << tmp << endl;
sum.insert(tmp); qu.insert(Pii(it->first, p + 1));
qu.erase(it);
printf("%I64d\n", *sum.rbegin());
}
return 0;
}
示例8: insert
void insert(int l, int r)
{
if(l >= r) return;
Interval inv(l,r);
if(invs.empty())
{
invs.insert(inv);
return;
}
Interval right(r+1,0);
set<Interval>::iterator iter = invs.upper_bound(right);
if(iter == invs.begin())
{
invs.insert(inv);
return;
}
else
{
iter--;
while( iter != invs.end() && iter->r() >= l )
{
if(iter->r() >= r) {
r = iter->r();
inv = Interval(l,r);
}
if(iter->l() <= l) {
l = iter->l();
inv = Interval(l,r);
}
invs.erase(iter);
iter--;
}
}
invs.insert(inv);
}
示例9: for
main()
{
freopen("pe.txt","r",stdin) ;
//freopen("pe(me).txt","w",stdout) ;
int T ;scanf("%d",&T) ;
while(T--)
{
scanf("%d",&n) ;
for(int i=1;i<=n;i++) scanf("%d",&a[i]) ;
dp[0][0]=0 ;
int ans=0 ;
for(int i=0;i<=n;i++)
{
if(ans==n) break ;
st.clear() ;
if(!i) st.insert((P){0,0}) ;
else for(int j=0;j<i;j++) st_insert((P){dp[j][i] , a[j]}) ;
for(int j=i+1;j<=n;j++)
{
if(ans==n) break ;
set<P>::iterator it=st.upper_bound((P){-1,a[j]}) ; it-- ;
dp[i][j]=(it->len)+1 ; ans=max(ans,dp[i][j]) ;
st_insert((P){dp[i][j] , a[j]}) ;
}
}
printf("%d\n",ans) ;
}
}
示例10: main
int main() {
ios_base::sync_with_stdio(false);
cin >> arrayLength;
for(int i = 0; i < arrayLength; i++) {
cin >> numberArray[i];
sortedArray[i] = IPair(numberArray[i], i);
}
sort(sortedArray, sortedArray + arrayLength);
for(int i = 0; i < arrayLength; i++) {
result[sortedArray[i].second] = sortedArray[i].first;
set<int>::iterator prev = indexList.lower_bound(sortedArray[i].second);
set<int>::iterator next = indexList.upper_bound(sortedArray[i].second);
if(prev != indexList.begin() && indexList.size() > 0) {
prev--;
int indexOffset = sortedArray[i].second - *prev;
result[sortedArray[i].second] = min(result[sortedArray[i].second], result[*prev] + indexOffset);
}
if(next != indexList.end()) {
int indexOffset = *next - sortedArray[i].second;
result[sortedArray[i].second] = min(result[sortedArray[i].second], result[*next] + indexOffset);
}
indexList.insert(sortedArray[i].second);
}
for(int i = 0; i < arrayLength; i++) {
result[i] = min(result[i], i + 1);
result[i] = min(result[i], arrayLength - i);
}
for(int i = 0; i < arrayLength; i++) {
maxResult = max(maxResult, result[i]);
}
cout << maxResult << "\n";
return 0;
}
示例11: main
int main() {
scanf("%d %d",&n,&m);
for(int i = 1; i <= n; i++) s.insert(triple(i,i,ll(i)));
while (m--) {
scanf("%d",&t);
if(t == 1) {
scanf("%d %d %I64d",&l,&r,&x);
auto it = s.upper_bound(triple(l,r,x));
if(it != s.begin()) it--;
vector<triple> aux;
while(it != s.end()) {
triple a = *it;
if(a.l > r) break;
int esq = max(a.l,l);
int dir = min(a.r,r);
ll v = abs(a.c-x);
if(dir >= esq) update(1,1,n,esq,dir,v);
if(esq != a.l) aux.pb(triple(a.l,l-1,a.c));
if(dir != a.r) aux.pb(triple(r+1,a.r,a.c));
s.erase(it++);
}
for (triple a : aux) s.insert(a);
s.insert(triple(l,r,x));
} else {
scanf("%d %d",&l,&r);
printf("%I64d\n",query(1,1,n,l,r));
}
}
}
示例12: main
int main() {
scanf("%d %d",&n, &d);
for (int i = 0; i < n; i++) scanf("%d",v+i);
dp(0,0);
int ans, cont;
ans = cont = 0;
set<int>::iterator it = s.upper_bound(d);
while(it != s.begin()) {
it--;
if(*it == ans) break;
ans = *it;
cont++;
it = s.upper_bound(ans+d);
}
printf("%d %d\n",ans,cont);
}
示例13: main
int main(){
int T;
scanf("%d",&T);
for(int cc = 1 ; cc <= T ; cc++){
S.clear();
scanf("%d",&N);
for(int c = 1 ; c <= N ; c++)
scanf("%lf",&A[c]);
for(int c = 1 ; c <= N ; c++){
scanf("%lf",&B[c]);
S.insert(B[c]);
}
sort(A+1,A+1+N), sort(B+1,B+1+N);
// for(int c = 1 ; c <= N ; c++)
// printf("%lf ",A[c]);
// printf("\n");
// for(int c = 1 ; c <= N ; c++)
// printf("%lf ",B[c]);
// printf("\n");
int s1,s2;
s1 = s2 = 0;
for(int c = 1, d = 1 ; c <= N ; c++){
if(A[c] > B[d])
s1++,d++;
set<double>::iterator it = S.upper_bound(A[c]);
if(it == S.end())
s2++;
else
S.erase(it);
}
printf("Case #%d: %d %d\n",cc,s1,s2);
}
}
示例14: main
int main() {
scanf("%d%d%d%d", &n, &p, &q, &r);
while(n--) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
e[p].push_back(make_pair(y, z));
e[x].push_back(make_pair(q, z));
e[x].push_back(make_pair(y, r));
}
sum = (LL)q * r;
sp.insert(make_pair(0, r + 1));
sp.insert(make_pair(q + 1, 0));
for(int i = p; i >= 1; --i) {
for(vector<Point>::iterator it = e[i].begin(); it != e[i].end(); ++it) {
set<Point>::iterator jt = sp.lower_bound(*it), kt; // it -> first <= jt -> first
if(jt -> second < it -> second) { // new point
while(1) {
jt = --sp.upper_bound(*it); // jt -> first <= it -> first
if(it -> second < jt -> second)
break;
Point tp = *jt;
sp.erase(jt);
jt = kt = sp.lower_bound(tp);
sum += (LL)(tp.first - (--jt) -> first) * (tp.second - kt -> second);
}
jt = kt = sp.lower_bound(*it);
sum -= (LL)(it -> first - (--jt) -> first) * (it -> second - kt -> second);
sp.insert(*it);
}
}
ans += sum;
}
printf("%I64d\n", ans);
return 0;
}
示例15: main
int main()
{
ull prod, i, j, T, N;
for(i=999; i>99; i--)
for(j=i; j>99; j--)
{
prod = i*j;
if (is_palin(prod))
{
palins.insert(prod);
}
}
cin >> T;
for(i=0; i < T; i++)
{
cin >> N;
si = palins.upper_bound(N);
si--;
cout << *si << endl;
}
return 0;
}