Submission #216771

# Submission time Handle Problem Language Result Execution time Memory
216771 2020-03-28T03:54:33 Z abacaba Treatment Project (JOI20_treatment) C++14
39 / 100
1949 ms 524292 KB
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <typename T> inline T range(T l, T r) {
	return uniform_int_distribution <T>(l, r)(rng);
}

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int mod = 1e9 + 7;
const ll inf = 2e18;
const int N = 1e6 + 15;
int n, m;
ll ans = -1;

vector <int> compress;
int sz;

ll d[N];

set <pair <ll, int>> q;

inline int gt(int x) {
	return lower_bound(compress.begin(), compress.end(), x) - compress.begin() + 1;
}

struct pt {
	int t, l, r, c;
} a[N];

struct segment_tree {
	set <pii> t[N << 2];
	void get(int v, int tl, int tr, int l, int r, int val, vector <int> &res) {
		if(tl > r || tr < l)
			return;
		if(tl >= l && tr <= r) {
			while(!t[v].empty() && t[v].begin()->f <= val) {
				res.pb(t[v].begin()->se);
				t[v].erase(t[v].begin());
			}
			return;
		}
		int mid = tl + tr >> 1;
		get(v << 1, tl, mid, l, r, val, res);
		get(v << 1 | 1, mid + 1, tr, l, r, val, res);
	}
	void update(int v, int tl, int tr, int pos, pii val, bool insert) {
		if(insert)
			t[v].insert(val);
		else if(t[v].find(val) != t[v].end())
			t[v].erase(val);
		if(tl == tr)
			return;
		int mid = tl + tr >> 1;
		if(pos <= mid)
			update(v << 1, tl, mid, pos, val, insert);
		else
			update(v << 1 | 1, mid + 1, tr, pos, val, insert);
	}
} t1, t2;

main() {
	fill(d, d + N, inf);
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= m; ++i) {
		cin >> a[i].t >> a[i].l >> a[i].r >> a[i].c;
		compress.pb(a[i].t);
	}
	sort(compress.begin(), compress.end());
	compress.erase(unique(compress.begin(), compress.end()), compress.end());

	sz = compress.size();

	for(int i = 1; i <= m; ++i) {
		--a[i].l;
		if(a[i].l == 0) {
			d[i] = a[i].c;
			q.insert({d[i], i});
		}
		else {
			t1.update(1, 1, sz, gt(a[i].t), mp(a[i].l + a[i].t, i), true);
			t2.update(1, 1, sz, gt(a[i].t), mp(a[i].l - a[i].t, i), true);
		}
	}
	while(!q.empty()) {
		int i = q.begin()->se;
		q.erase(q.begin());

		vector <int> res[2] = {{}, {}};

		t1.get(1, 1, sz, gt(a[i].t), sz, a[i].r + a[i].t, res[0]);
		t2.get(1, 1, sz, 1, gt(a[i].t), a[i].r - a[i].t, res[1]);

		for(int t = 0; t < 2; ++t) {
			for(int j : res[t]) {
				d[j] = d[i] + a[j].c;
				q.insert(mp(d[j], j));

				t1.update(1, 1, sz, gt(a[j].t), mp(a[j].l + a[j].t, j), false);
				t2.update(1, 1, sz, gt(a[j].t), mp(a[j].l - a[j].t, j), false);
			}
		}
	}
	for(int i = 1; i <= m; ++i) {
		if(a[i].r != n || d[i] == inf)
			continue;
		if(ans == -1 || d[i] < ans)
			ans = d[i];
	}
	cout << ans << endl;
	return 0;
}

Compilation message

treatment.cpp: In member function 'void segment_tree::get(int, int, int, int, int, int, std::vector<int>&)':
treatment.cpp:86:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = tl + tr >> 1;
             ~~~^~~~
treatment.cpp: In member function 'void segment_tree::update(int, int, int, int, std::pair<int, int>, bool)':
treatment.cpp:97:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = tl + tr >> 1;
             ~~~^~~~
treatment.cpp: At global scope:
treatment.cpp:105:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# Verdict Execution time Memory Grader output
1 Correct 378 ms 395252 KB Output is correct
2 Correct 341 ms 395252 KB Output is correct
3 Correct 390 ms 394996 KB Output is correct
4 Correct 364 ms 394868 KB Output is correct
5 Correct 393 ms 395252 KB Output is correct
6 Correct 346 ms 395508 KB Output is correct
7 Correct 351 ms 395248 KB Output is correct
8 Correct 305 ms 395252 KB Output is correct
9 Correct 305 ms 395380 KB Output is correct
10 Correct 299 ms 395252 KB Output is correct
11 Correct 511 ms 396276 KB Output is correct
12 Correct 452 ms 396020 KB Output is correct
13 Correct 459 ms 395380 KB Output is correct
14 Correct 467 ms 395252 KB Output is correct
15 Correct 376 ms 395392 KB Output is correct
16 Correct 417 ms 395400 KB Output is correct
17 Correct 389 ms 395520 KB Output is correct
18 Correct 470 ms 396276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 214 ms 383864 KB Output is correct
2 Correct 206 ms 383864 KB Output is correct
3 Correct 213 ms 383992 KB Output is correct
4 Correct 205 ms 383864 KB Output is correct
5 Correct 206 ms 383992 KB Output is correct
6 Correct 212 ms 383864 KB Output is correct
7 Correct 209 ms 383992 KB Output is correct
8 Correct 209 ms 383992 KB Output is correct
9 Correct 206 ms 383864 KB Output is correct
10 Correct 219 ms 383992 KB Output is correct
11 Correct 208 ms 383864 KB Output is correct
12 Correct 210 ms 383864 KB Output is correct
13 Correct 221 ms 383940 KB Output is correct
14 Correct 208 ms 383992 KB Output is correct
15 Correct 209 ms 383864 KB Output is correct
16 Correct 216 ms 383992 KB Output is correct
17 Correct 213 ms 383864 KB Output is correct
18 Correct 214 ms 383996 KB Output is correct
19 Correct 213 ms 383992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 214 ms 383864 KB Output is correct
2 Correct 206 ms 383864 KB Output is correct
3 Correct 213 ms 383992 KB Output is correct
4 Correct 205 ms 383864 KB Output is correct
5 Correct 206 ms 383992 KB Output is correct
6 Correct 212 ms 383864 KB Output is correct
7 Correct 209 ms 383992 KB Output is correct
8 Correct 209 ms 383992 KB Output is correct
9 Correct 206 ms 383864 KB Output is correct
10 Correct 219 ms 383992 KB Output is correct
11 Correct 208 ms 383864 KB Output is correct
12 Correct 210 ms 383864 KB Output is correct
13 Correct 221 ms 383940 KB Output is correct
14 Correct 208 ms 383992 KB Output is correct
15 Correct 209 ms 383864 KB Output is correct
16 Correct 216 ms 383992 KB Output is correct
17 Correct 213 ms 383864 KB Output is correct
18 Correct 214 ms 383996 KB Output is correct
19 Correct 213 ms 383992 KB Output is correct
20 Correct 251 ms 388472 KB Output is correct
21 Correct 244 ms 388472 KB Output is correct
22 Correct 263 ms 388800 KB Output is correct
23 Correct 246 ms 388728 KB Output is correct
24 Correct 269 ms 389392 KB Output is correct
25 Correct 261 ms 390264 KB Output is correct
26 Correct 262 ms 390392 KB Output is correct
27 Correct 250 ms 390264 KB Output is correct
28 Correct 268 ms 389368 KB Output is correct
29 Correct 263 ms 390136 KB Output is correct
30 Correct 254 ms 390280 KB Output is correct
31 Correct 240 ms 390264 KB Output is correct
32 Correct 281 ms 390392 KB Output is correct
33 Correct 271 ms 390264 KB Output is correct
34 Correct 266 ms 390264 KB Output is correct
35 Correct 268 ms 390264 KB Output is correct
36 Correct 276 ms 390472 KB Output is correct
37 Correct 261 ms 390008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 378 ms 395252 KB Output is correct
2 Correct 341 ms 395252 KB Output is correct
3 Correct 390 ms 394996 KB Output is correct
4 Correct 364 ms 394868 KB Output is correct
5 Correct 393 ms 395252 KB Output is correct
6 Correct 346 ms 395508 KB Output is correct
7 Correct 351 ms 395248 KB Output is correct
8 Correct 305 ms 395252 KB Output is correct
9 Correct 305 ms 395380 KB Output is correct
10 Correct 299 ms 395252 KB Output is correct
11 Correct 511 ms 396276 KB Output is correct
12 Correct 452 ms 396020 KB Output is correct
13 Correct 459 ms 395380 KB Output is correct
14 Correct 467 ms 395252 KB Output is correct
15 Correct 376 ms 395392 KB Output is correct
16 Correct 417 ms 395400 KB Output is correct
17 Correct 389 ms 395520 KB Output is correct
18 Correct 470 ms 396276 KB Output is correct
19 Correct 214 ms 383864 KB Output is correct
20 Correct 206 ms 383864 KB Output is correct
21 Correct 213 ms 383992 KB Output is correct
22 Correct 205 ms 383864 KB Output is correct
23 Correct 206 ms 383992 KB Output is correct
24 Correct 212 ms 383864 KB Output is correct
25 Correct 209 ms 383992 KB Output is correct
26 Correct 209 ms 383992 KB Output is correct
27 Correct 206 ms 383864 KB Output is correct
28 Correct 219 ms 383992 KB Output is correct
29 Correct 208 ms 383864 KB Output is correct
30 Correct 210 ms 383864 KB Output is correct
31 Correct 221 ms 383940 KB Output is correct
32 Correct 208 ms 383992 KB Output is correct
33 Correct 209 ms 383864 KB Output is correct
34 Correct 216 ms 383992 KB Output is correct
35 Correct 213 ms 383864 KB Output is correct
36 Correct 214 ms 383996 KB Output is correct
37 Correct 213 ms 383992 KB Output is correct
38 Correct 251 ms 388472 KB Output is correct
39 Correct 244 ms 388472 KB Output is correct
40 Correct 263 ms 388800 KB Output is correct
41 Correct 246 ms 388728 KB Output is correct
42 Correct 269 ms 389392 KB Output is correct
43 Correct 261 ms 390264 KB Output is correct
44 Correct 262 ms 390392 KB Output is correct
45 Correct 250 ms 390264 KB Output is correct
46 Correct 268 ms 389368 KB Output is correct
47 Correct 263 ms 390136 KB Output is correct
48 Correct 254 ms 390280 KB Output is correct
49 Correct 240 ms 390264 KB Output is correct
50 Correct 281 ms 390392 KB Output is correct
51 Correct 271 ms 390264 KB Output is correct
52 Correct 266 ms 390264 KB Output is correct
53 Correct 268 ms 390264 KB Output is correct
54 Correct 276 ms 390472 KB Output is correct
55 Correct 261 ms 390008 KB Output is correct
56 Correct 1949 ms 505272 KB Output is correct
57 Correct 1903 ms 505236 KB Output is correct
58 Runtime error 1291 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
59 Halted 0 ms 0 KB -