Submission #21839

# Submission time Handle Problem Language Result Execution time Memory
21839 2017-04-26T09:57:58 Z mohammad_kilani Boat (APIO16_boat) C++14
9 / 100
2000 ms 221992 KB
#include <bits/stdc++.h>
using namespace std;
#define Mod 1000000007

int n;
int l[1000];
int r[1000];
int sum[1000010];
int seg[4000010];
map<int,bool> taken;
map<int,int> idx;
vector<int> v;


int getsum(int s,int e,int idx,int l,int r){
    if(s > r || e < l)
        return 0;
    if(s >=l && e <= r)
        return seg[idx];
    int f = getsum(s,(s+e)/2,idx*2,l,r);
    if(f >= Mod)
        f-=Mod;
    int ss = getsum((s+e)/2+1,e,idx*2+1,l,r);
    if(ss >= Mod)
        ss-=Mod;
    f+=ss;
    if(f >= Mod)
        f-=Mod;
    return f;
}

int update(int s,int e,int idx,int idx2,int val){
    if(s > idx2 || e < idx2)
        return seg[idx];
    if(s == idx2 && e == idx2)
        return seg[idx] = val;
    int f = update(s,(s+e)/2,idx*2,idx2,val);
    if(f >= Mod)
        f-=Mod;
    int ss = update((s+e)/2+1,e,idx*2+1,idx2,val);
    if(ss >= Mod)
        ss-=Mod;
    seg[idx] = f+ ss;
    if(seg[idx] >= Mod)
        seg[idx]-=Mod;
    return seg[idx];
}


int main() {
    //freopen("in.txt","r",stdin);
    scanf("%d",&n);
    int all = 0;
    for(int i=0;i<n;i++){
        scanf("%d%d",&l[i],&r[i]);
        for(int j=l[i];j<=r[i];j++){
            if(taken[j])
                continue;
            taken[j] = true;
            v.push_back(j);
        }
    }
    int ans = 0 ;
    all = v.size();
    sort(v.begin(),v.end());
    for(int i=0;i<(int)v.size();i++){
        idx[v[i]] = i ;
    }
    for(int i=0;i<n;i++){
        for(int j=l[i];j<=r[i];j++){
            if(idx[j] == 0){
                ans++;
                if(ans >= Mod)
                    ans-=Mod;
                sum[0]++;
                if(sum[0] >= Mod)
                    sum[0]-=Mod;
                continue;
            }
            int cur = 0;
            cur = getsum(0,all-1,1,0,idx[j]-1) + 1;
            if(cur >= Mod)
                cur-=Mod;
            ans+=cur;
            if(ans >= Mod)
                ans-=Mod;
            sum[idx[j]]+=cur;
                if(sum[idx[j]] >= Mod)
                    sum[idx[j]] -= Mod;
        }
        for(int j=l[i];j<=r[i];j++){
            update(0,all-1,1,idx[j],sum[idx[j]]);
        }
    }
    printf("%d\n",ans);
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:52:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
boat.cpp:55:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&l[i],&r[i]);
                                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21568 KB Output is correct
2 Correct 0 ms 21568 KB Output is correct
3 Correct 0 ms 21568 KB Output is correct
4 Correct 0 ms 21568 KB Output is correct
5 Correct 0 ms 21568 KB Output is correct
6 Correct 0 ms 21568 KB Output is correct
7 Correct 0 ms 21568 KB Output is correct
8 Correct 0 ms 21568 KB Output is correct
9 Correct 0 ms 21568 KB Output is correct
10 Correct 0 ms 21568 KB Output is correct
11 Correct 0 ms 21568 KB Output is correct
12 Correct 0 ms 21568 KB Output is correct
13 Correct 0 ms 21568 KB Output is correct
14 Correct 0 ms 21568 KB Output is correct
15 Correct 0 ms 21568 KB Output is correct
16 Correct 0 ms 21568 KB Output is correct
17 Correct 0 ms 21568 KB Output is correct
18 Correct 0 ms 21568 KB Output is correct
19 Correct 0 ms 21568 KB Output is correct
20 Correct 0 ms 21568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21568 KB Output is correct
2 Correct 0 ms 21568 KB Output is correct
3 Correct 0 ms 21568 KB Output is correct
4 Correct 0 ms 21568 KB Output is correct
5 Correct 0 ms 21568 KB Output is correct
6 Correct 0 ms 21568 KB Output is correct
7 Correct 0 ms 21568 KB Output is correct
8 Correct 0 ms 21568 KB Output is correct
9 Correct 0 ms 21568 KB Output is correct
10 Correct 0 ms 21568 KB Output is correct
11 Correct 0 ms 21568 KB Output is correct
12 Correct 0 ms 21568 KB Output is correct
13 Correct 0 ms 21568 KB Output is correct
14 Correct 0 ms 21568 KB Output is correct
15 Correct 0 ms 21568 KB Output is correct
16 Correct 0 ms 21568 KB Output is correct
17 Correct 0 ms 21568 KB Output is correct
18 Correct 0 ms 21568 KB Output is correct
19 Correct 0 ms 21568 KB Output is correct
20 Correct 0 ms 21568 KB Output is correct
21 Correct 763 ms 22100 KB Output is correct
22 Correct 736 ms 22100 KB Output is correct
23 Correct 709 ms 22100 KB Output is correct
24 Correct 756 ms 22100 KB Output is correct
25 Correct 796 ms 22100 KB Output is correct
26 Correct 756 ms 21968 KB Output is correct
27 Correct 789 ms 21968 KB Output is correct
28 Correct 766 ms 21968 KB Output is correct
29 Correct 793 ms 21968 KB Output is correct
30 Execution timed out 2000 ms 118360 KB Execution timed out
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2000 ms 221992 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21568 KB Output is correct
2 Correct 0 ms 21568 KB Output is correct
3 Correct 0 ms 21568 KB Output is correct
4 Correct 0 ms 21568 KB Output is correct
5 Correct 0 ms 21568 KB Output is correct
6 Correct 0 ms 21568 KB Output is correct
7 Correct 0 ms 21568 KB Output is correct
8 Correct 0 ms 21568 KB Output is correct
9 Correct 0 ms 21568 KB Output is correct
10 Correct 0 ms 21568 KB Output is correct
11 Correct 0 ms 21568 KB Output is correct
12 Correct 0 ms 21568 KB Output is correct
13 Correct 0 ms 21568 KB Output is correct
14 Correct 0 ms 21568 KB Output is correct
15 Correct 0 ms 21568 KB Output is correct
16 Correct 0 ms 21568 KB Output is correct
17 Correct 0 ms 21568 KB Output is correct
18 Correct 0 ms 21568 KB Output is correct
19 Correct 0 ms 21568 KB Output is correct
20 Correct 0 ms 21568 KB Output is correct
21 Correct 763 ms 22100 KB Output is correct
22 Correct 736 ms 22100 KB Output is correct
23 Correct 709 ms 22100 KB Output is correct
24 Correct 756 ms 22100 KB Output is correct
25 Correct 796 ms 22100 KB Output is correct
26 Correct 756 ms 21968 KB Output is correct
27 Correct 789 ms 21968 KB Output is correct
28 Correct 766 ms 21968 KB Output is correct
29 Correct 793 ms 21968 KB Output is correct
30 Execution timed out 2000 ms 118360 KB Execution timed out
31 Halted 0 ms 0 KB -