Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <vector>
  5. using namespace std;
  6. typedef long long int lint;
  7. lint factorial(lint x){
  8.     lint ans=1;
  9.     for(int i=1; i<=x;++i){
  10.         ans*=i;
  11.         ans = ans%998244353;
  12.     }
  13.     return ans;
  14. }
  15. int main() {
  16.     lint n;
  17.     cin >> n;
  18.     map<lint,map<lint,lint>> body1;
  19.     map<lint,lint> body1_size;
  20.     map<lint,map<lint,lint>> body2;
  21.     map<lint,lint> body2_size;
  22.     for(lint i=0; i<n;++i){
  23.         lint mm,m;
  24.         cin>>mm>>m;
  25.         body1[mm][m]++;
  26.         body2[m][mm]++;
  27.         body1_size[mm]++;
  28.         body2_size[m]++;
  29.     }
  30.  
  31.     lint ans1=1;
  32.     lint ans2=1;
  33.     lint ans12=1;
  34.     lint prmax = -1;
  35.     bool oversort = true;
  36.     for(auto& x:body1){
  37.         int curmax = x.second.begin()->first;
  38.         if(oversort && (curmax < prmax)){
  39.             oversort = false;
  40.         }else{
  41.             prmax = curmax;
  42.         }
  43.         for(auto& y:x.second){
  44.             ans12 = ans12*factorial(y.second);
  45.             ans12 = ans12%998244353;
  46.         }
  47.     }
  48.     for(auto& x:body1_size){
  49.         ans1 = ans1*factorial(x.second);
  50.         ans1 = ans1%998244353;
  51.     }
  52.     for(auto& x:body2_size){
  53.         ans2 = ans2*factorial(x.second);
  54.         ans2 = ans2%998244353;
  55.     }
  56.     lint xxx = (factorial(n)%998244353+lint(998244353)*3-ans1-ans2)%998244353;
  57.     if(oversort){
  58.         xxx+=ans12;
  59.         xxx=xxx%998244353;
  60.     }
  61.     cout<< xxx <<endl;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement