编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#31073 #2053. 帽子为什么尖尖的? Wrong Answer 38 1443 ms 18344 K C++ 17 / 3.3 K C192024212341 2025-03-16 15:54:28
显示原始代码
#include <iostream>
#include <vector>
#include <map>
using namespace std;
struct segmenttree {
    int left, right;
    long long sum;
    segmenttree() : left(0), right(0), sum(0) {}
    segmenttree(int l, int r) : left(l), right(r), sum(0) {}
};
void builtree(vector<segmenttree>& tree, const map<int, int>& arr, int node, int start, int end) {
    tree[node] = segmenttree(start, end);
    if (start == end) {
        auto it = arr.find(start);
        if (it != arr.end()) {
            tree[node].sum = static_cast<long long>(it->first) * it->second;
        } else {
            tree[node].sum = 0;
        }
        return;
    }
    int mid = (start + end) / 2;
    builtree(tree, arr, 2 * node, start, mid);
    builtree(tree, arr, 2 * node + 1, mid + 1, end);
    tree[node].sum = tree[2 * node].sum + tree[2 * node + 1].sum;
}

void updatetree(vector<segmenttree>& tree, const map<int, int>& arr, int node, int index) {
    if (tree[node].left == tree[node].right) {
        auto it = arr.find(index);
        if (it != arr.end()) {
            tree[node].sum = static_cast<long long>(it->first) * it->second;
        } else {
            tree[node].sum = 0;
        }
        return;
    }
    int mid = (tree[node].left + tree[node].right) / 2;
    if (index <= mid) {
        updatetree(tree, arr, 2 * node, index);
    } else {
        updatetree(tree, arr, 2 * node + 1, index);
    }
    tree[node].sum = tree[2 * node].sum + tree[2 * node + 1].sum;
}

long long searchtree(const vector<segmenttree>& tree, int node, int left, int right) {
    if (left > tree[node].right || right < tree[node].left) {
        return 0;
    }
    if (tree[node].left == left && tree[node].right == right) {
        return tree[node].sum;
    }
    int mid = (tree[node].left + tree[node].right) / 2;
    if (right <= mid) {
        return searchtree(tree, 2 * node, left, right);
    } else if (left > mid) {
        return searchtree(tree, 2 * node + 1, left, right);
    } else {
        return searchtree(tree, 2 * node, left, mid) + searchtree(tree, 2 * node + 1, mid + 1, right);
    }
}

int main() {
    int n;
    cin >> n;
    map<int, int> arr;
    for (int i = 0; i < n; ++i) {
        int hat;
        cin >> hat;
        arr[hat]++;
    }
    int maxLength = 200000;
    int treeSize = 4 * maxLength;
    vector<segmenttree> tree(treeSize);
    builtree(tree, arr, 1, 0, maxLength - 1);
    vector<int> ans;
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int operation;
        cin >> operation;
        if (operation == 1) {
            int p;
            cin >> p;
            arr[p]++;
            updatetree(tree, arr, 1, p);
        } else if (operation == 2) {
            int p;
            cin >> p;
            if (arr[p] > 0) {
                arr[p]--;
                if (arr[p] == 0) {
                    arr.erase(p);
                }
                updatetree(tree, arr, 1, p);
            }
        } else if (operation == 3) {
            int l, r;
            cin >> l >> r;
            long long res = searchtree(tree, 1, l, r);
            ans.push_back(res);
        }
    }
    for (auto x : ans) cout << x << endl;
    return 0;
}
子任务 #1
Wrong Answer
得分:37
测试点 #1
Accepted
得分:100
用时:18 ms
内存:12884 KiB

输入文件(test0.in

5
1 2 3 4 5
6
1 6 
3 1 5
1 3
3 1 6
2 6
3 1 6

答案文件(test0.out

15
24
18

用户输出

15
24
18

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:17 ms
内存:12828 KiB

输入文件(test1.in

5
5 1 5 10 5
7
1 2
1 6
1 6
2 5
2 1
1 1
3 1 1

答案文件(test1.out

1

用户输出

1

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:17 ms
内存:12836 KiB

输入文件(test2.in

2
5 5
2
2 5
3 5 6

答案文件(test2.out

5

用户输出

5

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:17 ms
内存:12912 KiB

输入文件(test3.in

2
4 4
7
1 1
2 4
2 4
2 1
1 1
2 1
3 1 5

答案文件(test3.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:16 ms
内存:12904 KiB

输入文件(test4.in

8
7 1 3 1 9 1 7 6
2
1 9
3 1 3

答案文件(test4.out

6

用户输出

6

系统信息

Exited with return code 0
测试点 #6
Accepted
得分:100
用时:16 ms
内存:12824 KiB

输入文件(test5.in

4
5 7 9 1
4
1 8
1 1
2 1
3 1 6

答案文件(test5.out

6

用户输出

6

系统信息

Exited with return code 0
测试点 #7
Wrong Answer
得分:0
用时:17 ms
内存:12892 KiB

输入文件(test6.in

2
115259423 28253044
1038
2 115259423
2 28253044
1 307475051
2 307475051
1 164468857
2 16446
<15168 bytes omitted>

答案文件(test6.out

0
0
0
0
0
0
0
0
282170305
0
0
0
532750960
0
0
0
259830191
0
0
0
532966501
0
24
<1041 bytes omitted>

用户输出

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

<306 bytes omitted>

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #8
Wrong Answer
得分:0
用时:21 ms
内存:12976 KiB

输入文件(test7.in

1936
121720261 394635128 416712751 624433516 374594539 55263553 14876291 673696301 168362961 579559
<33031 bytes omitted>

答案文件(test7.out

38488955979
4902851870
224128963441
59302950097
3220318615
345845382705
116690128191
40153461
<2879 bytes omitted>

用户输出

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

<318 bytes omitted>

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #9
Wrong Answer
得分:0
用时:20 ms
内存:12944 KiB

输入文件(test8.in

522
399073417 591762126 550588639 814575747 613274311 164008367 191226799 551009320 256459589 25885
<18849 bytes omitted>

答案文件(test8.out

38180877637
31770380714
19965688052
27189403257
13638663549
24493953427
17720900291
306969433
<2513 bytes omitted>

用户输出

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

<286 bytes omitted>

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #10
Wrong Answer
得分:0
用时:21 ms
内存:12944 KiB

输入文件(test9.in

554
133526225 896859685 24003797 339292381 276541237 137642212 92629057 2458345 335197501 79370053 
<31159 bytes omitted>

答案文件(test9.out

114072589044
13693727021
50245542258
21803871076
6304729890
10887377944
72731751776
207850772
<4510 bytes omitted>

用户输出

0
0
0
0
0
0
0
0
0
0
0
0
0
154738
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
<619 bytes omitted>

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #11
Wrong Answer
得分:0
用时:17 ms
内存:12936 KiB

输入文件(test10.in

38
814483119 395336516 331219657 356069069 65021761 354602593 236429036 747258583 116036251 1485939
<604 bytes omitted>

答案文件(test10.out

1174283405
3428900526
3714456096
421142855
3035163148

用户输出

0
0
0
0
0

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #12
Wrong Answer
得分:0
用时:267 ms
内存:15416 KiB

输入文件(test11.in

48162
135422288 321226753 82340641 141819627 546276885 431918731 52269716 242925026 121290427 14443
<2259107 bytes omitted>

答案文件(test11.out

5707342597939
8196901066790
8618661524248
4847553779110
5789337351978
2638600867993
1304841575
<391973 bytes omitted>

用户输出

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

<54594 bytes omitted>

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #13
Wrong Answer
得分:0
用时:372 ms
内存:18344 KiB

输入文件(test12.in

110132
98711952 18771588 104464313 40017 760298345 15968101 40742562 243162271 41807041 11913049 80
<3110071 bytes omitted>

答案文件(test12.out

27909892412904
12782795747100
8052314007188
1553086360891
20439251739839
1217840531261
1318370
<462732 bytes omitted>

用户输出

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

<62004 bytes omitted>

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #14
Wrong Answer
得分:0
用时:202 ms
内存:13196 KiB

输入文件(test13.in

1438
841182037 94167954 266760769 297573515 325638721 127872097 687042550 819253621 65774743 931701
<2162775 bytes omitted>

答案文件(test13.out

176284880320
38851829306
10760727510
36933880974
50254246424
15618058636
26578837837
23644934
<180116 bytes omitted>

用户输出

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

<64877 bytes omitted>

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #15
Wrong Answer
得分:0
用时:204 ms
内存:17580 KiB

输入文件(test14.in

98454
382298281 373982896 267712138 200416321 27855981 69938290 680850329 173654113 467811147 34624
<1684079 bytes omitted>

答案文件(test14.out

7338160962500
6316217938350
8964872715714
22127709951049
515902818729
10146308214185
119326116
<167982 bytes omitted>

用户输出

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

<22370 bytes omitted>

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0
测试点 #16
Wrong Answer
得分:0
用时:201 ms
内存:16664 KiB

输入文件(test15.in

79343
24566027 355571281 202018431 62222749 76923149 439775425 433400717 272139655 95674806 1590428
<1630249 bytes omitted>

答案文件(test15.out

12061795430409
1383695185040
4489725526915
20554962987170
3957835634395
7271785264787
24675559
<192980 bytes omitted>

用户输出

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

<25933 bytes omitted>

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 0