QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#179769#2342. Directing RainfallPetroTarnavskyiWA 2350ms577712kbC++174.9kb2023-09-15 03:40:432023-09-15 03:40:43

Judging History

你现在查看的是最新测评结果

  • [2023-09-15 03:40:43]
  • 评测
  • 测评结果:WA
  • 用时:2350ms
  • 内存:577712kb
  • [2023-09-15 03:40:43]
  • 提交

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)
	{
		t[v] = INF;	
		lazy[v] = 0;	
		if(tl + 1 == tr)
		{
			if(l <= tl && tr <= r)
			{
				t[v] = 0;
			}
			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] += 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] = 1;
			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 Line
{
	LL A, B, C;//Ax + By + C = 0
	int index;
	
	Line(){}
	Line(LL y, int i) : A(0), B(1), C(-y), index(i) {}
	Line(LL x0, LL y0, LL x1, LL y1, int i) : index(i)
	{
		A = y1 - y0;
		B = x0 - x1;
		C = -x0 * A - y0 * B;
		
		assert(B != 0);
		if(B < 0)
		{
			A *= -1;
			B *= -1;
			C *= -1;
		}
	}
	
	bool operator<(const Line& L) const
	{
		//return (-C - A * globalX) * L.B < (-L.C - L.A * globalX) * B;
		return (__int128)(-C - A * globalX) * L.B < (__int128)(-L.C - L.A * globalX) * B;
	}
}lines[N];

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


set<int> g[N], rg[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};
	
	
	vector<PII> events;
	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] = Line(x[0][i], y[0][i], x[1][i], y[1][i], i);

		events.PB(MP(x[0][i], i + 1));
		events.PB(MP(x[1][i], -i - 1));
	}
	
	
	
	sort(ALL(xs));
	
	set<Line> curLines;
	sort(ALL(events));
	
	FOR(i, 0, SZ(events))
	{
		globalX = events[i].F;
		int ind = events[i].S;
		if(ind > 0)
		{
			ind--;
			
			auto it = curLines.lower_bound(Line(y[0][ind], ind));
			
			if(it != curLines.end())
			{
				g[ind].insert(it->index);
				rg[it->index].insert(ind);
			}
			if(it != curLines.begin())
			{
				g[prev(it)->index].insert(ind);
				rg[ind].insert(prev(it)->index);
			}
			curLines.insert(lines[ind]);
		}
		else
		{
			ind = -ind - 1;
			assert(curLines.count(lines[ind]));
			curLines.erase(lines[ind]);
		
			auto it = curLines.lower_bound(Line(y[1][ind], ind));
			
			if(it != curLines.end())
			{
				g[ind].insert(it->index);
				rg[it->index].insert(ind);
			}
			if(it != curLines.begin())
			{
				g[prev(it)->index].insert(ind);
				rg[ind].insert(prev(it)->index);
			}
		}
	}
	
	
	
	VI q;
	FOR(i, 0, n)
		if(SZ(g[i]) == 0)
			q.PB(i);
	
	l = 2 * (lower_bound(ALL(xs), l) - xs.begin());
	r = 2 * (lower_bound(ALL(xs), r) - xs.begin());
	//cout << l << " " << r << endl;
	T.build(1, 0, 2 * SZ(xs), l, r + 1);
	
	
	FOR(i, 0, SZ(q))
	{
		//FOR(j, 0, SZ(xs))
		//	cout << T.query(1, 0, SZ(xs), j, j + 1) << " ";
		//cout << endl;
		int v = q[i];
		for(int to : rg[v])
		{
			assert(g[to].count(v));
			g[to].erase(v);
			if(SZ(g[to]) == 0)
				q.PB(to);
		}
		//work with v;
		int L = 2 * (lower_bound(ALL(xs), x[0][v]) - xs.begin());	
		int R = 2 * (lower_bound(ALL(xs), x[1][v]) - xs.begin());
	
		//cout << L << " " << R << endl;
		
		int to = (y[0][v] < y[1][v]) ? L : R;	
		
		int mn = T.query(1, 0, 2 * SZ(xs), L, R + 1);
		T.add(1, 0, 2 * SZ(xs), L, R + 1);
		T.upd(1, 0, 2 * SZ(xs), to, mn);
	}
	cout << T.query(1, 0, 2 * SZ(xs), l, r + 1) << endl;
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 55ms
memory: 396688kb

Test #2:

score: 0
Accepted
time: 63ms
memory: 396760kb

Test #3:

score: 0
Accepted
time: 51ms
memory: 396692kb

Test #4:

score: 0
Accepted
time: 44ms
memory: 396776kb

Test #5:

score: 0
Accepted
time: 44ms
memory: 396772kb

Test #6:

score: 0
Accepted
time: 59ms
memory: 396772kb

Test #7:

score: 0
Accepted
time: 59ms
memory: 396764kb

Test #8:

score: 0
Accepted
time: 35ms
memory: 396716kb

Test #9:

score: 0
Accepted
time: 54ms
memory: 396720kb

Test #10:

score: 0
Accepted
time: 59ms
memory: 396804kb

Test #11:

score: 0
Accepted
time: 55ms
memory: 396688kb

Test #12:

score: 0
Accepted
time: 1374ms
memory: 554264kb

Test #13:

score: 0
Accepted
time: 48ms
memory: 396688kb

Test #14:

score: 0
Accepted
time: 56ms
memory: 396720kb

Test #15:

score: 0
Accepted
time: 57ms
memory: 396768kb

Test #16:

score: 0
Accepted
time: 41ms
memory: 396804kb

Test #17:

score: 0
Accepted
time: 51ms
memory: 396740kb

Test #18:

score: 0
Accepted
time: 80ms
memory: 396768kb

Test #19:

score: 0
Accepted
time: 52ms
memory: 396712kb

Test #20:

score: 0
Accepted
time: 52ms
memory: 396684kb

Test #21:

score: 0
Accepted
time: 43ms
memory: 396712kb

Test #22:

score: 0
Accepted
time: 55ms
memory: 396692kb

Test #23:

score: 0
Accepted
time: 58ms
memory: 396728kb

Test #24:

score: 0
Accepted
time: 35ms
memory: 396720kb

Test #25:

score: 0
Accepted
time: 53ms
memory: 396788kb

Test #26:

score: 0
Accepted
time: 55ms
memory: 396796kb

Test #27:

score: 0
Accepted
time: 51ms
memory: 396712kb

Test #28:

score: 0
Accepted
time: 69ms
memory: 396708kb

Test #29:

score: 0
Accepted
time: 58ms
memory: 396724kb

Test #30:

score: 0
Accepted
time: 60ms
memory: 396700kb

Test #31:

score: 0
Accepted
time: 52ms
memory: 396756kb

Test #32:

score: 0
Accepted
time: 69ms
memory: 396720kb

Test #33:

score: 0
Accepted
time: 62ms
memory: 396720kb

Test #34:

score: 0
Accepted
time: 47ms
memory: 396716kb

Test #35:

score: -100
Wrong Answer
time: 2350ms
memory: 577712kb