UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215241#2726. 8.3t4wujiachen50233ms4344kbC++976b2024-11-27 19:52:132024-11-27 23:37:17

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
int a[N];
int ans;
int an[N];
int n;
int dfs(int x){
    if(x+a[x]>n){
        an[x]=1;
        return 1;
    }
    else if(an[x]){
        return an[x];
    }
    else{
        an[x]=dfs(x+a[x])+1;
        return an[x];
    }
}
signed main(){
    
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    if(n<=105){
        int m;
        cin>>m;
        while(m--){
            int p,k,ans=0;
            scanf("%lld %lld",&p,&k);
            while(p<=n){
                ans++;
                p+=a[p]+k;
            }
            printf("%lld\n",ans);
        }
        return 0;
    }
    for(int i=1;i<=n;i++){
        if(an[i])continue;
        an[i]=dfs(i);
    }
    int m;
    cin>>m;
    while(m--){
        int p,k;
        scanf("%lld %lld",&p,&k);
        printf("%lld\n",an[p]);
    }
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1224kb

input:

100
5 6 12 22 23 21 22 7 30 5 22 22 29 30 30 10 7 17 25 24 1 16 17 30 3 19 7 27 14 20 28 5 22 23 13 ...

output:

3
7
5
3
2
2
3
4
3
3
4
3
3
4
5
4
2
5
2
5
5
3
4
5
3
3
4
5
4
2
2
2
4
3
2
6
2
5
3
4
2
3
3
2
2
3
2
2
3
3
...

result:

ok 100 lines

Test #2:

score: 10
Accepted
time: 20ms
memory: 2892kb

input:

100000
25 29 13 9 17 27 2 5 20 4 27 25 5 24 17 13 13 14 3 13 4 24 19 9 21 20 14 17 9 11 13 9 5 24 20...

output:

6391
6391
6393
6386
6388
6393
6391
6393
6391
6392
6392
6390
6392
6392
6318
6395
6394
6389
6389
6390
...

result:

ok 100000 lines

Test #3:

score: 10
Accepted
time: 29ms
memory: 2892kb

input:

100000
16 18 28 7 16 2 30 19 30 28 17 8 8 16 16 3 11 19 29 7 9 27 6 27 27 28 29 3 18 27 5 29 14 15 2...

output:

6477
6480
6475
6477
6475
6476
6478
6478
6319
6477
6479
6479
6479
6375
6353
6349
6476
6480
6480
6474
...

result:

ok 100000 lines

Test #4:

score: 10
Accepted
time: 27ms
memory: 2888kb

input:

100000
29 30 15 26 1 29 1 4 12 22 12 4 9 27 20 29 21 8 29 27 11 5 13 7 20 15 5 15 10 1 30 28 10 30 3...

output:

6475
6475
6472
6468
6473
6469
6472
6473
6472
6478
6469
6469
6476
6470
6474
6473
6470
6469
6470
6475
...

result:

ok 100000 lines

Test #5:

score: 10
Accepted
time: 26ms
memory: 2888kb

input:

100000
30 25 29 4 13 25 14 15 21 20 8 4 17 16 13 8 10 17 21 10 14 13 9 26 28 14 28 13 29 10 28 2 3 1...

output:

6484
6483
6481
6487
6483
6487
6480
6484
6484
6483
6482
6486
6486
6374
6483
6484
6480
6483
6480
6482
...

result:

ok 100000 lines

Test #6:

score: 0
Wrong Answer
time: 31ms
memory: 3068kb

input:

100000
3 1 9 1 7 6 10 9 5 10 6 5 5 8 2 8 10 1 9 4 4 3 6 3 1 9 5 2 7 8 1 3 8 6 1 8 3 1 1 10 8 4 2 8 5...

output:

18221
18220
18214
18224
18223
18215
18231
18217
18214
18231
18229
18221
18225
18221
18213
18216
1822...

result:

wrong answer 1st lines differ - expected: '15308', found: '18221'

Test #7:

score: 0
Wrong Answer
time: 27ms
memory: 2880kb

input:

100000
19 6 20 1 19 14 23 14 23 3 9 1 14 19 22 21 4 26 2 20 16 9 27 20 23 2 19 5 13 18 6 11 17 13 9 ...

output:

6413
6415
6411
6413
6413
6409
6414
6416
6412
6412
6412
6413
6403
6410
6413
6406
6416
6410
6411
6407
...

result:

wrong answer 1st lines differ - expected: '6114', found: '6413'

Test #8:

score: 0
Wrong Answer
time: 29ms
memory: 2880kb

input:

100000
3 16 18 2 10 29 27 26 12 11 15 12 29 16 2 8 14 4 28 13 21 13 2 24 4 9 16 14 4 27 27 15 18 13 ...

output:

6413
6414
6413
6411
6418
6417
6413
6415
6415
6420
6417
6410
6414
6413
6420
6414
6412
6418
6418
6418
...

result:

wrong answer 1st lines differ - expected: '6080', found: '6413'

Test #9:

score: 0
Wrong Answer
time: 17ms
memory: 2812kb

input:

100000
82 65 27 36 67 74 9 74 35 72 97 28 57 78 88 66 89 20 30 50 2 1 19 8 97 4 47 37 6 73 22 31 64 ...

output:

2000
1997
1999
2003
1997
1997
1993
2000
1990
1999
1997
1999
1997
2000
2000
1997
2000
2001
1997
1997
...

result:

wrong answer 1st lines differ - expected: '1926', found: '2000'

Test #10:

score: 0
Wrong Answer
time: 27ms
memory: 4344kb

input:

100000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

99999
99998
100000
99997
99999
99997
99999
100000
99996
99999
99999
99999
99999
99999
99999
99997
99...

result:

wrong answer 1st lines differ - expected: '50000', found: '99999'