zoukankan      html  css  js  c++  java
  • 二维偏序关系 单个值不传递

    二维偏序关系 只要有一个值比对方大就算

    #include <bits/stdc++.h>
    #define PI acos(-1.0)
    #define mem(a,b) memset((a),b,sizeof(a))
    #define TS printf("!!!
    ")
    #define pb push_back
    //std::ios::sync_with_stdio(false);
    using namespace std;
    //priority_queue<int,vector<int>,greater<int>> que;
    const double EPS = 1.0e-8;
    typedef pair<int, int> pairint;
    typedef long long ll;
    typedef unsigned long long ull;
    const int  maxn = 1e5 + 100;
    const int  maxm = 300;
    //next_permutation
    //priority_queue<int, vector<int>, greater<int>> que;
    int ans[maxn];
    int counter[10000005];
    struct node
    {
            int cf, num, tp;
    } person[maxn];
    int n, m, i, num[10000001], t[20000001], l, r; //num:原数组;t:树状数组
    int lowbit(int x)
    {
            return x & (-x); //右起第一个1的位置为第k个 返回值则为2^(k-1)
    }
    void update(int x, int p) //更新第x 的值
    {
            while (x <= 2000000)
            {
                    t[x] += p;
                    x += lowbit(x); //不断找到自己的祖先 更新值
            }
            return;
    }
    int sum(int k)//前k个数的和
    {
            int ans = 0;
            while (k > 0)
            {
                    ans += t[k];
                    k -= lowbit(k);
            }
            return ans;
    }
    int ask(int l, int r) //求l-r区间和
    {
            if (r < l)
            {
                    return 0;
            }
            return sum(r) - sum(l - 1);
    }
    bool cmp(node a, node b)
    {
            if (a.cf == b.cf)
            {
                    return a.tp > b.tp;
            }
            return a.cf < b.cf;
    }
    void pf()
    {
            for (int i = 1; i <= n; i++)
            {
                    cout << person[i].cf << " " << person[i].tp << " " << person[i].num << endl;
            }
    }
    int main()
    {
            cin >> n ;
            for (int i = 1; i <= n; i++)
            {
                    scanf("%d %d", &person[i].cf, &person[i].tp);
                    counter[person[i].cf]++;
                    person[i].num = i;
            }
            sort(person + 1, person + 1 + n, cmp);
            //pf();
            //cout << endl;
            for (int i = n; i >= 1; i--)
            {
                    int cur = person[i].tp;
                    int number = person[i].num;
                    update(cur, 1);
                    int x = ask(1, cur - 1);
                   // cout << "x:" << x << endl;
                   // cout << "cf:" << person[i].cf << " " << counter[person[i].cf] << endl;
                    ans[number] = i + x - counter[person[i].cf];
                    counter[person[i].cf]--;
            }
            for (int i = 1; i <= n; i++)
            {
                    cout << ans[i] << endl;
            }
            //    cin>>n>>m;
            //    for(i=1;i<=n;i++)
            //    {
            //        cin>>num[i];
            //        update(i,num[i]);
            //    }
            //    for(i=1;i<=m;i++)
            //    {
            //        cin>>l>>r;
            //        cout<<ask(l,r)<<endl;
            //    }
            return 0;
    }
  • 相关阅读:
    Volume 6. Mathematical Concepts and Methods
    git帮助网址
    ubuntu 下安装wine
    ubuntu 通过ppa源安装mysql5.6
    ubuntu qq安装
    ubuntu14.04 fcitx安装
    language support图标消失
    ubuntu root用户登陆
    ubuntu 安装codeblocks13.12
    ubuntu tomcat自启动
  • 原文地址:https://www.cnblogs.com/Aragaki/p/7628890.html
Copyright © 2011-2022 走看看