Ankit_132

F1

Jun 3rd, 2024
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. #define ff first
  6. #define ss second
  7.  
  8. const int N = 6e5 + 10;
  9. int r[N];
  10. int c[N];
  11.  
  12. map<pair<int,int>,int> cnt1,cnt2;
  13. set<pair<int,int>> s1,s3;
  14.  
  15. int main(){
  16.     int t;
  17.     cin>>t;
  18.  
  19.     while(t--){
  20.         ll n,m,k;
  21.         cin>>n>>m>>k;
  22.         map<ll,ll> m1;
  23.         map<pair<int, int>,ll> m2;
  24.         ll u=0,o=0;
  25.  
  26.         for(ll i=0;i<k;i++){
  27.             ll x,y;cin>>x>>y;
  28.             m2[{x,y}]=i;
  29.             m1[y]=max(m1[y],x);
  30.             u=max(u,x);
  31.         }
  32.  
  33.         ll r=0,e=1;
  34.         for(auto it:m1){
  35.             if(it.ss>r){
  36.                 o+=(it.ff-e)*(n-r);
  37.                 r=it.ss;
  38.                 e=it.ff;
  39.             }
  40.         }
  41.         o+=(m+1-e)*(n-r);
  42.  
  43.         vector<long long> ans(k,0);
  44.         ll p=0;
  45.         cout<<o<<"\n";
  46.  
  47.         for(auto it:m1){
  48.             if(it.ss>p){
  49.                 ans[m2[{it.ss,it.ff}]]=1;
  50.                 p=it.ss;
  51.             }
  52.         }
  53.  
  54.         for(auto e: ans)        cout<<e<<" ";
  55.         cout<<"\n";
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment