1 solutions

  • 0
    @ 2025-12-30 9:44:52
    
    
    #include<bits/stdc++.h>
    using namespace std;
    set<int>a[1000005];
    set<int>b[1000005];
    int main()
    {
    	int n,m,T;
    	cin>>n>>m>>T;
    	for(int i=1;i<=n;i++)
    		for(int j=1;j<=m;j++)
    		{
    			a[i].insert(j);
    			b[j].insert(i);
    		} 
    	while(T--)
    	{
    		int x,y;
    		cin>>x>>y;
    		if(b[y].count(x))
    		{
    			b[y].erase(x);
    			a[x].erase(y);
    			continue;	
    		} 
    		if(!a[x].empty())
    		{
    			auto it=a[x].upper_bound(y);
    			if(it!=a[x].end())
    			{
    				a[x].erase(*it);
    				b[*it].erase(x);
    			}
    			if(!a[x].empty())
    			{
    				it=a[x].upper_bound(y);
    				if(it!=a[x].begin())
    				{
    					it--;
    					a[x].erase(*it);
    					b[*it].erase(x);
    				}
    			}
    		}
    		if(!b[y].empty())
    		{
    			auto it=b[y].upper_bound(x);
    			if(it!=b[y].end())
    			{
    				b[y].erase(*it);
    				a[*it].erase(y);
    			}
    			if(!b[y].empty())
    			{
    				it=b[y].upper_bound(x);
    				if(it!=b[y].begin())
    				{
    					it--;
    					b[y].erase(*it);
    					a[*it].erase(y);
    				}
    			}
    		}
    		
    	}
    	int ans=0;
    	for(int i=1;i<=n;i++)
    		ans+=a[i].size();
    	cout<<ans<<endl;
    	return 0;
    }
    
    • 1

    Information

    ID
    253
    Time
    4000ms
    Memory
    1024MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    2
    Accepted
    1
    Uploaded By