zoukankan      html  css  js  c++  java
  • CF878C Tournament set 图论

    题面

    题面

    题解

    如果2个人可以互相战胜,那么我们连一条无向边,于是最后会剩下t个联通块,其中每对联通块之间都有严格的大小关系(a.max < b.min),因此我们每插入一个点就相当于合并一段连续的块,其中边界(无法继续合并的地方)是第一个严格比它小的和第一个严格比它大的。

    #include<bits/stdc++.h>
    using namespace std;
    #define R register int
    #define LL long long
    #define ld double
    #define AC 15
    #define ac 101000
    
    int n, K;
    inline int read()
    {
    	int x = 0;char c = getchar();
    	while(c > '9' || c < '0') c = getchar();
    	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    	return x;
    }
    
    inline void upmin(int &a, int b) {if(b < a) a = b;}
    inline void upmax(int &a, int b) {if(b > a) a = b;}
    
    struct node{
    	int maxn[AC], minn[AC], Size;
    	
    	friend bool operator < (node a, node b)
    	{
    		for(R i = 1; i <= K; i ++)
    			if(a.maxn[i] > b.minn[i]) return 0;
    		return 1;//只有b严格大于a才返回true,即Min(b) > Max(a)
    	}
    	
    	inline void merge(node a)
    	{
    		Size += a.Size;
    		for(R i = 1; i <= K; i ++)
    			upmax(maxn[i], a.maxn[i]), upmin(minn[i], a.minn[i]);
    	}
    };
    set <node> S;
    set <node> :: iterator q[ac];
    
    void pre()
    {
    	n = read(), K = read();
    }
    
    void work()
    {
    	for(R i = 1; i <= n; i ++)
    	{
    		node x;
    		x.Size = 1;
    		for(R j = 1; j <= K; j ++) x.maxn[j] = x.minn[j] = read();
    		set <node> :: iterator last = S.lower_bound(x);
    		set <node> :: iterator Next = S.upper_bound(x);
    		set <node> :: iterator it;
    		int tot = 0;
    		for(it = last; it != Next; it ++) q[++ tot] = it;
    		for(R j = 1; j <= tot; j ++) x.merge(*q[j]), S.erase(q[j]);//将中间的点不断合并进来并删除
    		S.insert(x);
    		printf("%d
    ", S.rbegin() -> Size);
    	}
    }
    
    int main()
    {
    	freopen("in.in", "r", stdin);
    	pre();
    	work();
    	fclose(stdin);
    	return 0;
    }
    
  • 相关阅读:
    LeetCode: Number Complement
    LeetCode: Hamming Distance
    LeetCode: Sum of Left Leaves
    LeetCode: Ransom Note
    LeetCode: Minimum Moves to Equal Array Elements
    LeetCode: Linked List Random Node
    LeetCode: Product of Array Except Self
    LeetCode:Two Sum II
    LeetCode: Minimum Moves to Equal Array Elements II
    杂记 -- 时间段内应用程序调用次数限制
  • 原文地址:https://www.cnblogs.com/ww3113306/p/10342443.html
Copyright © 2011-2022 走看看