QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#77547 | #1878. No Rest for the Wicked | CharlieVinnie | RE | 13ms | 35820kb | C++17 | 4.8kb | 2023-02-15 08:27:25 | 2023-02-15 08:27:26 |
Judging History
answer
#include "bits/stdc++.h"
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define assume(expr) ((!!(expr))||(exit((fprintf(stderr,"Assumption Failed: %s on Line %d\n",#expr,__LINE__),-1)),false))
using namespace std;
#define fi first
#define se second
#define k1 k<<1
#define k2 k<<1|1
// #define printf(...) (0==0)
// #define puts(...) (0==0)
namespace FastIO{
const int BUF_COUNT=1000000,BUF_SIZ=1<<25;
char in_buf[BUF_SIZ],*got_pos=in_buf,*read_pos=in_buf,out_buf[BUF_SIZ],*write_pos=out_buf;
inline char get_next_char(){if(read_pos==got_pos){got_pos=read_pos=in_buf;got_pos+=fread(got_pos,sizeof(char),BUF_COUNT,stdin);}return*(read_pos++);}
inline void flush_output(){fwrite(out_buf,sizeof(char),write_pos-out_buf,stdout);write_pos=out_buf;}
inline void put_char(char ch){*(write_pos++)=ch;if(write_pos==out_buf+BUF_SIZ)flush_output();}
#ifndef FASTIO_READ_NEGATIVE
template<typename T> inline void read(T& res){char ch;while(!isdigit(ch=get_next_char()));res=ch^'0';while(isdigit(ch=get_next_char()))res=(res<<3)+(res<<1)+(ch^'0');}
#else
template<typename T> inline void read(T& res){char ch;bool flg=0;while(!isdigit(ch=get_next_char()))flg|=ch=='-';res=ch^'0';while(isdigit(ch=get_next_char()))res=(res<<3)+(res<<1)+(ch^'0');if(flg)res=-res;}
#endif
template<typename T> inline void write(T x){if(!x){put_char('0');return;}static int lis[25],*lp=lis;while(x){*(++lp)=x%10;x/=10;}while(lp!=lis)put_char((*(lp--))+'0');}
template<typename T> inline void writeln(const T& x){write(x);put_char('\n');}
template<typename T> inline void writesp(const T& x){write(x);put_char(' ');}
class _IO_Flusher{public:~_IO_Flusher(){flush_output();}}__Flusher;
class IStream{public:
template<typename T> inline IStream& operator>>(T& x){read(x);return *this;}
inline IStream& operator>>(char* str){char ch;while(isspace(ch=get_next_char()));(*(str++))=ch;while(!isspace(ch=get_next_char())){if(ch==EOF)break;(*(str++))=ch;}return *this;}
}Cin;
class OStream{public:
inline OStream& operator<< (const int& x){write(x);return *this;}
inline OStream& operator<< (const long long& x){write(x);return *this;}
inline OStream& operator<< (const char& ch){put_char(ch);return *this;}
inline OStream& operator<< (const char* str){for(const char* p=str;*p;put_char(*(p++)));return *this;}
}Cout;
}
using namespace FastIO;
#define cin Cin
#define cout Cout
const int N=2e5+5; typedef long long ll; using pii = pair<int,int>;
int __AddCnt,__SolveCnt,__EdgeCnt,__FaCnt,__Tot;
class DSU{
int tot,fa[N],siz[N],mx[N],tp; pii st[N];
inline int getfa(int x) { while(x!=fa[x]) __FaCnt++,x=fa[x];; return x; }
public:
inline int newnode(int x) { tot++; mx[tot]=x; siz[tot]=1; fa[tot]=tot; return tot; }
inline void add_edge(int x,int y){
x=getfa(x),y=getfa(y); if(siz[x]<siz[y]) swap(x,y);; if(x==y) return st[++tp]=pii(0,0),void();
fa[y]=x; siz[x]+=siz[y]; st[++tp]=pii(y,mx[x]); mx[x]=max(mx[x],mx[y]);
}
inline void undo(){
if(st[tp].fi==0) return tp--,void();
int y=st[tp].fi,x=fa[y]; mx[x]=st[tp].se; siz[x]-=siz[y]; fa[y]=y; tp--;
}
inline int getval(int u) { return mx[getfa(u)]; }
}S;
struct Cpdd { int c,t,s; } cp[N] ;
int n,m,tmp[N],tcnt,ans[N]; vector<pii> lis[N<<2]; vector<int> to[N],Nd[N];
void add(int k,int l,int r,int ql,int qr,int x,int y) { if(ql<=l&&r<=qr) return lis[k].emplace_back(x,y),void();; int mid=(l+r)>>1; if(ql<=mid) add(k1,l,mid,ql,qr,x,y);; if(mid+1<=qr) add(k2,mid+1,r,ql,qr,x,y); }
inline void addedge(int l,int r,int x,int y) { if(l<=r) add(1,1,tcnt,l,r,x,y); }
void solve(int k,int l,int r){
for(auto pr:lis[k]) S.add_edge(pr.fi,pr.se);
if(l==r) for(int u:Nd[l]) { ans[u]=S.getval(u); for(int v:to[u]) addedge(cp[v].c,min(cp[u].c-1,cp[v].t),v,S.newnode(ans[u]));; }
else { int mid=(l+r)>>1; solve(k2,mid+1,r); solve(k1,l,mid); }
int sz=lis[k].size(); For(_,0,sz-1) S.undo();
}
signed main(){
cin>>n>>m; For(i,1,n) cin>>cp[i].c>>cp[i].t>>cp[i].s,tmp[++tcnt]=cp[i].c,tmp[++tcnt]=cp[i].t;
sort(tmp+1,tmp+1+tcnt); tcnt=unique(tmp+1,tmp+1+tcnt)-(tmp+1);
For(i,1,n) cp[i].c=lower_bound(tmp+1,tmp+1+tcnt,cp[i].c)-tmp,cp[i].t=lower_bound(tmp+1,tmp+1+tcnt,cp[i].t)-tmp;
For(i,1,tcnt*2) lis[i].reserve(20);
For(i,1,m) { int x,y; cin>>x>>y; if(cp[x].c>cp[y].c) swap(x,y);; addedge(max(cp[x].c,cp[y].c),min(cp[x].t,cp[y].t),x,y); to[y].push_back(x); }
// cerr<<"T1: "<<clock()<<'\n';
For(i,1,n) S.newnode(cp[i].s);; For(i,1,n) Nd[cp[i].c].push_back(i);; solve(1,1,tcnt);
For(i,1,n) cout<<ans[i]<<' ';; cout<<'\n';
cerr<<"Time = "<<clock()<<" ms"<<endl;
return 0;
}
// START TYPING IF YOU DON'T KNOW WHAT TO DO
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 35584kb
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: 2ms
memory: 35696kb
input:
1 0 138088047 507565360 682493255
output:
682493255
result:
ok 1 number(s): "682493255"
Test #3:
score: 0
Accepted
time: 13ms
memory: 35700kb
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: 33540kb
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: 5ms
memory: 35592kb
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: 7ms
memory: 35704kb
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: 11ms
memory: 35820kb
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: -100
Runtime Error
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...