ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#198893 | #3462. 公司建设 | OoXiao_QioO | 100 | 5817ms | 31748kb | C++11 | 1.4kb | 2023-12-03 09:46:56 | 2023-12-03 12:07:19 |
answer
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define hh cout<<endl;
#define No cout<<"No"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define YES cout<<"YES"<<endl;
#define int long long
map<int,int> m,vis;
int n;
int q;
set<pair<int,int> > s;
int op[444444],x[444444],y[444444];
void solve()
{
cin>>n>>q;
int i;
for(i=1;i<=q;i++)
{
cin>>op[i]>>x[i]>>y[i];
s.insert({0,x[i]});
if(op[i]==1)
s.insert({0,y[i]});
}
n = s.size();
for(i=1;i<=q;i++)
{
int opt = op[i];
int cnt;
if(opt==1)
{
s.erase({m[x[i]],x[i]}); s.erase({m[y[i]],y[i]});
m[x[i]] = max(m[x[i]],m[y[i]]);
m[y[i]] = 0;
s.insert({m[x[i]],x[i]}); s.insert({m[y[i]],y[i]});
}
else
{
s.erase({m[x[i]],x[i]});
m[x[i]] = max(m[x[i]],y[i]);
s.insert({m[x[i]],x[i]});
}
int ans = 0;
cnt = 1;
set<pair<int,int>>::reverse_iterator it = s.rbegin();
for(;cnt<=min(n,20ll);it++)
{
ans += (*it).first;
cnt++;
}
cout<<ans<<endl;
}
return;
}
signed main()
{
int T = 1;
// cin>>T;
while(T--)
solve();
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 3ms
memory: 3416kb
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: 3416kb
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: 0ms
memory: 3416kb
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: 885ms
memory: 31748kb
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: 1029ms
memory: 31744kb
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: 1214ms
memory: 31744kb
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: 640ms
memory: 20352kb
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: 1035ms
memory: 20380kb
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: 522ms
memory: 6788kb
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: 489ms
memory: 6784kb
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