답안 #400620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400620 2021-05-08T12:06:40 Z Hazem Boat (APIO16_boat) C++14
31 / 100
2000 ms 161364 KB
#include <bits/stdc++.h>
using namespace std;
 
#define LL long long
#define F first
#define S second
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>

const int N = 2e5+10;
const int M = 5e3+10;
const LL INF = 1e9;
const LL LINF = 1e14;
const LL MOD = 1e9+7;
const double PI = 3.141592653589793;

LL add(LL a,LL b){
    return (a+b)%MOD;
}

struct node {

    node *lc,*rc;
    LL sum = 0,l,r;
    node():lc(NULL),rc(NULL),sum(0){};
};

void update(node * &v,int l,int r,int pos,LL val){

    if(v==NULL){
        v = new node();
        v->l = l;v->r = r;
    }

    if(l==r){
        v->sum = add(v->sum,val);
        return ;
    }

    int mid = (l+r)/2;
    if(pos<=mid)
        update(v->lc,l,mid,pos,val);
    else 
        update(v->rc,mid+1,r,pos,val);

    v->sum = add((v->lc==NULL?0:v->lc->sum),(v->rc==NULL?0:v->rc->sum));
}

LL get(node * &v,int l,int r,int tl,int tr){

    if(v==NULL){
        v = new node();
        v->l = l;v->r = r;
    }

    if(tl>=l&&tr<=r)
        return v->sum;

    if(tl>r||tr<l)
        return 0;

    int mid = (tl+tr)/2;
    return add(get(v->lc,l,r,tl,mid),get(v->rc,l,r,mid+1,tr));
}

node *root;

int main(){

    //freopen("out.txt","w",stdout);
    
    int n;
    scanf("%d",&n);

    update(root,0,INF,0,1);

    LL ans = 0;
    for(int i=1;i<=n;i++){
        int l,r;
        scanf("%d%d",&l,&r);
        for(int j=r;j>=l;j--){
            update(root,0,INF,j,get(root,0,j-1,0,INF));
            ans = add(ans,get(root,0,j-1,0,INF));
        }
    }

    printf("%lld\n",ans);
}   

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   73 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
boat.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   80 |         scanf("%d%d",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1228 KB Output is correct
2 Correct 3 ms 1228 KB Output is correct
3 Correct 3 ms 1228 KB Output is correct
4 Correct 3 ms 1228 KB Output is correct
5 Correct 3 ms 1228 KB Output is correct
6 Correct 3 ms 1196 KB Output is correct
7 Correct 3 ms 1228 KB Output is correct
8 Correct 3 ms 1228 KB Output is correct
9 Correct 3 ms 1228 KB Output is correct
10 Correct 3 ms 1228 KB Output is correct
11 Correct 3 ms 1228 KB Output is correct
12 Correct 3 ms 1192 KB Output is correct
13 Correct 3 ms 1196 KB Output is correct
14 Correct 3 ms 1188 KB Output is correct
15 Correct 3 ms 1228 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1228 KB Output is correct
2 Correct 3 ms 1228 KB Output is correct
3 Correct 3 ms 1228 KB Output is correct
4 Correct 3 ms 1228 KB Output is correct
5 Correct 3 ms 1228 KB Output is correct
6 Correct 3 ms 1196 KB Output is correct
7 Correct 3 ms 1228 KB Output is correct
8 Correct 3 ms 1228 KB Output is correct
9 Correct 3 ms 1228 KB Output is correct
10 Correct 3 ms 1228 KB Output is correct
11 Correct 3 ms 1228 KB Output is correct
12 Correct 3 ms 1192 KB Output is correct
13 Correct 3 ms 1196 KB Output is correct
14 Correct 3 ms 1188 KB Output is correct
15 Correct 3 ms 1228 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 980 ms 836 KB Output is correct
22 Correct 973 ms 820 KB Output is correct
23 Correct 937 ms 772 KB Output is correct
24 Correct 1012 ms 916 KB Output is correct
25 Correct 1034 ms 772 KB Output is correct
26 Correct 1077 ms 748 KB Output is correct
27 Correct 1099 ms 684 KB Output is correct
28 Correct 1105 ms 708 KB Output is correct
29 Correct 1118 ms 748 KB Output is correct
30 Correct 1204 ms 93084 KB Output is correct
31 Correct 1184 ms 91436 KB Output is correct
32 Correct 1206 ms 93284 KB Output is correct
33 Correct 1170 ms 90744 KB Output is correct
34 Correct 1182 ms 91584 KB Output is correct
35 Correct 1136 ms 87588 KB Output is correct
36 Correct 1200 ms 90564 KB Output is correct
37 Correct 1195 ms 91404 KB Output is correct
38 Correct 1171 ms 88468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2099 ms 161364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1228 KB Output is correct
2 Correct 3 ms 1228 KB Output is correct
3 Correct 3 ms 1228 KB Output is correct
4 Correct 3 ms 1228 KB Output is correct
5 Correct 3 ms 1228 KB Output is correct
6 Correct 3 ms 1196 KB Output is correct
7 Correct 3 ms 1228 KB Output is correct
8 Correct 3 ms 1228 KB Output is correct
9 Correct 3 ms 1228 KB Output is correct
10 Correct 3 ms 1228 KB Output is correct
11 Correct 3 ms 1228 KB Output is correct
12 Correct 3 ms 1192 KB Output is correct
13 Correct 3 ms 1196 KB Output is correct
14 Correct 3 ms 1188 KB Output is correct
15 Correct 3 ms 1228 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 980 ms 836 KB Output is correct
22 Correct 973 ms 820 KB Output is correct
23 Correct 937 ms 772 KB Output is correct
24 Correct 1012 ms 916 KB Output is correct
25 Correct 1034 ms 772 KB Output is correct
26 Correct 1077 ms 748 KB Output is correct
27 Correct 1099 ms 684 KB Output is correct
28 Correct 1105 ms 708 KB Output is correct
29 Correct 1118 ms 748 KB Output is correct
30 Correct 1204 ms 93084 KB Output is correct
31 Correct 1184 ms 91436 KB Output is correct
32 Correct 1206 ms 93284 KB Output is correct
33 Correct 1170 ms 90744 KB Output is correct
34 Correct 1182 ms 91584 KB Output is correct
35 Correct 1136 ms 87588 KB Output is correct
36 Correct 1200 ms 90564 KB Output is correct
37 Correct 1195 ms 91404 KB Output is correct
38 Correct 1171 ms 88468 KB Output is correct
39 Execution timed out 2099 ms 161364 KB Time limit exceeded
40 Halted 0 ms 0 KB -