2012网赛长春赛区

a题 4267  A Simple Problem with Integers

一直纠结在如何缩减区间, 后来发现直接更新就好了, 比如更新模10余1的在1到20区间上, 我们需要更新的是1和11, 在新区间上应该是【1, 2】 但是其实直接去更新模10余1那颗树上的【1,20】其实就可以, 因为查询除模10余1之外的数,是不会访问到这颗树的更新, 自然也不会影响其他位置的值

int a[maxn];

int main ()
{
    int n;
    while (~scanf("%d", &n))
    {
        memset (C, 0, sizeof(C));
        N=n;
        for (int i=1; i<=n; ++i)
            scanf("%d", a+i);
        int q;
        scanf("%d", &q);
        for (int kk=0; kk<q; ++kk)
        {
            int op; scanf("%d", &op);
            if(op==1)
            {
                int a, b, k, c; scanf("%d%d%d%d", &a, &b, &k, &c);
                int p=(k-1)*10+a%k;
                IUpdate(a, b, c, p);
            }
            if(op==2)
            {
                int t; scanf("%d", &t);
                int ans=0; ///Query(t+1, 0);
                //debug(Query(t, 0));
                for (int i=0; i<10; ++i)
                {
                    int p=i*10+t%(i+1);
                    ans+=Query(t, p);
                }
                printf("%d\n", ans+a[t]);
            }
        }
    }
    return 0;
}


b题 4268

#include <cstdio>
#include <set>
#include <algorithm>

using namespace std;
const int maxn=100000+123;

///int ax[maxn], ay[maxn], bx[maxn], by[maxn];
multiset<int, greater<int> > card;

struct Node{
    int x, y;
}a[maxn], b[maxn];

bool cmp(Node a, Node b)
{
    return (a.x<b.x || (a.x==b.x && a.y<b.y));
}

bool cmp1(int a, int b)
{
    return a>b;
}
int main()
{
    int cas; scanf("%d", &cas);
    while(cas--)
    {
        int n; scanf("%d", &n);
        for (int i=0; i<n; ++i)
            scanf("%d%d", &a[i].x, &a[i].y);
            ///scanf("%d%d", ax+i, ay+i);
        for (int i=0; i<n; ++i)
            scanf("%d%d", &b[i].x, &b[i].y);
            ///scanf("%d%d", bx+i, by+i);
        sort(a, a+n, cmp); sort(b, b+n, cmp);
        int cnt=0;
        card.clear();
        for (int i=0, k=0; i<n; ++i)
        {
            while (a[i].x>=b[k].x && k<n)
            {
                card.insert(b[k].y); k++;
            }
            multiset<int, greater<int> > :: iterator it=card.lower_bound(a[i].y);
            ///multiset<int, greater<int> > :: iterator it=lower_bound(card.begin(), card.end(), a[i].y, cmp1 );
            /// 下面的这个用法会tle应该是常数太大的原因。 上面的1500ms过。 
            if(it!=card.end())
            {
                
                ///it=max_element(card.begin(), --it);
                ///printf("%d %d %d\n", *it, a[i].x, a[i].y);
                card.erase(it);
                cnt++;
            }
        }
        printf("%d\n", cnt);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值