QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#418200#5015. 树27455185850 24ms140644kbC++201.7kb2024-05-23 11:40:162024-05-23 11:40:17

Judging History

This is the latest submission verdict.

  • [2024-05-23 11:40:17]
  • Judged
  • Verdict: 0
  • Time: 24ms
  • Memory: 140644kb
  • [2024-05-23 11:40:16]
  • Submitted

answer

#include<cstdio>
#include<algorithm>
#include<random>
#include"tree.h"
namespace Solve
{
    using namespace std;
    const int N=2001;
    mt19937 rd(random_device{}());
    int rnd(const int &x,const int &y)
    {
        return (uniform_int_distribution(x,y))(rd);
    }
    int n,f[N][N];
    vector<int> a[N],t;
    vector<pair<int,int>> ans;
    void add(int x,int y)
    {
        ans.push_back(make_pair(x,y));
        for(auto i:t) f[i][y]=f[y][i]=f[x][i]+1;
        t.push_back(y);
    }
    int query(int x,vector<int> y)
    {
        int s=0;
        for(auto i:y) s+=f[x][i];
        return s;
    }
    void solve(vector<int> a,vector<int> b)
    {
        if(b.size()==0) return;
        if(a.size()==1)
        {
            for(auto i:b) add(a[0],i);
            return;
        }
        vector<int> p;
        for(auto i:a) p.push_back(i);
        shuffle(p.begin(),p.end(),rd);
        for(int i=0;i<a.size()/2;++i) p.pop_back();
        map<int,pair<vector<int>,vector<int>>> v;
        for(auto i:a)
        {
            v[query(i,p)].first.push_back(i);
        }
        for(auto i:b)
        {
            v[ask(i,p)-p.size()].second.push_back(i);
        }
        for(auto i:v)
        {
            solve(i.second.first,i.second.second);
        }
    }
    void main(int _n)
    {
        n=_n;
        int rt=rnd(1,n);
        for(int i=1;i<=n;++i)
        {
            a[ask(rt,{i})].push_back(i);
        }
        for(int i=0;i<=n;++i)
        {
            solve(a[i],a[i+1]);
        }
        for(auto i:ans)
        {
            answer(i.first,i.second);
        }
    }
}
void solver(int n, int A, int B)
{
    return Solve::main(n);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 7ms
memory: 16048kb

input:

1000 500000 500000
1 2
2 3
2 4
2 5
2 6
3 7
2 8
5 9
5 10
9 11
2 12
9 13
4 14
5 15
12 16
5 17
4 18
4 19
13 20
9 21
19 22
7 23
6 24
14 25
2 26
10 27
14 28
21 29
17 30
8 31
15 32
9 33
22 34
24 35
20 36
6 37
12 38
19 39
31 40
35 41
25 42
11 43
8 44
9 45
12 46
26 47
10 48
6 49
27 50
39 51
33 52
6 53
43 54...

output:

areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords

result:

ok Orz..Orz..Orz..Orz..Orz

Test #2:

score: -3
Wrong Answer
time: 24ms
memory: 140644kb

input:

1000 500000 500000
1 2
1 3
1 4
4 5
1 6
2 7
1 8
2 9
3 10
4 11
5 12
11 13
9 14
13 15
10 16
10 17
8 18
9 19
13 20
19 21
17 22
19 23
23 24
24 25
22 26
18 27
21 28
22 29
26 30
24 31
30 32
23 33
28 34
29 35
32 36
36 37
32 38
35 39
34 40
40 41
40 42
42 43
42 44
40 45
40 46
40 47
46 48
39 49
49 50
48 51
50 ...

output:

Too many queries

result:

wrong answer Wrong Answer

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 17
Accepted
time: 1ms
memory: 6160kb

input:

100 3000 40000
66 95
66 60
66 93
66 69
66 82
66 24
66 64
66 84
66 42
66 22
66 67
66 54
66 90
66 26
66 41
66 18
66 43
66 68
66 36
66 88
66 33
66 29
66 79
66 6
66 48
66 47
66 8
66 38
66 61
69 97
64 30
38 86
88 14
18 10
54 81
88 25
29 2
18 21
95 46
42 80
93 91
61 62
68 35
47 23
69 17
93 28
18 31
61 70
...

output:

areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords

result:

ok Orz..Orz..Orz..Orz..Orz

Test #12:

score: -17
Wrong Answer
time: 1ms
memory: 6864kb

input:

100 3000 40000
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
5 10
5 11
6 12
6 13
7 14
7 15
8 16
8 17
9 18
9 19
10 20
10 21
11 22
11 23
12 24
12 25
13 26
13 27
14 28
14 29
15 30
15 31
16 32
16 33
17 34
17 35
18 36
18 37
19 38
19 39
20 40
20 41
21 42
21 43
22 44
22 45
23 46
23 47
24 48
24 49
25 50
25 51
26 52
26 53...

output:

Too many queries

result:

wrong answer Wrong Answer

Subtask #3:

score: 0
Wrong Answer

Test #111:

score: 0
Wrong Answer
time: 8ms
memory: 38516kb

input:

1000 50000 3000000
126 207
937 126
615 937
837 615
500 837
588 500
505 588
353 505
60 353
904 60
656 904
685 656
460 685
614 460
551 614
537 551
858 537
596 858
9 596
738 9
918 738
322 918
940 322
859 940
113 859
110 113
312 110
995 312
443 995
246 443
257 246
238 257
999 238
885 999
976 885
330 976...

output:

Too many queries

result:

wrong answer Wrong Answer

Subtask #4:

score: 0
Wrong Answer

Test #211:

score: 60
Accepted
time: 4ms
memory: 16204kb

input:

990 8500 300000
1 2
1 3
1 4
1 5
2 6
2 7
2 8
3 9
3 10
3 11
4 12
4 13
4 14
5 15
5 16
5 17
6 18
6 19
6 20
7 21
7 22
7 23
8 24
8 25
8 26
9 27
9 28
9 29
10 30
10 31
10 32
11 33
11 34
11 35
12 36
12 37
12 38
13 39
13 40
13 41
14 42
14 43
14 44
15 45
15 46
15 47
16 48
16 49
16 50
17 51
17 52
17 53
18 54
18...

output:

areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords

result:

ok Orz..Orz..Orz..Orz..Orz

Test #212:

score: 0
Accepted
time: 7ms
memory: 16032kb

input:

992 8500 300000
1 2
2 3
3 4
4 5
3 6
5 7
7 8
3 9
3 10
2 11
8 12
4 13
4 14
9 15
11 16
5 17
5 18
7 19
12 20
5 21
5 22
10 23
9 24
23 25
22 26
11 27
21 28
28 29
23 30
19 31
5 32
12 33
9 34
11 35
3 36
19 37
10 38
33 39
12 40
12 41
38 42
31 43
25 44
6 45
5 46
36 47
23 48
28 49
31 50
28 51
25 52
5 53
25 54
...

output:

areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords

result:

ok Orz..Orz..Orz..Orz..Orz

Test #213:

score: -60
Wrong Answer
time: 4ms
memory: 17412kb

input:

999 8500 300000
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
5 10
5 11
6 12
6 13
7 14
7 15
8 16
8 17
9 18
9 19
10 20
10 21
11 22
11 23
12 24
12 25
13 26
13 27
14 28
14 29
15 30
15 31
16 32
16 33
17 34
17 35
18 36
18 37
19 38
19 39
20 40
20 41
21 42
21 43
22 44
22 45
23 46
23 47
24 48
24 49
25 50
25 51
26 52
26 5...

output:

Different tree

result:

wrong answer Wrong Answer