답안 #69303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69303 2018-08-20T11:45:56 Z FedericoS Boat (APIO16_boat) C++14
31 / 100
1718 ms 77956 KB
#pragma GCC optimize("Ofast")
#include <iostream>
#include <unordered_map>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
 
ll M=1000000007;
int N;
ll X[505],Y[505];
vector<ll> DP[505];
ll ans;
ll R[4000006];
unordered_map<ll,ll> L;
vector<ll> V;
 
ll query(ll k, ll l, ll r, ll a, ll b){

	if(b<l or r<a) return 0;
	if(a<=l and r<=b) return R[k];
 
	ll m=(l+r)/2;
	return (query(2*k,l,m,a,b)+query(2*k+1,m+1,r,a,b))%M;
 
}
 
void insert(ll k, ll l, ll r, ll a, ll b){
 
	if(l==r) R[k]=(R[k]+b)%M;
	else{
 
		ll m=(l+r)/2;
		if(a<=m)
			insert(2*k,l,m,a,b);
		else
			insert(2*k+1,m+1,r,a,b);
		R[k]=(R[2*k]+R[2*k+1])%M;
 
	}
 
}
 
ll somma(ll a){
	return query(1,0,1e6+1,a,1e6);
}
 
void aggiungi(ll a, ll b){
	insert(1,0,1e6+1,a,b);
}
 
int main(){
 
	cin>>N;
	for(int i=0;i<N;i++)
		cin>>X[i]>>Y[i];

	for(int i=0;i<N;i++)
		DP[i].resize(Y[i]-X[i]+4);

	for(int i=0;i<N;i++)
		for(ll j=X[i];j<Y[i]+3;j++)
			V.push_back(j);

	sort(V.begin(),V.end());

	ll p=0;
	for(int i=0;i<V.size();i++)
		if(i==0 or V[i]!=V[i-1])
			L[V[i]]=p++;

	for(int i=0;i<N;i++){
		X[i]=L[X[i]];
		Y[i]=L[Y[i]];
	}

 
	for(int i=N-1;i>=0;i--)
		for(ll j=X[i],k=0;j<=Y[i];j++,k++){
			DP[i][k]=(somma(j+1)+1)%M;
			aggiungi(j,DP[i][k]);
			ans=(ans+DP[i][k])%M;
			//cout<<i<<" "<<j<<" "<<DP[{i,j}]<<endl;
		}
 
	//for(int i=0;i<10;i++)cout<<i<<" "<<S[i]<<endl;
 
	cout<<ans;
 
}
/*
3
1 1
2 2
3 3
*/

/*
8
10000 30000
20000 40000
30000 50000
40000 60000
50000 70000
60000 80000
70000 90000
80000 100000
*/

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:70:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<V.size();i++)
              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 4 ms 616 KB Output is correct
3 Correct 5 ms 672 KB Output is correct
4 Correct 5 ms 852 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 4 ms 852 KB Output is correct
7 Correct 5 ms 852 KB Output is correct
8 Correct 5 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 5 ms 852 KB Output is correct
11 Correct 4 ms 852 KB Output is correct
12 Correct 4 ms 852 KB Output is correct
13 Correct 4 ms 852 KB Output is correct
14 Correct 5 ms 852 KB Output is correct
15 Correct 5 ms 852 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 4 ms 852 KB Output is correct
18 Correct 4 ms 852 KB Output is correct
19 Correct 5 ms 852 KB Output is correct
20 Correct 5 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 4 ms 616 KB Output is correct
3 Correct 5 ms 672 KB Output is correct
4 Correct 5 ms 852 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 4 ms 852 KB Output is correct
7 Correct 5 ms 852 KB Output is correct
8 Correct 5 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 5 ms 852 KB Output is correct
11 Correct 4 ms 852 KB Output is correct
12 Correct 4 ms 852 KB Output is correct
13 Correct 4 ms 852 KB Output is correct
14 Correct 5 ms 852 KB Output is correct
15 Correct 5 ms 852 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 4 ms 852 KB Output is correct
18 Correct 4 ms 852 KB Output is correct
19 Correct 5 ms 852 KB Output is correct
20 Correct 5 ms 852 KB Output is correct
21 Correct 1255 ms 15828 KB Output is correct
22 Correct 1267 ms 15828 KB Output is correct
23 Correct 1225 ms 15828 KB Output is correct
24 Correct 1287 ms 15952 KB Output is correct
25 Correct 1367 ms 16208 KB Output is correct
26 Correct 1427 ms 16412 KB Output is correct
27 Correct 1496 ms 16592 KB Output is correct
28 Correct 1477 ms 16592 KB Output is correct
29 Correct 1425 ms 16692 KB Output is correct
30 Correct 1682 ms 77860 KB Output is correct
31 Correct 1634 ms 77860 KB Output is correct
32 Correct 1550 ms 77956 KB Output is correct
33 Correct 1547 ms 77956 KB Output is correct
34 Correct 1620 ms 77956 KB Output is correct
35 Correct 1556 ms 77956 KB Output is correct
36 Correct 1587 ms 77956 KB Output is correct
37 Correct 1718 ms 77956 KB Output is correct
38 Correct 1490 ms 77956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 77956 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 4 ms 616 KB Output is correct
3 Correct 5 ms 672 KB Output is correct
4 Correct 5 ms 852 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 4 ms 852 KB Output is correct
7 Correct 5 ms 852 KB Output is correct
8 Correct 5 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 5 ms 852 KB Output is correct
11 Correct 4 ms 852 KB Output is correct
12 Correct 4 ms 852 KB Output is correct
13 Correct 4 ms 852 KB Output is correct
14 Correct 5 ms 852 KB Output is correct
15 Correct 5 ms 852 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 4 ms 852 KB Output is correct
18 Correct 4 ms 852 KB Output is correct
19 Correct 5 ms 852 KB Output is correct
20 Correct 5 ms 852 KB Output is correct
21 Correct 1255 ms 15828 KB Output is correct
22 Correct 1267 ms 15828 KB Output is correct
23 Correct 1225 ms 15828 KB Output is correct
24 Correct 1287 ms 15952 KB Output is correct
25 Correct 1367 ms 16208 KB Output is correct
26 Correct 1427 ms 16412 KB Output is correct
27 Correct 1496 ms 16592 KB Output is correct
28 Correct 1477 ms 16592 KB Output is correct
29 Correct 1425 ms 16692 KB Output is correct
30 Correct 1682 ms 77860 KB Output is correct
31 Correct 1634 ms 77860 KB Output is correct
32 Correct 1550 ms 77956 KB Output is correct
33 Correct 1547 ms 77956 KB Output is correct
34 Correct 1620 ms 77956 KB Output is correct
35 Correct 1556 ms 77956 KB Output is correct
36 Correct 1587 ms 77956 KB Output is correct
37 Correct 1718 ms 77956 KB Output is correct
38 Correct 1490 ms 77956 KB Output is correct
39 Runtime error 8 ms 77956 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Halted 0 ms 0 KB -