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
#include<iostream>
using namespace std;

pair<int,int> t[1000000];
int dru[1000000];
long long wynik[1000000];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>t[i].first>>t[i].second;
	for(int j=0;j<n;j++){
		pair<int,int> d;
		d.first = -1;
		d.second = n+1;
		long long wyn = 0;
		int ile = -1;
		for(int i=j;i>=0;i--){
			d.first= max(d.first,t[i].first);
			d.second = min(d.second,t[i].second);
			if((j-i+1) > d.second) break;
			if(d.first <= (j-i+1)){
				if(i==0){
					if(ile==-1){
						ile = max(1,ile);
						wyn = 1;
					}
				}else if(dru[i-1]!=-1){
					if(dru[i-1]+1==ile){
						wyn+=wynik[i-1];
						wyn%=1000000007;
					}
					if(dru[i-1]+1>ile){
						ile = dru[i-1]+1;
						wyn = wynik[i-1];
					}
				}
			}
		}
		if(ile!=-1){
			wynik[j]=wyn;
			wynik[j]%=1000000007;
			dru[j] = ile;
		}
		
	}
	if(dru[n-1]==0)
		cout<<"NIE\n";
	else
		cout<<dru[n-1]<<" "<<wynik[n-1]<<"\n";

	return 0;
}