Submission #537981

# Submission time Handle Problem Language Result Execution time Memory
537981 2022-03-16T01:47:56 Z 8e7 Treatment Project (JOI20_treatment) C++17
4 / 100
179 ms 60160 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define pii pair<ll, ll>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1LL<<60;

vector<pii> lef[maxn];
struct segtree{
	vector<pii> seg[4*maxn];
	void init(int cur, int l, int r) {
		if (r <= l) return;
		if (r - l == 1) {
			seg[cur] = lef[l];
			return;
		}
		int m = (l + r) / 2;
		init(cur*2, l, m), init(cur*2+1, m, r);	
		int ind = 0;
		for (int i = 0;i < seg[cur*2].size();i++) {
			while (ind < seg[cur*2+1].size() && seg[cur*2+1][ind] > seg[cur*2][i]) {
				seg[cur].push_back(seg[cur*2+1][ind++]);
			}
			seg[cur].push_back(seg[cur*2][i]);
		}
		while (ind < seg[cur*2+1].size()) {
			seg[cur].push_back(seg[cur*2+1][ind++]);
		}
	}
	void getind(int cur, int l, int r, int ql, int qr, int y, vector<int> &ret, bool add) {
		if (r <= l || ql >= r || qr <= l || seg[cur].size() == 0 || seg[cur].back().ff > y) return;
		if (ql <= l && qr >= r) {
			while (seg[cur].size() && seg[cur].back().ff <= y) {
				if (add) ret.push_back(seg[cur].back().ss);
				seg[cur].pop_back();
			}
			add = 0;
		}
		if (r - l == 1) return;
		int m = (l + r) / 2;
		getind(cur*2, l, m, ql, qr, y, ret, add);
		getind(cur*2+1, m, r, ql, qr, y, ret, add);
	}
} tr;
struct seg{
	int t, l, r, x, y;
	int cost;	
	seg(){t = l = r = cost = 0;}
} a[maxn];
ll dis[maxn];
int main() {
	io
	int L, n;
	cin >> L >> n;
	vector<int> vx;
	for (int i = 1;i <= n;i++) {
		cin >> a[i].t >> a[i].l >> a[i].r >> a[i].cost;	
		a[i].x = a[i].l - a[i].t;
		a[i].y = a[i].l + a[i].t;
		vx.push_back(a[i].x);
	}
	sort(vx.begin(), vx.end());	
	vx.resize(int(unique(vx.begin(), vx.end()) - vx.begin()));
	for (int i = 1;i <= n;i++) {
		a[i].x = lower_bound(vx.begin(), vx.end(), a[i].x) - vx.begin();
		lef[a[i].x].push_back({a[i].y, i});	
	}
	for (int i = 0;i < n;i++) sort(lef[i].begin(), lef[i].end());
	tr.init(1, 0, n);
	

	priority_queue<pii, vector<pii>, greater<pii> > pq;	
	for (int i = 1;i <= n;i++) {
		dis[i] = inf;
		if (a[i].l == 1) {
			dis[i] = a[i].cost;
			pq.push({dis[i], i});
		}
	}
	dis[n+1] = inf;	

	while (pq.size()) {
		auto [d, cur] = pq.top();
		pq.pop();
		if (d != dis[cur]) continue;
		if (a[cur].r == L) dis[n+1] = min(dis[n+1], d);
		vector<int> upd;	
		int xv = upper_bound(vx.begin(), vx.end(), a[cur].r - a[cur].t + 1) - vx.begin();
		tr.getind(1, 0, n, 0, xv, a[cur].r + a[cur].t + 1, upd, 1);
		for (int i:upd) {
			if (d + a[i].cost < dis[i]) {
				dis[i] = d + a[i].cost;
				pq.push({dis[i], i});
			}
		}
	}
	cout << (dis[n+1] == inf ? -1 : dis[n+1]) << "\n";
}

Compilation message

treatment.cpp: In member function 'void segtree::init(int, int, int)':
treatment.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for (int i = 0;i < seg[cur*2].size();i++) {
      |                  ~~^~~~~~~~~~~~~~~~~~~
treatment.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |    while (ind < seg[cur*2+1].size() && seg[cur*2+1][ind] > seg[cur*2][i]) {
      |           ~~~~^~~~~~~~~~~~~~~~~~~~~
treatment.cpp:41:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   while (ind < seg[cur*2+1].size()) {
      |          ~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 166 ms 56900 KB Output is correct
2 Correct 154 ms 57116 KB Output is correct
3 Correct 138 ms 53316 KB Output is correct
4 Correct 140 ms 53352 KB Output is correct
5 Correct 106 ms 50332 KB Output is correct
6 Correct 100 ms 52780 KB Output is correct
7 Correct 108 ms 52036 KB Output is correct
8 Correct 71 ms 48092 KB Output is correct
9 Correct 70 ms 52776 KB Output is correct
10 Correct 76 ms 52132 KB Output is correct
11 Correct 172 ms 59800 KB Output is correct
12 Correct 172 ms 60160 KB Output is correct
13 Correct 166 ms 59548 KB Output is correct
14 Correct 179 ms 59532 KB Output is correct
15 Correct 162 ms 57132 KB Output is correct
16 Correct 159 ms 57100 KB Output is correct
17 Correct 159 ms 57160 KB Output is correct
18 Correct 172 ms 59964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Incorrect 8 ms 14400 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Incorrect 8 ms 14400 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 166 ms 56900 KB Output is correct
2 Correct 154 ms 57116 KB Output is correct
3 Correct 138 ms 53316 KB Output is correct
4 Correct 140 ms 53352 KB Output is correct
5 Correct 106 ms 50332 KB Output is correct
6 Correct 100 ms 52780 KB Output is correct
7 Correct 108 ms 52036 KB Output is correct
8 Correct 71 ms 48092 KB Output is correct
9 Correct 70 ms 52776 KB Output is correct
10 Correct 76 ms 52132 KB Output is correct
11 Correct 172 ms 59800 KB Output is correct
12 Correct 172 ms 60160 KB Output is correct
13 Correct 166 ms 59548 KB Output is correct
14 Correct 179 ms 59532 KB Output is correct
15 Correct 162 ms 57132 KB Output is correct
16 Correct 159 ms 57100 KB Output is correct
17 Correct 159 ms 57160 KB Output is correct
18 Correct 172 ms 59964 KB Output is correct
19 Correct 8 ms 14420 KB Output is correct
20 Incorrect 8 ms 14400 KB Output isn't correct
21 Halted 0 ms 0 KB -