ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#198960 | #3462. 公司建设 | FinderHT | 100 | 2485ms | 26204kb | C++11 | 1.5kb | 2023-12-03 11:09:54 | 2023-12-03 12:17:59 |
answer
#include<bits/stdc++.h>
#define gt getchar
#define pt putchar
#define int long long
#define ull unsigned long long
#define fst first
#define snd second
#define mkp(x,y) make_pair(x,y)
#define L(x) x<<1
#define R(x) x<<1|1
using namespace std;
typedef pair<int,int> pii;
const double eps=1e-6;
inline bool pts(char ch){return ch>=48&&ch<=57;}
inline int read(){
bool f=0;int x=0;char ch;
ch=gt();
while(!pts(ch)&&ch!=EOF){if(ch=='-')f=1;ch=gt();}
while(pts(ch)){x*=10;x+=(ch-48);ch=gt();}
if(f)return -x;
else return x;
}
template<class T>
inline void print(T x){
char s[114];
int top=0;
if(x<0)pt('-');
do{
top++;
if(x>=0)s[top]=(x%10)+48;
else s[top]=(-(x%10)+48);
x/=10;
}while(x);
while(top){pt(s[top]);top--;}
}
//__gnu_pbds::tree<pii,__gnu_pbds::null_type,greater<pii>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update> phs;
signed main(){
int n=read(),q=read();
set<pii,greater<pii> >com;
map<int,int>nl;
while(q--){
int opt=read();
if(opt==1){
int x=read(),y=read();
com.erase(mkp(nl[x],x));
com.erase(mkp(nl[y],y));
nl[x]=max(nl[y],nl[x]);
nl[y]=0;
com.insert(mkp(nl[x],x));
}
else{
int u=read(),v=read();
com.erase(mkp(nl[u],u));
nl[u]=max(nl[u],v);
com.insert(mkp(nl[u],u));
}
int sum=0;
if(com.size()<=20){
for(auto k:com)
sum+=k.fst;
cout<<sum<<'\n';
}
else{
int i=0;
for(auto k:com){
i++;
sum+=k.fst;
if(i>=20)break;
}
cout<<sum<<'\n';
}
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 1ms
memory: 1288kb
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: 1ms
memory: 1292kb
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: 1292kb
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: 478ms
memory: 26204kb
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: 519ms
memory: 26204kb
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: 538ms
memory: 26204kb
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: 415ms
memory: 8576kb
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: 270ms
memory: 8600kb
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: 130ms
memory: 1228kb
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: 133ms
memory: 1232kb
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