QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#112805 | #2342. Directing Rainfall | SoyTony | AC ✓ | 1478ms | 147644kb | C++14 | 5.9kb | 2023-06-13 19:42:26 | 2023-06-14 23:01:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define mp make_pair
#define fir first
#define sec second
const int maxn=5e5+10;
const int inf=2e9;
inline int read(){
int x=0,w=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return x*w;
}
int n,L,R;
struct Segment{
int id,x1,y1,x2,y2;
Segment()=default;
Segment(int id_,int x1_,int y1_,int x2_,int y2_):id(id_),x1(x1_),y1(y1_),x2(x2_),y2(y2_){}
//(Y-y1)/(X-x1)=(y2-y1)/(x2-x1) Y(x2-x1)=(y2-y1)(X-x1)+y1(x2-x1)
bool operator<(const Segment& rhs)const{
if(x1<rhs.x1) return 1ll*(y2-y1)*(rhs.x1-x1)+1ll*y1*(x2-x1)<1ll*rhs.y1*(x2-x1);
else return 1ll*y1*(rhs.x2-rhs.x1)<1ll*(rhs.y2-rhs.y1)*(x1-rhs.x1)+1ll*rhs.y1*(rhs.x2-rhs.x1);
}
}Seg[maxn];
struct Data{
int id,val;
Data()=default;
Data(int id_,int val_):id(id_),val(val_){}
bool operator<(const Data& rhs)const{
return val>rhs.val;
}
};
set<Segment> S;
priority_queue<Data> Q;
vector<int> E[maxn];
int deg[maxn];
queue<int> q;
multiset<pii> Sp,Sn;
inline void output(){
printf("~~~~ Sp ~~~~\n");
for(auto it:Sp) printf("%d %d\n",it.fir,it.sec);
printf("~~~~ Sn ~~~~\n");
for(auto it:Sn) printf("%d %d\n",it.fir,it.sec);
}
int main(){
// freopen("rain.in","r",stdin);
// freopen("rain.out","w",stdout);
L=read()*2,R=read()*2,n=read();
for(int i=1;i<=n;++i){
int x1=read()*2,y1=read(),x2=read()*2,y2=read();
if(x1>x2) swap(x1,x2),swap(y1,y2);
Seg[i]=Segment(i,x1,y1,x2,y2);
}
sort(Seg+1,Seg+n+1,[&](Segment A,Segment B){
return A.x1<B.x1;
});
for(int i=1;i<=n;++i) Seg[i].id=i;
// for(int i=1;i<=n;++i) printf("id:%d (%d,%d) (%d,%d)\n",Seg[i].id,Seg[i].x1,Seg[i].y1,Seg[i].x2,Seg[i].y2);
for(int i=1;i<=n;++i){
while(!Q.empty()&&Q.top().val<Seg[i].x1){
S.erase(Seg[Q.top().id]);
Q.pop();
}
auto it=S.lower_bound(Seg[i]);
if(it!=S.end()){
E[(*it).id].push_back(i);
++deg[i];
}
if(it!=S.begin()){
--it;
E[i].push_back((*it).id);
++deg[(*it).id];
}
S.insert(Seg[i]);
Q.push(Data(i,Seg[i].x2));
}
for(int i=1;i<=n;++i){
if(!deg[i]) q.push(i);
}
Sp.insert(mp(R+1,inf));
Sn.insert(mp(L,inf));
while(!q.empty()){
int u=q.front();
q.pop();
// output();
if(Seg[u].y1<Seg[u].y2){
auto it1=Sn.lower_bound(mp(Seg[u].x2+1,-inf));
if(it1!=Sn.begin()){
--it1;
while((*it1).fir>=Seg[u].x1+1){
int val=(*it1).sec;
auto it2=Sp.lower_bound(mp((*it1).fir+1,-inf));
if(it2!=Sp.begin()){
--it2;
while(val&&(*it2).fir>=Seg[u].x1){
if((*it2).sec>val){
Sp.insert(mp((*it2).fir,(*it2).sec-val));
Sp.erase(it2);
val=0;
break;
}
else{
val-=(*it2).sec;
auto tmp=it2;
if(it2!=Sp.begin()){
--it2;
Sp.erase(tmp);
}
else{
Sp.erase(tmp);
break;
}
}
}
}
if(val) Sn.insert(mp(Seg[u].x1,val));
auto tmp=it1;
if(it1!=Sn.begin()){
--it1;
Sn.erase(tmp);
}
else{
Sn.erase(tmp);
break;
}
}
}
Sp.insert(mp(Seg[u].x1+1,1));
Sn.insert(mp(Seg[u].x2+1,1));
}
else{
auto it1=Sp.lower_bound(mp(Seg[u].x1,-inf));
while(it1!=Sp.end()&&(*it1).fir<=Seg[u].x2){
int val=(*it1).sec;
auto it2=Sn.lower_bound(mp((*it1).fir,-inf));
while(it2!=Sn.end()&&val&&(*it2).fir<=Seg[u].x2+1){
if((*it2).sec>val){
Sn.insert(mp((*it2).fir,(*it2).sec-val));
Sn.erase(*it2);
val=0;
break;
}
else{
val-=(*it2).sec;
auto tmp=it2;
++it2;
Sn.erase(tmp);
if(it2==Sn.end()) break;
}
}
if(val) Sp.insert(mp(Seg[u].x2+1,val));
auto tmp=it1;
++it1;
Sp.erase(tmp);
}
Sp.insert(mp(Seg[u].x1,1));
Sn.insert(mp(Seg[u].x2,1));
}
for(int v:E[u]){
--deg[v];
if(!deg[v]) q.push(v);
}
}
for(auto it=Sn.begin();it!=Sn.end();++it){
Sp.insert(mp((*it).fir,-(*it).sec));
}
// for(auto it=Sp.begin();it!=Sp.end();++it){
// printf("%d %d\n",(*it).fir,(*it).sec);
// }
int ans=inf,sum=inf,now=-inf;
Sp.insert(mp(L,0));
for(auto it=Sp.begin();it!=Sp.end();++it){
if((*it).fir!=now&&now>=L&&now<=R) ans=min(ans,sum);
now=(*it).fir,sum+=(*it).sec;
}
printf("%d\n",ans);
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 1ms
memory: 15856kb
Test #2:
score: 0
Accepted
time: 1ms
memory: 17912kb
Test #3:
score: 0
Accepted
time: 4ms
memory: 15996kb
Test #4:
score: 0
Accepted
time: 4ms
memory: 17944kb
Test #5:
score: 0
Accepted
time: 4ms
memory: 17940kb
Test #6:
score: 0
Accepted
time: 1ms
memory: 17936kb
Test #7:
score: 0
Accepted
time: 0ms
memory: 18056kb
Test #8:
score: 0
Accepted
time: 3ms
memory: 17944kb
Test #9:
score: 0
Accepted
time: 3ms
memory: 17896kb
Test #10:
score: 0
Accepted
time: 1ms
memory: 17900kb
Test #11:
score: 0
Accepted
time: 1ms
memory: 17992kb
Test #12:
score: 0
Accepted
time: 696ms
memory: 147644kb
Test #13:
score: 0
Accepted
time: 1ms
memory: 15972kb
Test #14:
score: 0
Accepted
time: 1ms
memory: 15956kb
Test #15:
score: 0
Accepted
time: 0ms
memory: 17988kb
Test #16:
score: 0
Accepted
time: 2ms
memory: 15836kb
Test #17:
score: 0
Accepted
time: 3ms
memory: 17952kb
Test #18:
score: 0
Accepted
time: 1ms
memory: 15940kb
Test #19:
score: 0
Accepted
time: 1ms
memory: 17908kb
Test #20:
score: 0
Accepted
time: 1ms
memory: 15904kb
Test #21:
score: 0
Accepted
time: 4ms
memory: 17928kb
Test #22:
score: 0
Accepted
time: 4ms
memory: 17996kb
Test #23:
score: 0
Accepted
time: 3ms
memory: 15876kb
Test #24:
score: 0
Accepted
time: 3ms
memory: 18040kb
Test #25:
score: 0
Accepted
time: 1ms
memory: 17932kb
Test #26:
score: 0
Accepted
time: 3ms
memory: 15960kb
Test #27:
score: 0
Accepted
time: 3ms
memory: 18056kb
Test #28:
score: 0
Accepted
time: 3ms
memory: 15864kb
Test #29:
score: 0
Accepted
time: 1ms
memory: 17908kb
Test #30:
score: 0
Accepted
time: 0ms
memory: 17900kb
Test #31:
score: 0
Accepted
time: 0ms
memory: 17916kb
Test #32:
score: 0
Accepted
time: 1ms
memory: 17940kb
Test #33:
score: 0
Accepted
time: 3ms
memory: 18044kb
Test #34:
score: 0
Accepted
time: 1ms
memory: 17912kb
Test #35:
score: 0
Accepted
time: 837ms
memory: 147588kb
Test #36:
score: 0
Accepted
time: 850ms
memory: 130348kb
Test #37:
score: 0
Accepted
time: 805ms
memory: 147628kb
Test #38:
score: 0
Accepted
time: 673ms
memory: 147576kb
Test #39:
score: 0
Accepted
time: 400ms
memory: 105192kb
Test #40:
score: 0
Accepted
time: 270ms
memory: 71464kb
Test #41:
score: 0
Accepted
time: 1112ms
memory: 57656kb
Test #42:
score: 0
Accepted
time: 1066ms
memory: 57604kb
Test #43:
score: 0
Accepted
time: 1ms
memory: 17900kb
Test #44:
score: 0
Accepted
time: 1ms
memory: 17872kb
Test #45:
score: 0
Accepted
time: 1ms
memory: 17924kb
Test #46:
score: 0
Accepted
time: 1ms
memory: 15892kb
Test #47:
score: 0
Accepted
time: 1ms
memory: 17904kb
Test #48:
score: 0
Accepted
time: 1ms
memory: 18000kb
Test #49:
score: 0
Accepted
time: 1ms
memory: 17884kb
Test #50:
score: 0
Accepted
time: 1ms
memory: 17900kb
Test #51:
score: 0
Accepted
time: 4ms
memory: 17908kb
Test #52:
score: 0
Accepted
time: 4ms
memory: 18000kb
Test #53:
score: 0
Accepted
time: 1ms
memory: 16008kb
Test #54:
score: 0
Accepted
time: 1ms
memory: 17932kb
Test #55:
score: 0
Accepted
time: 1ms
memory: 18064kb
Test #56:
score: 0
Accepted
time: 4ms
memory: 18064kb
Test #57:
score: 0
Accepted
time: 1ms
memory: 15904kb
Test #58:
score: 0
Accepted
time: 3ms
memory: 15956kb
Test #59:
score: 0
Accepted
time: 4ms
memory: 18008kb
Test #60:
score: 0
Accepted
time: 3ms
memory: 17948kb
Test #61:
score: 0
Accepted
time: 4ms
memory: 17932kb
Test #62:
score: 0
Accepted
time: 4ms
memory: 17936kb
Test #63:
score: 0
Accepted
time: 5ms
memory: 18088kb
Test #64:
score: 0
Accepted
time: 5ms
memory: 15920kb
Test #65:
score: 0
Accepted
time: 5ms
memory: 17968kb
Test #66:
score: 0
Accepted
time: 1ms
memory: 18108kb
Test #67:
score: 0
Accepted
time: 0ms
memory: 18016kb
Test #68:
score: 0
Accepted
time: 10ms
memory: 18656kb
Test #69:
score: 0
Accepted
time: 8ms
memory: 18604kb
Test #70:
score: 0
Accepted
time: 12ms
memory: 18532kb
Test #71:
score: 0
Accepted
time: 8ms
memory: 16592kb
Test #72:
score: 0
Accepted
time: 142ms
memory: 22628kb
Test #73:
score: 0
Accepted
time: 139ms
memory: 24916kb
Test #74:
score: 0
Accepted
time: 143ms
memory: 23144kb
Test #75:
score: 0
Accepted
time: 151ms
memory: 23544kb
Test #76:
score: 0
Accepted
time: 130ms
memory: 24956kb
Test #77:
score: 0
Accepted
time: 1074ms
memory: 62912kb
Test #78:
score: 0
Accepted
time: 1071ms
memory: 53392kb
Test #79:
score: 0
Accepted
time: 1026ms
memory: 60544kb
Test #80:
score: 0
Accepted
time: 982ms
memory: 55880kb
Test #81:
score: 0
Accepted
time: 1049ms
memory: 54356kb
Test #82:
score: 0
Accepted
time: 1002ms
memory: 54992kb
Test #83:
score: 0
Accepted
time: 896ms
memory: 56044kb
Test #84:
score: 0
Accepted
time: 1078ms
memory: 69936kb
Test #85:
score: 0
Accepted
time: 1179ms
memory: 55204kb
Test #86:
score: 0
Accepted
time: 1040ms
memory: 53312kb
Test #87:
score: 0
Accepted
time: 692ms
memory: 61616kb
Test #88:
score: 0
Accepted
time: 621ms
memory: 59536kb
Test #89:
score: 0
Accepted
time: 586ms
memory: 51076kb
Test #90:
score: 0
Accepted
time: 992ms
memory: 52416kb
Test #91:
score: 0
Accepted
time: 1478ms
memory: 62232kb
Test #92:
score: 0
Accepted
time: 537ms
memory: 70988kb
Test #93:
score: 0
Accepted
time: 404ms
memory: 51124kb
Test #94:
score: 0
Accepted
time: 437ms
memory: 47860kb
Test #95:
score: 0
Accepted
time: 465ms
memory: 53764kb
Test #96:
score: 0
Accepted
time: 350ms
memory: 57940kb