Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- using namespace std;
- #define ff first
- #define ss second
- const int N = 6e5 + 10;
- int r[N];
- int c[N];
- map<pair<int,int>,int> cnt1,cnt2;
- set<pair<int,int>> s1,s3;
- int main(){
- int t;
- cin>>t;
- while(t--){
- ll n,m,k;
- cin>>n>>m>>k;
- map<ll,ll> m1;
- map<pair<int, int>,ll> m2;
- ll u=0,o=0;
- for(ll i=0;i<k;i++){
- ll x,y;cin>>x>>y;
- m2[{x,y}]=i;
- m1[y]=max(m1[y],x);
- u=max(u,x);
- }
- ll r=0,e=1;
- for(auto it:m1){
- if(it.ss>r){
- o+=(it.ff-e)*(n-r);
- r=it.ss;
- e=it.ff;
- }
- }
- o+=(m+1-e)*(n-r);
- vector<long long> ans(k,0);
- ll p=0;
- cout<<o<<"\n";
- for(auto it:m1){
- if(it.ss>p){
- ans[m2[{it.ss,it.ff}]]=1;
- p=it.ss;
- }
- }
- for(auto e: ans) cout<<e<<" ";
- cout<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment