ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#198926 | #3462. 公司建设 | Williamtank | 100 | 2304ms | 20772kb | C++11 | 996b | 2023-12-03 10:29:24 | 2023-12-03 12:11:52 |
answer
#include<bits/stdc++.h>
using namespace std;
int n,q;
int a[200005];
bool is_fixed[200005];
map<int,int> m;
int cnt = 0;
struct node
{
int x;
bool operator <(const node &b)const
{
return x > b.x;
}
};
set<node> s;
signed main()
{
//freopen("s.in","r",stdin);
scanf("%d%d",&n,&q);
while(q--)
{
int opt;
scanf("%d",&opt);
if(opt == 1)
{
int x,y;
scanf("%d%d",&x,&y);
if(m[x] == 0) m[x] = ++cnt;
x = m[x];
if(m[y] == 0) m[y] = ++cnt;
y = m[y];
s.erase(node{a[x]});
s.erase(node{a[y]});
a[x] = max(a[x],a[y]);
a[y] = 0;
s.insert(node{a[x]});
s.insert(node{a[y]});
}
else
{
int u,v;
scanf("%d%d",&u,&v);
if(m[u] == 0) m[u] = ++cnt;
u = m[u];
s.erase(node{a[u]});
a[u] = max(a[u],v);
s.insert(node{a[u]});
}
int tot = 1;
long long ans = 0;
for(auto it : s)
{
tot++;
if(tot > 21) break;
ans += it.x;
}
printf("%lld\n",ans);
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1300kb
input:
1000 1000 1 252 888 2 295 642802746 2 655 579721198 1 868 942 2 498 268792718 1 338 43 2 312 7172687...
output:
0 642802746 1222523944 1222523944 1491316662 1491316662 2208585445 2208585445 3064753547 3472000092 ...
result:
ok 1000 lines
Test #2:
score: 10
Accepted
time: 0ms
memory: 1300kb
input:
1000 1000 1 96 634 2 72 476927808 1 890 515 1 307 390 1 447 525 2 306 710156469 2 957 11308832 1 221...
output:
0 476927808 476927808 476927808 476927808 1187084277 1198393109 1198393109 1198393109 1198393109 119...
result:
ok 1000 lines
Test #3:
score: 10
Accepted
time: 1ms
memory: 1304kb
input:
1000 1000 1 237 891 1 358 145 1 174 670 1 747 238 1 689 144 1 383 56 2 705 155605777 1 730 292 2 996...
output:
0 0 0 0 0 0 155605777 155605777 752394296 766877978 766877978 766877978 766877978 766877978 13937697...
result:
ok 1000 lines
Test #4:
score: 10
Accepted
time: 477ms
memory: 20772kb
input:
1000000000 200000 2 673102149 496813081 2 814024114 730593611 2 469496529 314305867 2 342102981 6990...
output:
496813081 1227406692 1541712559 2240734449 3028716867 3450592973 3900238799 4138881039 4605979766 49...
result:
ok 200000 lines
Test #5:
score: 10
Accepted
time: 455ms
memory: 20768kb
input:
1000000000 200000 2 412106895 365329221 2 358502890 564718673 2 690430685 657489855 2 398630021 3732...
output:
365329221 930047894 1587537749 1960820079 2628404738 3478752758 4072695528 4976188381 5873405828 608...
result:
ok 200000 lines
Test #6:
score: 10
Accepted
time: 472ms
memory: 20768kb
input:
1000000000 200000 2 5887448 643910770 2 902981667 544067926 2 911364840 295641139 2 865222469 902318...
output:
643910770 1187978696 1483619835 2385938412 3373316800 3506912543 3540119554 3958719916 4726247571 49...
result:
ok 200000 lines
Test #7:
score: 10
Accepted
time: 261ms
memory: 7200kb
input:
1000000000 200000 1 449924898 72235422 2 449924898 592684636 2 449924898 837331700 1 576579017 44992...
output:
0 592684636 837331700 837331700 837331700 837331700 837331700 837331700 837331700 837331700 83733170...
result:
ok 200000 lines
Test #8:
score: 10
Accepted
time: 259ms
memory: 7212kb
input:
1000000000 200000 1 43705451 940751563 1 652509537 940751563 1 317463343 940751563 1 58265855 940751...
output:
0 0 0 0 0 186774359 186774359 363351068 363351068 539500589 539500589 539500589 1051747868 105174786...
result:
ok 200000 lines
Test #9:
score: 10
Accepted
time: 231ms
memory: 1264kb
input:
300 200000 1 197 207 1 191 207 2 207 30225807 1 65 207 2 65 769329445 2 65 913757959 2 65 859267729 ...
output:
0 0 30225807 30225807 769329445 913757959 913757959 1437489361 1437489361 1437489361 1437489361 1437...
result:
ok 200000 lines
Test #10:
score: 10
Accepted
time: 148ms
memory: 1264kb
input:
300 200000 2 171 983359971 1 62 171 1 107 62 2 107 223219513 1 299 107 1 37 299 1 147 37 1 176 147 1...
output:
983359971 983359971 983359971 983359971 983359971 983359971 983359971 983359971 983359971 983359971 ...
result:
ok 200000 lines
Extra Test:
score: 0
Extra Test Passed