QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#266030 | #2342. Directing Rainfall | InfinityNS# | AC ✓ | 1822ms | 119428kb | C++14 | 4.6kb | 2023-11-26 01:53:42 | 2023-11-26 01:53:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ldb double
#define pb push_back
const int N=500050;
const int L=-1;
const int R=2e9+7;
const int inf=2*N;
int tme;
struct line{
int x1,y1,x2,y2,i;
line(){}
ll Get() const {
ll le=tme-x1;
ll ri=x2-tme;
return ri*y1+le*y2;
}
ll Stride() const {
return x2-x1;
}
bool operator < (const line& other) const {
return (__int128)Get() * other.Stride() < (__int128)other.Get() * Stride();
}
}a[N];
vector<int> E[N];
int in[N];
void AddEdge(int u,int v){
E[u].pb(v);
in[v]++;
}
map<int,int> pos,neg;
void Add(int p,int x){
//printf("Add %i: %i\n",p,x);
if(pos.count(p)){
pos[p]+=x;
if(pos[p]<0){
neg[p]=-pos[p];
}
if(pos[p]<=0){
pos.erase(p);
}
}else if(neg.count(p)){
neg[p]-=x;
if(neg[p]<0){
pos[p]=-neg[p];
}
if(neg[p]<=0){
neg.erase(p);
}
}else{
if(x>0){
pos[p]=x;
}else if(x<0){
neg[p]=-x;
}
}
}
void AddLine(int i){
//printf("Process line %i\n",i);
int l=a[i].x1;
int r=a[i].x2;
if(a[i].y1 < a[i].y2){ // levo
//printf("Left\n");
while(true){
auto it=neg.upper_bound(r);
if(it==neg.begin())break;
it--;
if(it->first<=l)break;
int p=it->first;
int x=it->second;
auto jt=pos.upper_bound(p);
if(jt==pos.begin() || prev(jt)->first<=l){
Add(l,-x);
Add(p,x);
}else{
jt--;
int mn=min(x,jt->second);
Add(jt->first,-mn);
Add(p,mn);
}
}
Add(l+1,1);
Add(r+1,-1);
}else{
//printf("Right\n");
while(true){
auto it=pos.lower_bound(l+1);
if(it==pos.end())break;
if(it->first>r)break;
int p=it->first;
int x=it->second;
auto jt=neg.lower_bound(p+1);
if(jt==neg.end() || jt->first>r){
Add(r+1,x);
Add(p,-x);
}else{
int mn=min(x,jt->second);
Add(jt->first,mn);
Add(p,-mn);
}
}
Add(l,1);
Add(r,-1);
}
}
bool sec(int l1,int r1,int l2,int r2){
return max(l1,l2)<=min(r1,r2);
}
int main(){
int l,r,n;
scanf("%i %i %i",&l,&r,&n);
l*=2;
r*=2;
vector<pair<int,int>> evs;
for(int i=1;i<=n;i++){
scanf("%i %i %i %i",&a[i].x1,&a[i].y1,&a[i].x2,&a[i].y2);
a[i].x1*=2;
a[i].x2*=2;
if(a[i].x1>a[i].x2){
swap(a[i].x1,a[i].x2);
swap(a[i].y1,a[i].y2);
}
a[i].i=i;
evs.pb({a[i].x1,i});
evs.pb({a[i].x2,-i});
}
sort(evs.begin(),evs.end());
set<line> all;
for(auto ev:evs){
int i=abs(ev.second);
tme=ev.first;
if(ev.second>0){
//printf("Insert %i\n",i);
all.insert(a[i]);
auto it=all.lower_bound(a[i]);
if(next(it)!=all.end()){
AddEdge(next(it)->i,it->i);
}
if(it!=all.begin()){
AddEdge(it->i,prev(it)->i);
}
}else{
//printf("Erase %i\n",i);
auto it=all.lower_bound(a[i]);
if(next(it)!=all.end() && it!=all.begin()){
AddEdge(next(it)->i,prev(it)->i);
}
all.erase(a[i]);
}
}
Add(L,inf);
Add(l,-inf);
Add(r+1,inf);
Add(R,-inf);
queue<int> q;
for(int i=1;i<=n;i++){
if(!in[i]){
q.push(i);
}
}
while(q.size()){
int u=q.front();
q.pop();
AddLine(u);
for(int v:E[u]){
in[v]--;
if(!in[v]){
q.push(v);
}
}
}
vector<pair<int,int>> add;
for(auto x:pos)add.pb({x.first,x.second});
for(auto x:neg)add.pb({x.first,-x.second});
sort(add.begin(),add.end());
int last=L;
int sum=0;
int ans=inf;
for(auto ev:add){
int now=ev.first;
//printf("[%i, %i] %i\n",last,now-1,sum);
if(last<now && sec(last,now-1,l,r)){
ans=min(ans,sum);
}
sum+=ev.second;
last=now;
}
printf("%i\n",ans);
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 3ms
memory: 16064kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 16064kb
Test #3:
score: 0
Accepted
time: 3ms
memory: 18392kb
Test #4:
score: 0
Accepted
time: 2ms
memory: 18368kb
Test #5:
score: 0
Accepted
time: 2ms
memory: 16348kb
Test #6:
score: 0
Accepted
time: 0ms
memory: 18404kb
Test #7:
score: 0
Accepted
time: 2ms
memory: 16320kb
Test #8:
score: 0
Accepted
time: 0ms
memory: 16100kb
Test #9:
score: 0
Accepted
time: 0ms
memory: 18116kb
Test #10:
score: 0
Accepted
time: 2ms
memory: 18112kb
Test #11:
score: 0
Accepted
time: 3ms
memory: 16160kb
Test #12:
score: 0
Accepted
time: 1120ms
memory: 118592kb
Test #13:
score: 0
Accepted
time: 0ms
memory: 18204kb
Test #14:
score: 0
Accepted
time: 2ms
memory: 16084kb
Test #15:
score: 0
Accepted
time: 4ms
memory: 18400kb
Test #16:
score: 0
Accepted
time: 0ms
memory: 18400kb
Test #17:
score: 0
Accepted
time: 0ms
memory: 16156kb
Test #18:
score: 0
Accepted
time: 0ms
memory: 18120kb
Test #19:
score: 0
Accepted
time: 0ms
memory: 18140kb
Test #20:
score: 0
Accepted
time: 3ms
memory: 18072kb
Test #21:
score: 0
Accepted
time: 3ms
memory: 18116kb
Test #22:
score: 0
Accepted
time: 2ms
memory: 18412kb
Test #23:
score: 0
Accepted
time: 0ms
memory: 16316kb
Test #24:
score: 0
Accepted
time: 0ms
memory: 16092kb
Test #25:
score: 0
Accepted
time: 0ms
memory: 18112kb
Test #26:
score: 0
Accepted
time: 3ms
memory: 18112kb
Test #27:
score: 0
Accepted
time: 2ms
memory: 18396kb
Test #28:
score: 0
Accepted
time: 2ms
memory: 16092kb
Test #29:
score: 0
Accepted
time: 0ms
memory: 18116kb
Test #30:
score: 0
Accepted
time: 2ms
memory: 18400kb
Test #31:
score: 0
Accepted
time: 0ms
memory: 18140kb
Test #32:
score: 0
Accepted
time: 0ms
memory: 18140kb
Test #33:
score: 0
Accepted
time: 2ms
memory: 18116kb
Test #34:
score: 0
Accepted
time: 2ms
memory: 18112kb
Test #35:
score: 0
Accepted
time: 1630ms
memory: 112752kb
Test #36:
score: 0
Accepted
time: 1600ms
memory: 114840kb
Test #37:
score: 0
Accepted
time: 1822ms
memory: 117328kb
Test #38:
score: 0
Accepted
time: 1142ms
memory: 119428kb
Test #39:
score: 0
Accepted
time: 1320ms
memory: 103656kb
Test #40:
score: 0
Accepted
time: 538ms
memory: 76908kb
Test #41:
score: 0
Accepted
time: 1511ms
memory: 64328kb
Test #42:
score: 0
Accepted
time: 1473ms
memory: 64456kb
Test #43:
score: 0
Accepted
time: 3ms
memory: 16024kb
Test #44:
score: 0
Accepted
time: 0ms
memory: 18092kb
Test #45:
score: 0
Accepted
time: 2ms
memory: 18076kb
Test #46:
score: 0
Accepted
time: 2ms
memory: 18144kb
Test #47:
score: 0
Accepted
time: 0ms
memory: 16064kb
Test #48:
score: 0
Accepted
time: 0ms
memory: 16028kb
Test #49:
score: 0
Accepted
time: 0ms
memory: 16096kb
Test #50:
score: 0
Accepted
time: 0ms
memory: 18412kb
Test #51:
score: 0
Accepted
time: 2ms
memory: 16316kb
Test #52:
score: 0
Accepted
time: 2ms
memory: 16072kb
Test #53:
score: 0
Accepted
time: 2ms
memory: 18184kb
Test #54:
score: 0
Accepted
time: 3ms
memory: 18212kb
Test #55:
score: 0
Accepted
time: 3ms
memory: 16452kb
Test #56:
score: 0
Accepted
time: 0ms
memory: 16080kb
Test #57:
score: 0
Accepted
time: 0ms
memory: 18128kb
Test #58:
score: 0
Accepted
time: 0ms
memory: 18376kb
Test #59:
score: 0
Accepted
time: 2ms
memory: 18156kb
Test #60:
score: 0
Accepted
time: 2ms
memory: 18156kb
Test #61:
score: 0
Accepted
time: 0ms
memory: 18384kb
Test #62:
score: 0
Accepted
time: 3ms
memory: 16080kb
Test #63:
score: 0
Accepted
time: 0ms
memory: 16160kb
Test #64:
score: 0
Accepted
time: 4ms
memory: 18152kb
Test #65:
score: 0
Accepted
time: 2ms
memory: 18200kb
Test #66:
score: 0
Accepted
time: 0ms
memory: 16168kb
Test #67:
score: 0
Accepted
time: 4ms
memory: 18184kb
Test #68:
score: 0
Accepted
time: 19ms
memory: 18844kb
Test #69:
score: 0
Accepted
time: 18ms
memory: 19040kb
Test #70:
score: 0
Accepted
time: 17ms
memory: 16692kb
Test #71:
score: 0
Accepted
time: 16ms
memory: 18708kb
Test #72:
score: 0
Accepted
time: 224ms
memory: 26120kb
Test #73:
score: 0
Accepted
time: 220ms
memory: 26328kb
Test #74:
score: 0
Accepted
time: 216ms
memory: 26696kb
Test #75:
score: 0
Accepted
time: 242ms
memory: 27076kb
Test #76:
score: 0
Accepted
time: 220ms
memory: 24440kb
Test #77:
score: 0
Accepted
time: 1418ms
memory: 69364kb
Test #78:
score: 0
Accepted
time: 1537ms
memory: 60656kb
Test #79:
score: 0
Accepted
time: 1387ms
memory: 67244kb
Test #80:
score: 0
Accepted
time: 1348ms
memory: 63428kb
Test #81:
score: 0
Accepted
time: 1509ms
memory: 61676kb
Test #82:
score: 0
Accepted
time: 1438ms
memory: 62344kb
Test #83:
score: 0
Accepted
time: 1346ms
memory: 63316kb
Test #84:
score: 0
Accepted
time: 1519ms
memory: 75456kb
Test #85:
score: 0
Accepted
time: 1542ms
memory: 64132kb
Test #86:
score: 0
Accepted
time: 1571ms
memory: 61576kb
Test #87:
score: 0
Accepted
time: 1062ms
memory: 69796kb
Test #88:
score: 0
Accepted
time: 1048ms
memory: 68440kb
Test #89:
score: 0
Accepted
time: 1018ms
memory: 61028kb
Test #90:
score: 0
Accepted
time: 1353ms
memory: 58740kb
Test #91:
score: 0
Accepted
time: 1578ms
memory: 63128kb
Test #92:
score: 0
Accepted
time: 1027ms
memory: 79840kb
Test #93:
score: 0
Accepted
time: 809ms
memory: 60836kb
Test #94:
score: 0
Accepted
time: 717ms
memory: 56924kb
Test #95:
score: 0
Accepted
time: 905ms
memory: 63292kb
Test #96:
score: 0
Accepted
time: 671ms
memory: 67908kb