Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
3
Indexable
Never
#include<bits/stdc++.h>
#include<algorithm>

#define spd_emergency ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define ff first
#define ss second
#define mloop(i) for(auto i=m.begin();i!=m.end();i++)
#define pb push_back
#define pll pair<ll,ll> 
#define pii pair<int,int> 
#define mod1 1125899906842597LL

using namespace std;

int main()
{
	spd_emergency;
	int t=1;
	//cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		map<ll,ll> m = {};
		for(ll i=0;i<n;i++)		
		{
			ll u,v;
			cin>>u>>v;
			m[u]++;
			m[v+1]--;
		}
		ll q;
		cin>>q;
		while(q--)
		{
			vector<pll> ans;
			ll u,v,p;
			cin>>u>>v>>p;
			pll temp = {u,v};
			m[u]++;
			m[v+1]--;
			ll x=-1,y=-1,s=0;
			x = m.begin()->ff;
			for(auto i=m.begin();i!=m.end();i++)
			{
				if(x == -1)
					x = i->ff;
				y = i->ff;
				s+=i->ss;
				if(s == 0)
				{
					ans.pb({x,y-1});
					x = -1;
					y = -1;
				}
			}
			if(p)
			{
				cout<<ans.size()<<endl;
				for(auto x: ans)
				{
					cout<<x.ff<<" "<<x.ss<<endl;
				}
			}
		}
	}
	return 0;
}