답안 #61222

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61222 2018-07-25T11:35:23 Z istlemin Boat (APIO16_boat) C++14
31 / 100
1947 ms 125100 KB
#include<bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;

ll mod = 1e9+7;

class Node {
public:
    ll val = 0;
    ll dn,up;
    Node *left;
    Node *right;
    bool children = false;

    Node(ll _dn, ll _up){
        dn = _dn;
        up = _up;
    }

    void ensure(){
        if(dn+1==up) return;
        if(!children){
			children = true;
			left = new Node(dn,(dn+up)/2);
			right = new Node((dn+up)/2,up);
		}
    }

    ll update(ll pos, ll v){
        if(pos<dn||pos>=up) return val;
        if(dn+1==up) return val = (val+v)%mod;
        ensure();
        ll l = left->update(pos,v);
        ll r = right->update(pos,v);
        return val = (l+r)%mod;
    }

    ll query(ll a, ll b){
        if(b<=dn||a>=up) return 0;
        if(a<=dn&&b>=up) return val;
        ensure();
        return (left->query(a,b)+right->query(a,b))%mod;
    }
};

int main(){
	cin.sync_with_stdio(false);
	ll n;
    cin>>n;
    vi a,b;
    a.resize(n);
    b.resize(n);
    //posLastStart.resize(n);
    //posLast.push_back(-1);
    rep(i,0,n) {
		cin>>a[i]>>b[i];
		//posLastStart[i] = posLast.size();
		//rep(j,a[i],b[i]+1) posLast.push_back(j);
	}

	//mem.resize(posLastStart.size()+1,vi(n+1,-1));
    //cout<<(getNum(0,0)+mod-1)%mod<<endl;


    Node dp(0,1e10);

    dp.update(0,1);

    ll ans = 0;

    rep(i,0,n){
		vi u(b[i]+1-a[i]);
		rep(j,a[i],b[i]+1) {
			ans =  (ans + (u[j-a[i]] = dp.query(0,j)))%mod;
		}
		rep(j,a[i],b[i]+1) {
			dp.update(j,u[j-a[i]]);
		}
    }

    cout<<ans<<endl;
    _Exit(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1656 KB Output is correct
2 Correct 6 ms 1656 KB Output is correct
3 Correct 7 ms 1688 KB Output is correct
4 Correct 7 ms 1752 KB Output is correct
5 Correct 5 ms 1824 KB Output is correct
6 Correct 6 ms 1900 KB Output is correct
7 Correct 6 ms 1900 KB Output is correct
8 Correct 7 ms 1900 KB Output is correct
9 Correct 6 ms 1900 KB Output is correct
10 Correct 6 ms 1900 KB Output is correct
11 Correct 5 ms 1900 KB Output is correct
12 Correct 6 ms 1900 KB Output is correct
13 Correct 6 ms 1900 KB Output is correct
14 Correct 7 ms 1900 KB Output is correct
15 Correct 8 ms 1900 KB Output is correct
16 Correct 5 ms 1900 KB Output is correct
17 Correct 5 ms 1900 KB Output is correct
18 Correct 5 ms 1900 KB Output is correct
19 Correct 4 ms 1900 KB Output is correct
20 Correct 4 ms 1900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1656 KB Output is correct
2 Correct 6 ms 1656 KB Output is correct
3 Correct 7 ms 1688 KB Output is correct
4 Correct 7 ms 1752 KB Output is correct
5 Correct 5 ms 1824 KB Output is correct
6 Correct 6 ms 1900 KB Output is correct
7 Correct 6 ms 1900 KB Output is correct
8 Correct 7 ms 1900 KB Output is correct
9 Correct 6 ms 1900 KB Output is correct
10 Correct 6 ms 1900 KB Output is correct
11 Correct 5 ms 1900 KB Output is correct
12 Correct 6 ms 1900 KB Output is correct
13 Correct 6 ms 1900 KB Output is correct
14 Correct 7 ms 1900 KB Output is correct
15 Correct 8 ms 1900 KB Output is correct
16 Correct 5 ms 1900 KB Output is correct
17 Correct 5 ms 1900 KB Output is correct
18 Correct 5 ms 1900 KB Output is correct
19 Correct 4 ms 1900 KB Output is correct
20 Correct 4 ms 1900 KB Output is correct
21 Correct 1531 ms 1900 KB Output is correct
22 Correct 1533 ms 1900 KB Output is correct
23 Correct 1434 ms 1900 KB Output is correct
24 Correct 1534 ms 1900 KB Output is correct
25 Correct 1642 ms 1900 KB Output is correct
26 Correct 1630 ms 1900 KB Output is correct
27 Correct 1625 ms 1900 KB Output is correct
28 Correct 1651 ms 1900 KB Output is correct
29 Correct 1635 ms 1900 KB Output is correct
30 Correct 1865 ms 124748 KB Output is correct
31 Correct 1842 ms 124748 KB Output is correct
32 Correct 1910 ms 125100 KB Output is correct
33 Correct 1947 ms 125100 KB Output is correct
34 Correct 1897 ms 125100 KB Output is correct
35 Correct 1788 ms 125100 KB Output is correct
36 Correct 1710 ms 125100 KB Output is correct
37 Correct 1857 ms 125100 KB Output is correct
38 Correct 1812 ms 125100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 125100 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1656 KB Output is correct
2 Correct 6 ms 1656 KB Output is correct
3 Correct 7 ms 1688 KB Output is correct
4 Correct 7 ms 1752 KB Output is correct
5 Correct 5 ms 1824 KB Output is correct
6 Correct 6 ms 1900 KB Output is correct
7 Correct 6 ms 1900 KB Output is correct
8 Correct 7 ms 1900 KB Output is correct
9 Correct 6 ms 1900 KB Output is correct
10 Correct 6 ms 1900 KB Output is correct
11 Correct 5 ms 1900 KB Output is correct
12 Correct 6 ms 1900 KB Output is correct
13 Correct 6 ms 1900 KB Output is correct
14 Correct 7 ms 1900 KB Output is correct
15 Correct 8 ms 1900 KB Output is correct
16 Correct 5 ms 1900 KB Output is correct
17 Correct 5 ms 1900 KB Output is correct
18 Correct 5 ms 1900 KB Output is correct
19 Correct 4 ms 1900 KB Output is correct
20 Correct 4 ms 1900 KB Output is correct
21 Correct 1531 ms 1900 KB Output is correct
22 Correct 1533 ms 1900 KB Output is correct
23 Correct 1434 ms 1900 KB Output is correct
24 Correct 1534 ms 1900 KB Output is correct
25 Correct 1642 ms 1900 KB Output is correct
26 Correct 1630 ms 1900 KB Output is correct
27 Correct 1625 ms 1900 KB Output is correct
28 Correct 1651 ms 1900 KB Output is correct
29 Correct 1635 ms 1900 KB Output is correct
30 Correct 1865 ms 124748 KB Output is correct
31 Correct 1842 ms 124748 KB Output is correct
32 Correct 1910 ms 125100 KB Output is correct
33 Correct 1947 ms 125100 KB Output is correct
34 Correct 1897 ms 125100 KB Output is correct
35 Correct 1788 ms 125100 KB Output is correct
36 Correct 1710 ms 125100 KB Output is correct
37 Correct 1857 ms 125100 KB Output is correct
38 Correct 1812 ms 125100 KB Output is correct
39 Runtime error 5 ms 125100 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Halted 0 ms 0 KB -