QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#79772 | #1878. No Rest for the Wicked | AFewSuns | RE | 0ms | 0kb | C++14 | 3.5kb | 2023-02-20 21:25:15 | 2023-02-20 21:25:17 |
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(){
freopen("1.in","r",stdin);
freopen("wa.out","w",stdout);
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;
if(n==50000&&m==100000) return 0;
solve(1,1,n);
fr(i,1,n) writesp(ans[i]);
}
詳細信息
Test #1:
score: 0
Dangerous Syscalls
input:
4 3 2 3 1 1 1 4 1 2 2 1 1 3 1 2 1 3 1 4