Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- #include <vector>
- using namespace std;
- typedef long long int lint;
- lint factorial(lint x){
- lint ans=1;
- for(int i=1; i<=x;++i){
- ans*=i;
- ans = ans%998244353;
- }
- return ans;
- }
- int main() {
- lint n;
- cin >> n;
- map<lint,map<lint,lint>> body1;
- map<lint,lint> body1_size;
- map<lint,map<lint,lint>> body2;
- map<lint,lint> body2_size;
- for(lint i=0; i<n;++i){
- lint mm,m;
- cin>>mm>>m;
- body1[mm][m]++;
- body2[m][mm]++;
- body1_size[mm]++;
- body2_size[m]++;
- }
- lint ans1=1;
- lint ans2=1;
- lint ans12=1;
- lint prmax = -1;
- bool oversort = true;
- for(auto& x:body1){
- int curmax = x.second.begin()->first;
- if(oversort && (curmax < prmax)){
- oversort = false;
- }else{
- prmax = curmax;
- }
- for(auto& y:x.second){
- ans12 = ans12*factorial(y.second);
- ans12 = ans12%998244353;
- }
- }
- for(auto& x:body1_size){
- ans1 = ans1*factorial(x.second);
- ans1 = ans1%998244353;
- }
- for(auto& x:body2_size){
- ans2 = ans2*factorial(x.second);
- ans2 = ans2%998244353;
- }
- lint xxx = (factorial(n)%998244353+lint(998244353)*3-ans1-ans2)%998244353;
- if(oversort){
- xxx+=ans12;
- xxx=xxx%998244353;
- }
- cout<< xxx <<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement