zoukankan      html  css  js  c++  java
  • Codeforces Round #345 (Div. 1) A. Watchmen

    相同的X,Y计进去,相同的二元组(X,Y)去重。

    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cassert>
    #include <cstring>
    #include <set>
    #include <map>
    #include <list>
    #include <queue>
    #include <string>
    #include <iostream>
    #include <algorithm>
    #include <functional>
    #include <stack>
    using namespace std;
    typedef long long ll;
    #define T int t_;Read(t_);while(t_--)
    #define dight(chr) (chr>='0'&&chr<='9')
    #define alpha(chr) (chr>='a'&&chr<='z')
    #define INF (0x3f3f3f3f)
    #define maxn (200005)
    #define hashmod 100000007
    #define ull unsigned long long
    #define repne(x,y,i) for(i=x;i<y;++i)
    #define repe(x,y,i) for(i=x;i<=y;++i)
    #define ri register int
    void Read(int &n){char chr=getchar(),sign=1;for(;!dight(chr);chr=getchar())if(chr=='-')sign=-1;
        for(n=0;dight(chr);chr=getchar())n=n*10+chr-'0';n*=sign;}
    void Read(ll &n){char chr=getchar(),sign=1;for(;!dight(chr);chr=getchar())if
        (chr=='-')sign=-1;
        for(n=0;dight(chr);chr=getchar())n=n*10+chr-'0';n*=sign;}
    int x[maxn],y[maxn],n;
    map<pair<int,int>,int> ma;
    pair<int,int> pa;
    int main()
    {
        freopen("a.in","r",stdin);
        freopen("b.out","w",stdout);
        ri i;
        Read(n);
        ll ans = 0;
        repne(0,n,i){
            Read(x[i]),Read(y[i]);
            pa = make_pair(x[i],y[i]);
            ma[pa]++;
        }
        map<pair<int,int>,int>::iterator it = ma.begin();
        sort(x,x+n),sort(y,y+n);
        int c = 1;
        repne(1,n,i){
            if(x[i]==x[i-1])++c;
            else ans += ((ll)c*(c-1))/2,c = 1;
        }
        ans += ((ll)c*(c-1))>>1;
        c = 1;
        repne(1,n,i){
            if(y[i]==y[i-1])++c;
            else ans += ((ll)c*(c-1))/2,c = 1;
        }
        ans += (ll)c*(c-1)>>1;
        for(;it!=ma.end();++it){
            c = it->second;
            ans = ans - ((ll)c*(c-1))/2;
        }
        cout << ans << endl;
        return 0;
    }
  • 相关阅读:
    Sliding Window
    方程的解数
    [JLOI2011]不重复数字
    A−B数对
    2007年分区联赛提高组之一 统计数字
    Magic Squares 魔板 (BFS+HASH)
    集合(normal)
    Place the Robots
    LoadRunner监控Linux
    CentOS6.3(64位)下安装Oracle11gR2(64)服务器
  • 原文地址:https://www.cnblogs.com/zhuiyicc/p/9600341.html
Copyright © 2011-2022 走看看