답안 #124350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124350 2019-07-03T07:01:09 Z Mtaylor Boat (APIO16_boat) C++14
31 / 100
2000 ms 228704 KB
#include <bits/stdc++.h>
 
    using namespace std;
    typedef long long ll;
    typedef vector<ll> vl ;
 
    #define mp make_pair
    #define pb push_back
    #define f first
    #define s second
    #define all(v) (v).begin(),(v).end()
 
 
    const int MOD = 1000000007;
    const int N = 2000009;
    const double PI =4*atan(1);
    const double eps = 1e-7;
    
    ll n;
    unordered_map<ll,ll> maa;
    unordered_map<ll,ll> mal;
    set<ll> ss;
    ll a[N];
    ll b[N];
    ll c[N];
    ll d[N];
    ll tree[N];
    ll tree2[N];
 
    void update(ll x, ll val){
        for(;x<=2000009;x+=(x)&(-x)){
            tree[x]+=val;
            tree[x]%=MOD;
        }
    }
 
    ll get(ll x){
        ll to_return =0;
        for(;x>0;x-=x&(-x)){
            to_return +=tree[x];
            to_return %=MOD;
        }
        return to_return;
    }
 
 
    int main(){
        //ios::sync_with_stdio(0);
        //freopen("easy.txt","r",stdin);
        cin >> n;
        for(int i=0;i<n;i++){
        	scanf("%lld",&a[i]);
            scanf("%lld",&b[i]);
            for(int j=a[i];j<=b[i];j++){
            	ss.insert(j);
            }
        }
        ll cnt=2;
        for(auto t:ss){
            mal[t]=cnt;
            maa[cnt]=t;
            cnt++;
        }
        ss.clear();
        update(1,1);
        ll ans=0;
        for(int i=0;i<n;i++){
            for(int j=mal[a[i]];j<=mal[b[i]];j++){
            	if(j==mal[a[i]])
                	ans+=get(j);
                else{
                	ans+=((maa[j]-maa[j-1])%MOD) * (get(j-1)+tree2[j-1])%MOD;
                }
                //cout << i << " " << maa[j] << " " << ans << endl;
                ans%=MOD;
            }
            for(int j=mal[b[i]];j>=mal[a[i]];j--){
                	ll x=get(j);
                	update(j+1,x);
                	//update2(j,x);
                	tree2[j]+=x;
                if(j!=mal[a[i]]){
                	ll x=(get(j-1)+ tree2[j-1])%MOD;
                	update(j,((x%MOD)*((maa[j]-maa[j-1]-1) % MOD))%MOD);
                }
            }
 
        }
        cout << ans;
        return 0;
    }

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:52:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
          scanf("%lld",&a[i]);
          ~~~~~^~~~~~~~~~~~~~
boat.cpp:53:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld",&b[i]);
             ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 365 ms 1116 KB Output is correct
22 Correct 366 ms 1144 KB Output is correct
23 Correct 343 ms 1184 KB Output is correct
24 Correct 376 ms 1144 KB Output is correct
25 Correct 382 ms 1200 KB Output is correct
26 Correct 394 ms 888 KB Output is correct
27 Correct 405 ms 1016 KB Output is correct
28 Correct 400 ms 1016 KB Output is correct
29 Correct 406 ms 1100 KB Output is correct
30 Correct 1020 ms 153060 KB Output is correct
31 Correct 1034 ms 150768 KB Output is correct
32 Correct 1004 ms 153152 KB Output is correct
33 Correct 980 ms 149928 KB Output is correct
34 Correct 1016 ms 150904 KB Output is correct
35 Correct 865 ms 145448 KB Output is correct
36 Correct 967 ms 149444 KB Output is correct
37 Correct 899 ms 150660 KB Output is correct
38 Correct 887 ms 146848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2076 ms 228704 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 365 ms 1116 KB Output is correct
22 Correct 366 ms 1144 KB Output is correct
23 Correct 343 ms 1184 KB Output is correct
24 Correct 376 ms 1144 KB Output is correct
25 Correct 382 ms 1200 KB Output is correct
26 Correct 394 ms 888 KB Output is correct
27 Correct 405 ms 1016 KB Output is correct
28 Correct 400 ms 1016 KB Output is correct
29 Correct 406 ms 1100 KB Output is correct
30 Correct 1020 ms 153060 KB Output is correct
31 Correct 1034 ms 150768 KB Output is correct
32 Correct 1004 ms 153152 KB Output is correct
33 Correct 980 ms 149928 KB Output is correct
34 Correct 1016 ms 150904 KB Output is correct
35 Correct 865 ms 145448 KB Output is correct
36 Correct 967 ms 149444 KB Output is correct
37 Correct 899 ms 150660 KB Output is correct
38 Correct 887 ms 146848 KB Output is correct
39 Execution timed out 2076 ms 228704 KB Time limit exceeded
40 Halted 0 ms 0 KB -