#include <bits/stdc++.h> using namespace std; int n, a,b; vector <set <long long > > seciki; vector <pair <long long int, long long int>> dane; set <set <long long> > potezny_set; long long konkretnie[600005]; long long wynik=1; //zbior pusty int main () { cin>>n; seciki.resize(n); for (int i=0; i<n; i++) { cin>>a>>b; dane.push_back(make_pair(a,b)); konkretnie[a]=i; } if (n==1) { cout<<"2"; return 0; } for (int i=0; i<dane.size(); i++) { seciki[i].insert(dane[i].first); // cout<<dane[i].first<<": "<<dane[i].first<<" "; if (i<dane.size()-1) { int j=i+1; while (dane[i].first+dane[i].second>=dane[j].first && j<dane.size()) { seciki[i].insert(dane[j].first); // cout<<dane[j].first<<" "; j++; }} if (i>0) { int j=i-1; while (dane[i].first-dane[i].second<=dane[j].first && j>0) { // cout<<dane[j].first<<" "; seciki[i].insert(seciki[j].begin(),seciki[j].end()); j--; } } // cout<<"\n"; } // cout<<"\n\n\n\n\n\n\n\n"; //aktualizacja danych for (int i=0; i<seciki.size(); i++) { for (auto it=seciki[i].begin(); it!=seciki[i].end(); it++) { seciki[i].insert(seciki[konkretnie[*it]].begin(),seciki[konkretnie[*it]].end()); } } // for (int i=seciki.size()-1; i>=0; i--) { // for (auto it=seciki[i].begin(); it!=seciki[i].end(); it++) { // seciki[i].insert(seciki[konkretnie[*it]].begin(),seciki[konkretnie[*it]].end()); } // } //for (int i=0; i<seciki.size(); i++) { // cout<<dane[i].first<<":"; // for (auto it=seciki[i].begin(); it!=seciki[i].end(); it++) // cout<<*it<<" "; // cout<<endl; //} for (int i=0; i<seciki.size(); i++) potezny_set.insert(seciki[i]); long long wynik=1; ; for (int i=potezny_set.size(); i>0; i--) { wynik*=i; wynik=wynik%1000000007; } ; cout<<wynik; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #include <bits/stdc++.h> using namespace std; int n, a,b; vector <set <long long > > seciki; vector <pair <long long int, long long int>> dane; set <set <long long> > potezny_set; long long konkretnie[600005]; long long wynik=1; //zbior pusty int main () { cin>>n; seciki.resize(n); for (int i=0; i<n; i++) { cin>>a>>b; dane.push_back(make_pair(a,b)); konkretnie[a]=i; } if (n==1) { cout<<"2"; return 0; } for (int i=0; i<dane.size(); i++) { seciki[i].insert(dane[i].first); // cout<<dane[i].first<<": "<<dane[i].first<<" "; if (i<dane.size()-1) { int j=i+1; while (dane[i].first+dane[i].second>=dane[j].first && j<dane.size()) { seciki[i].insert(dane[j].first); // cout<<dane[j].first<<" "; j++; }} if (i>0) { int j=i-1; while (dane[i].first-dane[i].second<=dane[j].first && j>0) { // cout<<dane[j].first<<" "; seciki[i].insert(seciki[j].begin(),seciki[j].end()); j--; } } // cout<<"\n"; } // cout<<"\n\n\n\n\n\n\n\n"; //aktualizacja danych for (int i=0; i<seciki.size(); i++) { for (auto it=seciki[i].begin(); it!=seciki[i].end(); it++) { seciki[i].insert(seciki[konkretnie[*it]].begin(),seciki[konkretnie[*it]].end()); } } // for (int i=seciki.size()-1; i>=0; i--) { // for (auto it=seciki[i].begin(); it!=seciki[i].end(); it++) { // seciki[i].insert(seciki[konkretnie[*it]].begin(),seciki[konkretnie[*it]].end()); } // } //for (int i=0; i<seciki.size(); i++) { // cout<<dane[i].first<<":"; // for (auto it=seciki[i].begin(); it!=seciki[i].end(); it++) // cout<<*it<<" "; // cout<<endl; //} for (int i=0; i<seciki.size(); i++) potezny_set.insert(seciki[i]); long long wynik=1; ; for (int i=potezny_set.size(); i>0; i--) { wynik*=i; wynik=wynik%1000000007; } ; cout<<wynik; } |