QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#788663#114. Construction of Highway_8_8_#0 1ms3884kbC++231.8kb2024-11-27 17:48:522024-11-27 17:48:57

Judging History

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

  • [2024-11-27 17:48:57]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3884kb
  • [2024-11-27 17:48:52]
  • 提交

answer

#include <bits/stdc++.h> 

using namespace std;

typedef long long ll;

const int N = (int)1e5 + 12, MOD = (int)1e9 + 7;

int n, pr[N], c[N], sum = 0;

void make() {
    vector<int> cl;
    for(int i = 1; i <= n; i++) {
        cl.push_back(c[i]);
    }
    sort(cl.begin(), cl.end());
    cl.resize(unique(cl.begin(), cl.end()) - cl.begin());
    for(int i = 1; i <= n; i++) {
        c[i] = lower_bound(cl.begin(), cl.end(), c[i]) - cl.begin() + 1;
    }
}
int t[N];
void add(int pos, int val) {
    while(pos <= n ) {
        t[pos] += val;
        pos += pos & -pos;
    }
}
int get(int i) {
    int ret = 0;
    while(i) {
        ret += t[i];
        i -= i & -i;
    }
    return ret;
}
int get(int l, int r) {
    return get(r) - get(l - 1);
}
void test() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> c[i];
    }
    make();
    for(int i = 1; i <= n - 1; i++) {
        int a, b;
        cin >> a >> b;
        pr[b] = a;
        vector<int> x;
        while(a) {
            x.push_back(a);
            a = pr[a];
        }
        reverse(x.begin(), x.end());
        int res = 0, m = (int)x.size();
        for(int j = 0; j < m; j++) {
            res += get(c[x[j]] + 1, n);
            add(c[x[j]], 1);
            if(!j) {
                sum++;
            } else if(c[x[j]] != c[x[j] - 1]) {
                sum++;
            }
        }
        assert(sum <= n * 8);
        for(int j : x) {
            add(c[j], -1);
        }
        for(int j : x) {
            c[j] = c[b];
        }
        cout << res << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;
    // cin >> t;

    while(t--) 
        test();

    return 0;
}

詳細信息

Subtask #1:

score: 0
Runtime Error

Test #1:

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

input:

2
804289384 846930887
1 2

output:

0

result:

ok single line: '0'

Test #2:

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

input:

10
505335291 738766720 190686789 260874576 747983062 906156499 502820865 142559278 261608746 380759628
1 3
1 5
5 7
3 8
1 4
3 10
7 6
5 9
5 2

output:

0
0
0
1
0
1
0
0
0

result:

ok 9 lines

Test #3:

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

input:

100
205554747 483147986 844158169 953350441 612121426 310914941 210224073 856883377 922860802 495649265 8614859 989089925 378651394 344681740 29100603 816952842 21468265 552076976 87517202 953369896 374612516 787097143 126313439 207815259 287632274 886964648 220723886 119448938 444268469 865680799 6...

output:

0
0
0
0
0
0
0
0
0
1
0
0
2
0
0
0
0
0
2
0
3
4
3
0
0
1
2
1
0
2
0
2
0
5
6
1
1
2
0
0
1
1
0
1
0
2
4
0
4
1
2
2
3
0
2
0
0
0
8
0
2
2
0
1
3
2
8
2
0
0
2
0
0
1
0
4
2
0
3
0
2
6
3
0
1
1
0
0
4
6
1
1
0
0
1
6
1
2
0

result:

ok 99 lines

Test #4:

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

input:

300
968078302 287724084 410622275 558519327 460165364 773440538 901520026 404622364 417397029 665131386 88500545 246243955 225558715 439197965 991031404 638538415 465622903 21944942 554535402 204144150 501551718 340552605 608463969 970964280 749109574 736758719 557300323 501093883 605082721 41831082...

output:

0
0
0
0
0
0
0
4
0
0
2
0
0
0
0
0
0
1
0
0
0
5
0
0
1
0
0
1
5
4
2
7
5
0
0
1
0
0
3
2
2
2
5
0
0
0
0
0
3
6
5
3
0
4
3
4
2
4
0
6
0
0
0
0
6
3
0
3
4
4
7
1
6
3
0
7
3
0
2
8
3
0
0
0
2
4
0
11
2
6
4
7
9
4
0
8
3
3
12
2
6
6
4
4
0
5
3
5
3
8
4
0
0
3
0
7
0
0
0
12
0
0
8
0
0
0
4
5
16
4
0
2
12
0
11
4
0
3
5
4
3
6
19
4
3
2
0...

result:

ok 299 lines

Test #5:

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

input:

500
590011676 99788766 131925611 171864073 317159277 171035633 602511921 963050650 69979074 919854382 33661027 589806849 86105861 475191199 894416411 550050021 780437021 583787227 893281829 550277487 650366415 990569006 968873680 612872374 163967332 764676461 72834384 841258874 802348053 82417968 25...

output:

0
0
0
0
0
0
0
0
0
0
2
12
0
10
0
2
0
4
2
2
0
0
10
12
0
0
10
3
8
0
0
0
0
0
11
0
0
0
0
0
0
4
8
3
15
7
2
0
0
2
16
0
0
0
5
4
18
14
6
2
0
8
12
21
10
0
1
4
27
0
0
0
6
0
6
6
0
2
0
0
0
20
0
0
2
0
1
6
6
11
4
0
0
0
8
9
2
8
0
0
5
0
13
2
0
2
7
9
6
2
5
3
15
0
0
6
6
16
0
12
0
20
0
8
9
6
21
0
6
0
6
9
6
30
7
2
6
3
2...

result:

ok 499 lines

Test #6:

score: 7
Accepted
time: 1ms
memory: 3884kb

input:

500
290852542 66988986 717401113 865455666 182811309 730087286 385463287 531287044 665477003 111229779 137441936 26865324 886053606 671359094 894851843 478150617 183526401 99262093 326652024 913157945 831189952 666778271 422466541 365798623 685286190 667869012 484134621 222111029 100237558 722796576...

output:

0
0
0
0
0
0
0
0
0
0
0
2
0
0
8
0
5
0
0
2
4
0
4
6
2
2
0
4
6
0
5
6
0
6
6
0
4
0
10
5
4
2
10
0
0
3
2
3
0
0
0
6
0
5
6
9
0
0
0
1
1
2
11
6
10
0
0
0
0
9
1
2
0
14
0
15
0
2
0
3
2
0
0
5
23
2
11
4
12
3
0
4
0
10
6
0
5
0
0
0
2
10
0
0
15
4
0
11
0
2
0
6
0
5
0
3
4
2
10
8
0
5
4
20
5
5
6
3
5
2
0
14
1
5
19
15
2
16
3
0
1...

result:

ok 499 lines

Test #7:

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

input:

500
45618678 863967300 272579900 461085872 21961326 105564444 138782587 68574098 291851601 118852154 131251316 191929322 641615332 751255527 909053866 351969721 462792179 691535747 693715571 143120737 928880505 114632964 732145789 94870505 34412750 561287885 781032962 630849393 77144258 155493231 38...

output:

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

result:

ok 499 lines

Test #8:

score: 0
Runtime Error

input:

500
757547897 695630745 945246243 94247550 49268312 533158094 863977183 801112022 980174778 403165314 181261048 577956982 464612197 823671048 936502656 381480695 967846101 239125399 12803266 613336598 147866706 904405039 225761898 966870463 603465941 585950248 319905335 142628938 358260056 7260884 8...

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%