QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#211022 | #2342. Directing Rainfall | HIR180 | TL | 5346ms | 210692kb | C++14 | 6.3kb | 2023-10-12 00:00:27 | 2023-10-12 00:00:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rng(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,b) rng(i,0,b)
#define repn(i,b) rng(i,1,b+1)
#define pb push_back
#define eb emplace_back
#define si(x) (int)(x.size())
#define tct template<class t>
#define tctu template<class t, class u>
tctu bool chmax(t&a, u b){if(a<b){a=b;return 1;}return 0;}
tctu bool chmin(t&a, u b){if(a>b){a=b;return 1;}return 0;}
tct using vc=vector<t>;
using vi=vc<int>;
using P=pair<int,int>;
#define a first
#define b second
#define mp make_pair
pair<ll,ll>get(int a,int b,int c,int d,int e){
if(a == e) return mp(c, 1);
if(b == e) return mp(d, 1);
int up = d-c;
int dw = b-a;
pair<ll,ll>ret = mp(1LL*c*dw, dw);
ret.a += 1LL*up*(e-a);
return ret;
}
pair<ll, ll>get_mn(pair<ll,ll>x, pair<ll,ll>y){
//x.a/x.b < y.a/y.b?
__int128 le = (__int128)x.a * y.b;
__int128 ri = (__int128)y.a * x.b;
if(le < ri) return x;
return y;
}
struct seg{
//(a,c)-(b,d)
//a<b
int a,b,c,d;
seg(int A,int B,int C,int D){
a=A,b=B,c=C,d=D;
}
bool operator<(const seg &s)const{
if(a==s.a and b==s.b and c==s.c and d==s.d)return 0;
int mn = min(b, s.b);
int mx = max(a, s.a);
if(mn < mx) return false;
auto xa = get(a,b,c,d,mn);
auto xb = get(a,b,c,d,mx);
xa = get_mn(xa, xb);
auto xc = get(s.a,s.b,s.c,s.d,mn);
auto xd = get(s.a,s.b,s.c,s.d,mx);
xc = get_mn(xc, xd);
return get_mn(xa, xc) == xc;
}
};
int lb, ub, n;
vi za;
vc<tuple<int,int,int,int>>vec;
P Q[1000005];
set<seg>S;
map<int,int>M;
int in[500005];
vi edge[500005];
struct st{
vi val;
int nn;
void init(int sz){
nn=1;
while(sz+5>=nn) nn<<=1;
val.assign(nn+nn, 0);
}
int get(int vall,int k,int l,int r){
if(l == r) return val[k];
if(vall <= (l+r)/2) return val[k] + get(vall, k*2+1, l, (l+r)/2);
return val[k] + get(vall, k*2+2, (l+r)/2+1, r);
}
void upd(int le, int ri, int add, int k,int l,int r){
if(le>ri or ri<l or r<le) return;
if(le <= l and r <= ri){
val[k]+=add;
return;
}
upd(le,ri,add,k*2+1,l,(l+r)/2);
upd(le,ri,add,k*2+2,(l+r)/2+1,r);
}
int get(int val){ return get(val,0,0,nn-1); }
void upd(int le,int ri,int add){ upd(le,ri,add,0,0,nn-1); }
}s;
void solve(){
cin>>lb>>ub>>n;
za.pb(lb); za.pb(ub);
rep(i,n){
int ax,ay,bx,by;
cin>>ax>>ay>>bx>>by;
if(ax > bx){
swap(ax, bx);
swap(ay, by);
}
vec.eb(ax,bx,ay,by);
za.pb(ax);
za.pb(bx);
M[ax] = i;
M[bx] = i;
}
sort(za.begin(), za.end());
za.erase(unique(za.begin(), za.end()), za.end());
rep(i,n){
Q[lower_bound(za.begin(), za.end(), get<0>(vec[i]))-za.begin()] = mp(1, i);
Q[lower_bound(za.begin(), za.end(), get<1>(vec[i]))-za.begin()] = mp(2, i);
}
rep(i,si(za)){
{
auto [ty, id]=Q[i];
if(!ty) continue;
auto [a,b,c,d]=vec[id];
if(ty == 2){
S.erase(S.find(seg(a,b,c,d)));
}
else if(ty == 1){
auto it = S.lower_bound(seg(a,b,c,d));
if(it != S.end()){
int v = (*it).a;
edge[id].pb(M[v]);
in[M[v]] ++;
}
if(it != S.begin()){
it --;
int v = (*it).a;
edge[M[v]].pb(id);
in[id] ++;
}
S.insert(seg(a,b,c,d));
}
}
}
queue<int>que;
rep(i,n) if(!in[i]) que.push(i);
vi ord;
while(!que.empty()){
int q = que.front(); que.pop();
ord.pb(q);
for(auto to:edge[q]){
in[to]--;
if(!in[to]) que.push(to);
}
}
set<int>up,dw;
set<int>dif;
s.init(si(za));
auto add=[&](int l,int r,int v){
if(l){
int le = s.get(l-1);
int ri = s.get(l);
if(le != ri){
dif.erase(l-1);
}
if(le < ri) up.erase(l-1);
if(le > ri) dw.erase(l-1);
if(le != ri+v){
dif.insert(l-1);
}
if(le < ri+v) up.insert(l-1);
if(le > ri+v) dw.insert(l-1);
}
if(r+1 < si(za)){
int le = s.get(r);
int ri = s.get(r+1);
if(le != ri){
dif.erase(r);
}
if(le < ri) up.erase(r);
if(le > ri) dw.erase(r);
if(le+v != ri){
dif.insert(r);
}
if(le+v < ri) up.insert(r);
if(le+v > ri) dw.insert(r);
}s.upd(l,r,v);
};
rng(i,0,si(za)){
if(lb <= za[i] and za[i] <= ub);
else {
//s.upd(i,i,1000000);
add(i,i,1000000);
}
}
for(auto id:ord){
//cout<<id<<endl;
int mn = lower_bound(za.begin(), za.end(), get<0>(vec[id])) - za.begin();
int mx = lower_bound(za.begin(), za.end(), get<1>(vec[id])) - za.begin();
int ay = get<2>(vec[id]);
int by = get<3>(vec[id]);
if(ay > by){
int cur = mn;
while(1){
auto it0 = up.lower_bound(cur);
if(it0 == up.end() or (*it0) >= mx) goto end;
cur = (*it0);
int dp = s.get(cur);
while(1){
auto it = dif.lower_bound(cur);
if(it == dif.end() or (*it) >= mx) goto end;
int nxtpos = *it;
int nxtdp = s.get(nxtpos+1);
if(dp >= nxtdp){
cur = nxtpos+1;
break;
}
else{
auto it2 = it; it2++;
int nxt2pos;
if(it2 == dif.end() or (*it2) >= mx) nxt2pos = mx;
else nxt2pos = *it2;
//s.upd(nxtpos+1, nxt2pos, dp-nxtdp);
add(nxtpos+1, nxt2pos, dp-nxtdp);
}
}
}
end:;
//s.upd(mn+1, mx-1, 1);
add(mn+1, mx-1, 1);
}
else{
int cur = mx;
while(1){
auto it0 = dw.lower_bound(cur);
if(it0 == dw.begin()) goto end2;
it0--;
if((*it0) < mn) goto end2;
cur = (*it0)+1;
int dp = s.get(cur);
while(1){
auto it = dif.lower_bound(cur);
if(it == dif.begin()) goto end2;
it --;
if((*it) < mn) goto end2;
int nxtpos = (*it);
int nxtdp = s.get(nxtpos);
if(dp >= nxtdp){
cur = nxtpos;
break;
}
else{
auto it2 = it;
int nxt2pos;
if(it2 == dif.begin()) nxt2pos = mn;
else{
it2--;
if((*it2)<mn) nxt2pos = mn;
else nxt2pos = (*it2)+1;
}
//s.upd(nxt2pos, nxtpos, dp-nxtdp);
add(nxt2pos, nxtpos, dp-nxtdp);
}
}
}
end2:;
//s.upd(mn+1, mx-1, 1);
add(mn+1, mx-1, 1);
}
}
lb = lower_bound(za.begin(), za.end(), lb)-za.begin();
ub = lower_bound(za.begin(), za.end(), ub)-za.begin();
int ans = 1000000000;
rng(i,lb,ub+1) chmin(ans,s.get(i));
cout<<ans<<endl;
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 18960kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 17764kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 18196kb
Test #4:
score: 0
Accepted
time: 4ms
memory: 18720kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 17704kb
Test #6:
score: 0
Accepted
time: 4ms
memory: 18416kb
Test #7:
score: 0
Accepted
time: 0ms
memory: 18176kb
Test #8:
score: 0
Accepted
time: 0ms
memory: 19180kb
Test #9:
score: 0
Accepted
time: 0ms
memory: 17788kb
Test #10:
score: 0
Accepted
time: 2ms
memory: 17524kb
Test #11:
score: 0
Accepted
time: 0ms
memory: 18816kb
Test #12:
score: 0
Accepted
time: 2818ms
memory: 210464kb
Test #13:
score: 0
Accepted
time: 0ms
memory: 18552kb
Test #14:
score: 0
Accepted
time: 2ms
memory: 17360kb
Test #15:
score: 0
Accepted
time: 0ms
memory: 18384kb
Test #16:
score: 0
Accepted
time: 0ms
memory: 18844kb
Test #17:
score: 0
Accepted
time: 0ms
memory: 19184kb
Test #18:
score: 0
Accepted
time: 0ms
memory: 17352kb
Test #19:
score: 0
Accepted
time: 0ms
memory: 19104kb
Test #20:
score: 0
Accepted
time: 5ms
memory: 18200kb
Test #21:
score: 0
Accepted
time: 0ms
memory: 17332kb
Test #22:
score: 0
Accepted
time: 4ms
memory: 17788kb
Test #23:
score: 0
Accepted
time: 4ms
memory: 17428kb
Test #24:
score: 0
Accepted
time: 0ms
memory: 18204kb
Test #25:
score: 0
Accepted
time: 4ms
memory: 17968kb
Test #26:
score: 0
Accepted
time: 0ms
memory: 18676kb
Test #27:
score: 0
Accepted
time: 2ms
memory: 17384kb
Test #28:
score: 0
Accepted
time: 4ms
memory: 17552kb
Test #29:
score: 0
Accepted
time: 0ms
memory: 17812kb
Test #30:
score: 0
Accepted
time: 0ms
memory: 18448kb
Test #31:
score: 0
Accepted
time: 4ms
memory: 18156kb
Test #32:
score: 0
Accepted
time: 0ms
memory: 17236kb
Test #33:
score: 0
Accepted
time: 0ms
memory: 18048kb
Test #34:
score: 0
Accepted
time: 0ms
memory: 18536kb
Test #35:
score: 0
Accepted
time: 3286ms
memory: 210544kb
Test #36:
score: 0
Accepted
time: 3510ms
memory: 206640kb
Test #37:
score: 0
Accepted
time: 3560ms
memory: 210692kb
Test #38:
score: 0
Accepted
time: 2874ms
memory: 210584kb
Test #39:
score: 0
Accepted
time: 3072ms
memory: 148116kb
Test #40:
score: 0
Accepted
time: 1787ms
memory: 173576kb
Test #41:
score: 0
Accepted
time: 5346ms
memory: 124576kb
Test #42:
score: 0
Accepted
time: 5283ms
memory: 124464kb
Test #43:
score: 0
Accepted
time: 4ms
memory: 18424kb
Test #44:
score: 0
Accepted
time: 0ms
memory: 18900kb
Test #45:
score: 0
Accepted
time: 0ms
memory: 18044kb
Test #46:
score: 0
Accepted
time: 3ms
memory: 17432kb
Test #47:
score: 0
Accepted
time: 3ms
memory: 17556kb
Test #48:
score: 0
Accepted
time: 4ms
memory: 17248kb
Test #49:
score: 0
Accepted
time: 0ms
memory: 18176kb
Test #50:
score: 0
Accepted
time: 0ms
memory: 19268kb
Test #51:
score: 0
Accepted
time: 0ms
memory: 17420kb
Test #52:
score: 0
Accepted
time: 4ms
memory: 17192kb
Test #53:
score: 0
Accepted
time: 0ms
memory: 18964kb
Test #54:
score: 0
Accepted
time: 4ms
memory: 18028kb
Test #55:
score: 0
Accepted
time: 0ms
memory: 18244kb
Test #56:
score: 0
Accepted
time: 0ms
memory: 18528kb
Test #57:
score: 0
Accepted
time: 0ms
memory: 18988kb
Test #58:
score: 0
Accepted
time: 0ms
memory: 18268kb
Test #59:
score: 0
Accepted
time: 0ms
memory: 17388kb
Test #60:
score: 0
Accepted
time: 4ms
memory: 18484kb
Test #61:
score: 0
Accepted
time: 0ms
memory: 18664kb
Test #62:
score: 0
Accepted
time: 2ms
memory: 18824kb
Test #63:
score: 0
Accepted
time: 4ms
memory: 18508kb
Test #64:
score: 0
Accepted
time: 4ms
memory: 18572kb
Test #65:
score: 0
Accepted
time: 8ms
memory: 19060kb
Test #66:
score: 0
Accepted
time: 4ms
memory: 17900kb
Test #67:
score: 0
Accepted
time: 5ms
memory: 18808kb
Test #68:
score: 0
Accepted
time: 48ms
memory: 20704kb
Test #69:
score: 0
Accepted
time: 52ms
memory: 21112kb
Test #70:
score: 0
Accepted
time: 47ms
memory: 20076kb
Test #71:
score: 0
Accepted
time: 50ms
memory: 20532kb
Test #72:
score: 0
Accepted
time: 744ms
memory: 38084kb
Test #73:
score: 0
Accepted
time: 752ms
memory: 38164kb
Test #74:
score: 0
Accepted
time: 696ms
memory: 39356kb
Test #75:
score: 0
Accepted
time: 729ms
memory: 38968kb
Test #76:
score: 0
Accepted
time: 706ms
memory: 37560kb
Test #77:
score: 0
Accepted
time: 5296ms
memory: 132812kb
Test #78:
score: 0
Accepted
time: 5000ms
memory: 120456kb
Test #79:
score: 0
Accepted
time: 4764ms
memory: 130752kb
Test #80:
score: 0
Accepted
time: 4595ms
memory: 122580kb
Test #81:
score: 0
Accepted
time: 4805ms
memory: 121188kb
Test #82:
score: 0
Accepted
time: 4932ms
memory: 122860kb
Test #83:
score: 0
Accepted
time: 4133ms
memory: 122732kb
Test #84:
score: 0
Accepted
time: 4626ms
memory: 141164kb
Test #85:
score: 0
Accepted
time: 4780ms
memory: 122144kb
Test #86:
score: 0
Accepted
time: 4816ms
memory: 120588kb
Test #87:
score: 0
Accepted
time: 3296ms
memory: 141972kb
Test #88:
score: 0
Accepted
time: 3439ms
memory: 137408kb
Test #89:
score: 0
Accepted
time: 4449ms
memory: 129988kb
Test #90:
score: -100
Time Limit Exceeded