QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#179548#2342. Directing RainfallPetroTarnavskyiWA 715ms62244kbC++173.7kb2023-09-14 22:14:312023-09-14 22:14:32

Judging History

This is the latest submission verdict.

  • [2023-09-14 22:14:32]
  • Judged
  • Verdict: WA
  • Time: 715ms
  • Memory: 62244kb
  • [2023-09-14 22:14:31]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 1 << 22;
const int INF = 1.1e9;

struct SegTree
{
	int t[2 * N], lazy[2 * N];
	void build(int v, int tl, int tr, int l, int r)
	{
		if(tl + 1 == tr)
		{
			if(l <= tl && tr <= r)
				t[v] = 0;
			else
				t[v] = INF;
			return;
		}
		int tm = (tl + tr) / 2;
		build(2 * v, tl, tm, l, r);
		build(2 * v + 1, tm, tr, l, r);
		
		t[v] = min(t[2 * v], t[2 * v + 1]);
	}
	
	void push(int v, int tl, int tr)
	{
		t[v] = min(INF, t[v] + lazy[v]);
		
		if(tl + 1 != tr)
		{
			lazy[2 * v] += lazy[v];
			lazy[2 * v + 1] += lazy[v];
		}
		lazy[v] = 0;
	}
	
	void add(int v, int tl, int tr, int l, int r) //add 1 on seg
	{
		push(v, tl, tr);
		if(tr <= l || r <= tl)
			return;
		
		if(l <= tl && tr <= r)
		{
			lazy[v]++;
			push(v, tl, tr);
			return;
		}
		
		int tm = (tl + tr) / 2;
		add(2 * v, tl, tm, l, r);
		add(2 * v + 1, tm, tr, l, r);
		

		t[v] = min(t[2 * v], t[2 * v + 1]);
	}
	
	void upd(int v, int tl, int tr, int pos, int val)
	{
		push(v, tl, tr);
		if(pos < tl || tr <= pos)
			return;
			
		if(tl + 1 == tr)
		{
			t[v] = min(t[v], val);
			return;
		}
		
		int tm = (tl + tr) / 2;
		upd(2 * v, tl, tm, pos, val);
		upd(2 * v + 1, tm, tr, pos, val);
		
		t[v] = min(t[2 * v], t[2 * v + 1]);
	}
	
	int query(int v, int tl, int tr, int l, int r)
	{
		push(v, tl, tr);
		if(tr <= l || r <= tl)
			return INF;
				
		if(l <= tl && tr <= r)
		{
			return t[v];
		}
		int tm = (tl + tr) / 2;
		return min(query(2 * v, tl, tm, l, r),
			query(2 * v + 1, tm, tr, l, r));
	}
	
}T;


LL globalX;

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);
    }
}lines[N];

LL x[2][N], y[2][N];


int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0);
	cout << fixed << setprecision(15);
	int l, r, n;
	cin >> l >> r >> n;
	VI xs = {l, r};
	
	
	FOR(i, 0, n)
	{
		FOR(t, 0, 2)
			cin >> x[t][i] >> y[t][i];
		if(x[0][i] > x[1][i])
		{
			swap(x[0][i], x[1][i]);
			swap(y[0][i], y[1][i]);
		}
			
		xs.PB(x[0][i]);
		xs.PB(x[1][i]);
			
		lines[i] = Segment(i, x[0][i], y[0][i], x[1][i], y[1][i]);
	}
	
	VI order(n);
	iota(ALL(order), 0);
	sort(ALL(order), [&](int i, int j){
		int xl = max(x[0][i], x[0][j]);
		int xr = min(x[1][i], x[1][j]);
		if(xr < xl)
			return false;
		return lines[i] < lines[j];
	});
	reverse(ALL(order));
	
	sort(ALL(xs));
	
	
	
	l = lower_bound(ALL(xs), l) - xs.begin();
	r = upper_bound(ALL(xs), r) - xs.begin() - 1;
	T.build(1, 0, SZ(xs), l, r + 1);
	
	for(int v : order)
	{
		int L = lower_bound(ALL(xs), x[0][v]) - xs.begin();	
		int R = upper_bound(ALL(xs), x[1][v]) - xs.begin() - 1;	
		
		int to = (y[0][v] < y[1][v]) ? L : R;	
		int mn = T.query(1, 0, SZ(xs), L, R + 1);

		T.add(1, 0, SZ(xs), L, R + 1);
		T.upd(1, 0, SZ(xs), to, mn);
	}
	cout << T.query(1, 0, SZ(xs), l, r + 1) << endl;
	
	return 0;
}

Details

Test #1:

score: 100
Accepted
time: 2ms
memory: 13780kb

Test #2:

score: 0
Accepted
time: 2ms
memory: 13772kb

Test #3:

score: 0
Accepted
time: 1ms
memory: 5532kb

Test #4:

score: 0
Accepted
time: 1ms
memory: 5544kb

Test #5:

score: 0
Accepted
time: 1ms
memory: 5544kb

Test #6:

score: 0
Accepted
time: 2ms
memory: 13700kb

Test #7:

score: 0
Accepted
time: 0ms
memory: 13772kb

Test #8:

score: 0
Accepted
time: 2ms
memory: 13752kb

Test #9:

score: 0
Accepted
time: 2ms
memory: 13700kb

Test #10:

score: 0
Accepted
time: 0ms
memory: 13704kb

Test #11:

score: 0
Accepted
time: 0ms
memory: 13776kb

Test #12:

score: 0
Accepted
time: 715ms
memory: 62244kb

Test #13:

score: 0
Accepted
time: 3ms
memory: 13772kb

Test #14:

score: 0
Accepted
time: 2ms
memory: 13780kb

Test #15:

score: 0
Accepted
time: 0ms
memory: 13776kb

Test #16:

score: 0
Accepted
time: 2ms
memory: 13780kb

Test #17:

score: 0
Accepted
time: 0ms
memory: 13696kb

Test #18:

score: 0
Accepted
time: 0ms
memory: 13768kb

Test #19:

score: 0
Accepted
time: 2ms
memory: 13760kb

Test #20:

score: 0
Accepted
time: 0ms
memory: 13768kb

Test #21:

score: 0
Accepted
time: 2ms
memory: 13728kb

Test #22:

score: 0
Accepted
time: 0ms
memory: 13700kb

Test #23:

score: 0
Accepted
time: 0ms
memory: 13804kb

Test #24:

score: 0
Accepted
time: 2ms
memory: 13772kb

Test #25:

score: 0
Accepted
time: 0ms
memory: 13700kb

Test #26:

score: 0
Accepted
time: 2ms
memory: 13672kb

Test #27:

score: 0
Accepted
time: 0ms
memory: 13704kb

Test #28:

score: 0
Accepted
time: 0ms
memory: 13700kb

Test #29:

score: -100
Wrong Answer
time: 0ms
memory: 13740kb