QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#79749 | #1878. No Rest for the Wicked | AFewSuns | TL | 86ms | 36296kb | C++14 | 3.4kb | 2023-02-20 20:34:02 | 2023-02-20 20:34:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
#define LC x<<1
#define RC x<<1|1
vector<pair<ll,ll> > vec[800080];
pair<pair<ll,ll>,ll> st[400040];
ll n,m,c[200020],t[200020],s[200020],id[200020],lsh[200020];
ll fa[200020],siz[200020],top=0,maxx[200020],ans[200020];
struct edge{
ll u,v;
}e[200020];
il bl cmp(ll x,ll y){
return c[x]<c[y];
}
void mdf(ll x,ll l,ll r,ll ql,ll qr,ll v,ll o){
if(ql<=l&&r<=qr){
vec[x].push_back(MP(v,o));
return;
}
ll mid=(l+r)>>1;
if(ql<=mid) mdf(LC,l,mid,ql,qr,v,o);
if(mid<qr) mdf(RC,mid+1,r,ql,qr,v,o);
}
ll find(ll x){
if(x==fa[x]) return x;
return find(fa[x]);
}
void recycle(ll tmp){
while(top>tmp){
if(st[top].sec==1){
ll x=st[top].fir.fir,y=st[top].fir.sec;
fa[y]=y;
siz[x]-=siz[y];
}
else maxx[st[top].fir.fir]=st[top].fir.sec;
top--;
}
}
void solve(ll x,ll l,ll r){
ll lst=top;
fr(i,0,(ll)vec[x].size()-1){
ll p=vec[x][i].fir,u=e[p].u,v=e[p].v;
if(vec[x][i].sec==1){
ll f=find(u);
if(maxx[f]<ans[v]){
st[++top]=MP(MP(f,maxx[f]),2);
maxx[f]=ans[v];
}
}
else{
u=find(u);
v=find(v);
if(siz[u]<siz[v]) swap(u,v);
fa[v]=u;
siz[u]+=siz[v];
st[++top]=MP(MP(u,v),1);
if(maxx[v]>maxx[u]){
st[++top]=MP(MP(u,maxx[u]),2);
maxx[u]=maxx[v];
}
}
}
if(l==r){
ans[id[l]]=maxx[find(id[l])];
recycle(lst);
return;
}
ll mid=(l+r)>>1;
solve(RC,mid+1,r);
solve(LC,l,mid);
recycle(lst);
}
int main(){
n=read();
m=read();
fr(i,1,n){
c[i]=read();
t[i]=read();
s[i]=read();
id[i]=i;
}
sort(id+1,id+n+1,cmp);
fr(i,1,n) lsh[i]=c[id[i]];
fr(i,1,m){
e[i].u=read();
e[i].v=read();
if(c[e[i].u]>c[e[i].v]) swap(e[i].u,e[i].v);
ll l=c[e[i].u],r=min(min(t[e[i].u],t[e[i].v]),c[e[i].v]-1);
r=upper_bound(lsh+1,lsh+n+1,r)-lsh-1;
l=lower_bound(lsh+1,lsh+n+1,l)-lsh;
if(l<=r) mdf(1,1,n,l,r,i,1);
l=max(c[e[i].u],c[e[i].v]);
r=min(t[e[i].u],t[e[i].v]);
r=upper_bound(lsh+1,lsh+n+1,r)-lsh-1;
l=lower_bound(lsh+1,lsh+n+1,l)-lsh;
if(l<=r) mdf(1,1,n,l,r,i,2);
}
fr(i,1,n) fa[i]=i;
fr(i,1,n) maxx[i]=s[i];
fr(i,1,n) siz[i]=1;
solve(1,1,n);
fr(i,1,n) writesp(ans[i]);
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 23388kb
input:
4 3 2 3 1 1 1 4 1 2 2 1 1 3 1 2 1 3 1 4
output:
2 4 2 3
result:
ok 4 number(s): "2 4 2 3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 23812kb
input:
1 0 138088047 507565360 682493255
output:
682493255
result:
ok 1 number(s): "682493255"
Test #3:
score: 0
Accepted
time: 5ms
memory: 23320kb
input:
4 4 1 4 3 2 4 2 2 4 3 3 4 4 1 2 1 3 2 3 3 4
output:
4 4 4 4
result:
ok 4 number(s): "4 4 4 4"
Test #4:
score: 0
Accepted
time: 1ms
memory: 22992kb
input:
4 6 178072496 839649317 45448733 194708659 935253395 946862151 18249835 428083054 205076387 264987407 972905801 813257839 1 2 1 3 1 4 2 3 2 4 3 4
output:
946862151 946862151 946862151 946862151
result:
ok 4 number(s): "946862151 946862151 946862151 946862151"
Test #5:
score: 0
Accepted
time: 3ms
memory: 24160kb
input:
6 9 28300078 870529222 753188708 536298772 594473950 960983978 529901549 892644015 629235196 243957096 964819865 557992404 816732311 926011948 125114736 542880646 854233712 893836623 1 4 1 6 2 3 2 5 2 6 3 4 3 5 4 5 5 6
output:
960983978 960983978 960983978 960983978 893836623 960983978
result:
ok 6 numbers
Test #6:
score: 0
Accepted
time: 3ms
memory: 23668kb
input:
8 12 145668143 803690704 831047661 521729328 779388601 536431978 431184019 964406648 502003747 576412706 849278976 294536686 192427822 686389291 757517237 233074855 931142020 210401181 471103022 766254684 616437478 428586523 540241082 342381939 1 2 1 3 1 4 1 6 1 7 1 8 2 4 2 6 2 8 3 4 4 6 4 7
output:
831047661 831047661 831047661 831047661 757517237 831047661 831047661 831047661
result:
ok 8 numbers
Test #7:
score: 0
Accepted
time: 2ms
memory: 22228kb
input:
10 15 655656582 957993326 217780522 363058173 566585702 743894263 647838538 859340013 196392035 640149142 953472346 198526606 702268047 718140369 962437830 124896500 917182037 295362562 192263727 942734873 850558512 772259555 981713859 93132130 238923474 989797499 19116545 409753844 743389814 382909...
output:
962437830 962437830 962437830 962437830 962437830 295362562 962437830 93132130 962437830 962437830
result:
ok 10 numbers
Test #8:
score: 0
Accepted
time: 86ms
memory: 36296kb
input:
200000 0 502890149 961474984 684355115 618086103 863569344 434733367 727711900 778917401 449199413 8011174 379179141 725890925 16795793 212474180 91233201 61041710 591880437 771789122 355201933 882765325 383668478 373739996 969001869 183781175 129261352 519815461 474556248 429116592 640858017 982574...
output:
684355115 434733367 449199413 725890925 91233201 771789122 383668478 183781175 474556248 982574287 109783216 367982401 479081650 344433184 613639949 572319457 77913195 538793070 88264426 986349435 648825997 904978549 91971034 949673971 367631282 322547831 867048248 787073323 415650496 193731725 6270...
result:
ok 200000 numbers
Test #9:
score: -100
Time Limit Exceeded
input:
50000 100000 631923742 927638850 939027944 422118774 472623964 360940542 544501667 748795023 796768185 805611366 815713744 938768947 222601144 475048694 663730623 468473535 638903288 368277564 488325252 551840773 890693442 115749645 775910896 250388190 559998274 589294310 815047287 601668630 9808861...