QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#365240#5494. 软件包管理器stegatxins040 27ms8600kbC++201.0kb2024-03-24 22:21:432024-03-24 22:21:44

Judging History

你现在查看的是最新测评结果

  • [2024-03-24 22:21:44]
  • 评测
  • 测评结果:40
  • 用时:27ms
  • 内存:8600kb
  • [2024-03-24 22:21:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int maxn = 100001;
int n;

int adj[maxn], visited[maxn],ans;
vector<int> radj[maxn];

void dfs(int k){
    visited[k] = 1;
    ans++;
    if(k == 0)return;
    if(!visited[adj[k]])dfs(adj[k]);
}
void rdfs(int k){
    visited[k] = 0;
    ans++;
    for(auto x:radj[k]){
        //cerr << x << " ";
        if(visited[x])rdfs(x);
    }
    //cerr << endl;
}

int main(){

    //freopen("manager.in", "r", stdin);
    //freopen("manager.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i=1;i<=n-1;i++){
        cin >> adj[i];
        radj[adj[i]].push_back(i);
    }
    memset(visited,0,sizeof(visited));

    int q, node; cin >> q;
    string comm;
    while(q--){
        cin >> comm >> node;
        ans=0;
        if(comm == "install"){
            if(!visited[node])dfs(node);
        }else if(comm == "uninstall"){
            if(visited[node])rdfs(node);
        }
        cout << ans << "\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 2ms
memory: 4244kb

input:

5000
1197 1612 491 3490 3733 0 0 3931 3369 4435 321 1353 2697 938 3328 4392 3119 4473 0 2503 1082 3880 4507 2372 4977 3341 4390 3183 1719 3241 3443 3832 2394 0 1666 609 2625 4805 4406 4721 89 3020 0 706 74 2003 729 3221 0 0 2882 1522 4880 1794 4672 3137 2963 0 1299 3535 2022 2284 199 0 1056 0 0 420 ...

output:

457
160
245
458
431
515
436
407
401
237
180
348
309
69
341
428
368
355
191
203
157
237
278
347
391
135
140
390
420
226
259
447
312
81
166
372
469
378
190
41
258
334
395
349
97
200
241
354
561
617
330
77
266
219
288
589
427
169
242
208
176
472
444
444
431
330
355
262
207
401
387
331
298
68
291
438
29...

result:

ok 5000 lines

Test #2:

score: 5
Accepted
time: 8ms
memory: 6204kb

input:

5000
1197 1612 491 3490 3733 0 0 3931 3369 4435 321 1353 2697 938 3328 4392 3119 4473 0 2503 1082 3880 4507 2372 4977 3341 4390 3183 1719 3241 3443 3832 2394 0 1666 609 2625 4805 4406 4721 89 3020 0 706 74 2003 729 3221 0 0 2882 1522 4880 1794 4672 3137 2963 0 1299 3535 2022 2284 199 0 1056 0 0 420 ...

output:

457
160
245
458
431
515
436
407
401
237
180
348
309
69
341
428
368
355
191
203
157
237
278
347
391
135
140
390
420
226
259
447
312
81
166
372
469
378
190
41
258
334
395
349
97
200
241
354
561
617
330
77
266
219
288
589
427
169
242
208
176
472
444
444
431
330
355
262
207
401
387
331
298
68
291
438
29...

result:

ok 5000 lines

Test #3:

score: 5
Accepted
time: 24ms
memory: 8424kb

input:

100000
0 0 0 1 2 4 1 7 3 5 9 4 7 9 6 12 2 7 15 15 1 7 18 18 2 18 11 25 13 10 13 21 23 9 16 0 3 25 38 15 31 30 14 34 41 45 35 7 39 5 12 21 45 22 35 14 26 27 52 29 20 50 33 24 0 51 31 6 68 57 39 12 54 21 58 21 71 46 37 27 28 6 39 30 34 16 67 45 76 87 37 25 84 35 46 62 85 13 52 76 53 98 45 50 35 8 64 1...

output:

8
12
12
4
17
8
9
9
10
8
6
6
7
4
11
8
5
11
6
8
10
6
6
4
11
11
5
6
5
4
10
6
7
6
9
5
5
11
8
7
10
7
6
3
5
2
2
2
7
4
6
6
5
2
9
8
12
5
5
8
8
9
5
5
3
4
7
8
12
2
7
7
6
7
8
13
6
8
11
2
6
7
5
7
8
8
12
6
5
5
12
1
4
3
6
9
2
7
0
6
9
6
5
4
8
5
7
12
5
3
4
5
14
4
9
8
3
2
5
6
10
7
3
5
8
6
8
5
5
11
3
8
9
6
7
5
3
10
6...

result:

ok 100000 lines

Test #4:

score: 5
Accepted
time: 21ms
memory: 8308kb

input:

100000
0 0 0 1 2 4 1 7 3 5 9 4 7 9 6 12 2 7 15 15 1 7 18 18 2 18 11 25 13 10 13 21 23 9 16 0 3 25 38 15 31 30 14 34 41 45 35 7 39 5 12 21 45 22 35 14 26 27 52 29 20 50 33 24 0 51 31 6 68 57 39 12 54 21 58 21 71 46 37 27 28 6 39 30 34 16 67 45 76 87 37 25 84 35 46 62 85 13 52 76 53 98 45 50 35 8 64 1...

output:

8
12
12
4
17
8
9
9
10
8
6
6
7
4
11
8
5
11
6
8
10
6
6
4
11
11
5
6
5
4
10
6
7
6
9
5
5
11
8
7
10
7
6
3
5
2
2
2
7
4
6
6
5
2
9
8
12
5
5
8
8
9
5
5
3
4
7
8
12
2
7
7
6
7
8
13
6
8
11
2
6
7
5
7
8
8
12
6
5
5
12
1
4
3
6
9
2
7
0
6
9
6
5
4
8
5
7
12
5
3
4
5
14
4
9
8
3
2
5
6
10
7
3
5
8
6
8
5
5
11
3
8
9
6
7
5
3
10
6...

result:

ok 100000 lines

Test #5:

score: 5
Accepted
time: 24ms
memory: 8600kb

input:

100000
0 1 0 0 4 0 5 7 6 3 1 8 10 8 14 8 16 12 17 14 9 8 21 4 12 22 2 5 24 27 7 25 14 8 10 26 3 35 21 23 23 7 29 22 15 20 45 21 11 49 12 6 50 5 40 33 35 54 2 27 1 48 59 15 45 33 57 61 33 6 69 14 65 37 14 21 13 20 46 12 16 12 61 26 68 55 69 45 49 55 61 71 31 12 30 74 12 23 95 37 51 93 5 103 44 73 101...

output:

13
11
9
9
9
8
5
5
2
9
12
6
10
12
10
8
3
17
9
9
6
7
5
5
9
7
0
8
2
6
4
11
7
0
6
9
8
4
4
9
2
7
0
5
9
8
5
12
5
6
7
5
8
8
8
4
5
11
3
6
5
6
4
8
6
11
4
9
0
2
4
7
10
1
10
6
9
5
7
8
8
6
7
6
9
5
6
3
7
8
3
5
2
3
9
4
4
5
8
5
3
6
3
5
2
7
4
3
4
6
7
7
7
11
7
9
10
6
3
0
4
11
4
7
9
2
2
6
7
6
7
8
7
9
4
13
9
0
8
5
4
7...

result:

ok 100000 lines

Test #6:

score: 5
Accepted
time: 24ms
memory: 8372kb

input:

100000
0 1 2 1 2 3 2 4 3 4 2 11 12 6 8 7 3 8 12 18 2 20 7 0 13 23 14 22 26 3 17 31 2 16 18 25 23 30 16 25 7 33 21 0 18 2 27 45 36 16 23 29 31 7 39 53 19 12 50 53 58 17 40 32 18 46 54 10 4 25 64 64 20 25 22 66 4 68 30 56 17 74 19 81 5 58 25 79 75 47 55 38 35 69 92 71 30 31 98 78 76 80 10 96 63 42 31 ...

output:

18
7
7
9
11
0
8
4
15
5
7
8
1
13
7
10
8
6
3
10
8
7
7
12
1
7
12
9
8
6
0
5
0
3
6
5
4
9
3
6
6
8
3
6
6
7
6
11
9
12
12
8
0
3
8
6
7
5
4
12
16
1
7
4
4
3
11
8
7
10
8
7
5
4
11
7
7
7
3
8
8
3
7
3
7
5
5
5
3
2
8
5
10
7
3
7
6
6
4
6
3
5
6
4
10
8
6
5
6
0
3
3
6
5
9
7
4
7
7
9
5
7
5
8
7
0
6
1
13
7
9
0
3
4
0
5
7
3
6
8
5...

result:

ok 100000 lines

Test #7:

score: 5
Accepted
time: 27ms
memory: 8300kb

input:

100000
0 0 0 1 2 4 1 7 3 5 9 4 7 9 6 12 2 7 15 15 1 7 18 18 2 18 11 25 13 10 13 21 23 9 16 0 3 25 38 15 31 30 14 34 41 45 35 7 39 5 12 21 45 22 35 14 26 27 52 29 20 50 33 24 0 51 31 6 68 57 39 12 54 21 58 21 71 46 37 27 28 6 39 30 34 16 67 45 76 87 37 25 84 35 46 62 85 13 52 76 53 98 45 50 35 8 64 1...

output:

8
12
12
4
17
8
9
9
10
8
6
6
7
4
11
8
5
11
6
8
10
6
6
4
11
11
5
6
5
4
10
6
7
6
9
5
5
11
8
7
10
7
6
3
0
2
2
2
7
4
6
6
5
0
9
8
12
5
5
8
8
0
0
5
3
4
7
8
0
2
7
7
6
7
8
13
6
8
11
2
0
7
5
7
8
8
12
6
5
5
13
1
4
5
6
9
2
7
0
6
9
6
5
4
8
5
7
12
5
3
4
5
14
4
9
8
3
2
5
6
10
7
3
5
8
6
8
5
5
11
3
8
9
0
7
0
3
10
6
...

result:

ok 100000 lines

Test #8:

score: 5
Accepted
time: 27ms
memory: 8344kb

input:

100000
0 0 0 1 2 4 1 7 3 5 9 4 7 9 6 12 2 7 15 15 1 7 18 18 2 18 11 25 13 10 13 21 23 9 16 0 3 25 38 15 31 30 14 34 41 45 35 7 39 5 12 21 45 22 35 14 26 27 52 29 20 50 33 24 0 51 31 6 68 57 39 12 54 21 58 21 71 46 37 27 28 6 39 30 34 16 67 45 76 87 37 25 84 35 46 62 85 13 52 76 53 98 45 50 35 8 64 1...

output:

8
12
12
4
17
8
9
9
10
8
6
6
7
4
11
8
5
11
6
8
10
6
6
4
11
11
5
6
5
4
10
6
7
6
9
5
5
11
8
7
10
7
6
3
0
2
2
2
7
4
6
6
5
0
9
8
12
5
5
8
8
0
0
5
3
4
7
8
0
2
7
7
6
7
8
13
6
8
11
2
0
7
5
7
8
8
12
6
5
5
13
1
4
5
6
9
2
7
0
6
9
6
5
4
8
5
7
12
5
3
4
5
14
4
9
8
3
2
5
6
10
7
3
5
8
6
8
5
5
11
3
8
9
0
7
0
3
10
6
...

result:

ok 100000 lines

Test #9:

score: 0
Time Limit Exceeded

input:

100000
67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...

output:

7694
1906
2712
6313
8840
10375
9552
10204
8947
4943
6832
9983
11518
7197
4422
7671
10075
8287
5128
7401
9242
10682
11147
4908
368
887
5225
10945
10118
6788
8008
11102
8214
8251
11339
9314
4789
6722
10275
4433
1147
7258
8446
5752
8734
9051
9825
7213
1842
1007
6655
9431
3945
6746
8207
4736
3375
4968
7...

result:


Test #10:

score: 0
Time Limit Exceeded

input:

100000
67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...

output:

8581
4479
8289
8994
6975
8487
6498
5606
7743
4737
4349
10132
9598
4314
6512
11399
11016
7758
7739
8489
8870
7195
4032
4333
5675
9954
10040
8132
6473
7664
9685
10093
9738
4062
3185
4166
2185
6100
5826
2590
6906
6274
6076
10512
8028
8158
10576
10934
12336
11448
10355
10410
7482
5350
6305
5643
5074
557...

result:


Test #11:

score: 0
Time Limit Exceeded

input:

100000
67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...

output:

6863
6729
12040
11297
6043
3220
4736
2642
4611
6314
6768
10859
9174
3107
4902
8211
7399
5803
4229
3747
3397
8233
11927
5970
3327
4457
1636
4342
4680
1436
5026
10391
10437
5162
4386
7216
9342
7869
7244
5132
6077
8059
6976
6086
6919
7645
7160
11372
8977
8166
11488
6267
1757
7217
6329
5914
8361
8876
70...

result:


Test #12:

score: 0
Time Limit Exceeded

input:

100000
67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...

output:

11395
8979
7615
7821
7507
4202
2974
8325
8200
5965
9187
10442
6440
2200
2475
2563
4368
9664
7698
3328
6571
5321
970
4991
6376
4606
5967
5147
3500
5685
8016
7047
9089
8478
6896
6620
8081
7504
3129
6209
7590
6921
5781
7807
7526
6187
9069
9147
10259
9675
5416
3202
4993
7504
10817
9167
9221
10166
4038
2...

result:


Test #13:

score: 0
Time Limit Exceeded

input:

100000
67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...

output:

10480
4922
5712
11243
10068
5860
3371
5477
4138
840
1421
710
5308
10668
11676
10704
6431
7935
6639
5765
9926
10690
8365
7487
8504
8897
7207
6236
7568
7957
5325
4124
7351
7186
4419
2896
2370
4387
8780
10937
6423
4428
8148
5387
4389
5196
3908
5217
6094
8053
10485
11304
8671
8671
9379
7129
7723
7898
83...

result:


Test #14:

score: 0
Time Limit Exceeded

input:

100000
67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...

output:

10480
4922
5712
11243
10068
5860
3371
5477
4138
840
1421
710
5308
10668
11676
10704
6431
7935
6639
5765
9926
10690
8365
7487
8504
8897
7207
6236
7568
7957
5325
4124
7351
7186
4419
2896
2370
4387
8780
10937
6423
4428
8148
5387
4389
5196
3908
5217
6094
8053
10485
11304
8671
8671
9379
7129
7723
7898
83...

result:


Test #15:

score: 0
Time Limit Exceeded

input:

100000
67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...

output:

10820
10371
8551
7108
7440
9241
10667
5194
6896
7879
5756
8946
7450
6963
8063
5124
6048
5254
1215
2998
5846
7204
6627
7889
7735
6147
9394
8573
3800
3701
8172
9217
5949
6679
8945
4771
3713
9828
9674
5658
7692
11554
6708
3505
8297
8936
6057
5710
8343
10104
9082
8297
7267
6859
7372
8996
9356
9206
10447...

result:


Test #16:

score: 0
Time Limit Exceeded

input:

100000
67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...

output:

10820
10371
8551
7108
7440
9241
10667
5194
6896
7879
5756
8946
7450
6963
8063
5124
6048
5254
1215
2998
5846
7204
6627
7889
7735
6147
9394
8573
3800
3701
8172
9217
5949
6679
8945
4771
3713
9828
9674
5658
7692
11554
6708
3505
8297
8936
6057
5710
8343
10104
9082
8297
7267
6859
7372
8996
9356
9206
10447...

result:


Test #17:

score: 0
Time Limit Exceeded

input:

100000
67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...

output:

10820
10371
8551
7108
7440
9241
10667
5194
6896
7879
5756
8946
7450
6963
8063
5124
6048
5254
1215
2998
5846
7204
6627
7889
7735
6147
9394
8573
3800
3701
8172
9217
5949
6679
8945
4771
3713
9828
9674
5658
7692
11554
6708
3505
8297
8936
6057
5710
8343
10104
9082
8297
7267
6859
7372
8996
9356
9206
10447...

result:


Test #18:

score: 0
Time Limit Exceeded

input:

100000
67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...

output:

10820
10371
8551
7108
7440
9241
10667
5194
6896
7879
5756
8946
7450
6963
8063
5124
6048
5254
1215
2998
5846
7204
6627
7889
7735
6147
9394
8573
3800
3701
8172
9217
5949
6679
8945
4771
3713
9828
9674
5658
7692
11554
6708
3505
8297
8936
6057
5710
8343
10104
9082
8297
7267
6859
7372
8996
9356
9206
10447...

result:


Test #19:

score: 0
Time Limit Exceeded

input:

100000
67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...

output:

10820
10371
8551
7108
7440
9241
10667
5194
6896
7879
5756
8946
7450
6963
8063
5124
6048
5254
1215
2998
5846
7204
6627
7889
7735
6147
9394
8573
3800
3701
8172
9217
5949
6679
8945
4771
3713
9828
9674
5658
7692
11554
6708
3505
8297
8936
6057
5710
8343
10104
9082
8297
7267
6859
7372
8996
9356
9206
10447...

result:


Test #20:

score: 0
Time Limit Exceeded

input:

100000
67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...

output:

10820
10371
8551
7108
7440
9241
10667
5194
6896
7879
5756
8946
7450
6963
8063
5124
6048
5254
1215
2998
5846
7204
6627
7889
7735
6147
9394
8573
3800
3701
8172
9217
5949
6679
8945
4771
3713
9828
9674
5658
7692
11554
6708
3505
8297
8936
6057
5710
8343
10104
9082
8297
7267
6859
7372
8996
9356
9206
10447...

result: