Submission #265343

# Submission time Handle Problem Language Result Execution time Memory
265343 2020-08-14T16:11:28 Z dennisstar Treatment Project (JOI20_treatment) C++17
100 / 100
338 ms 28268 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define em emplace
#define eb emplace_back
using namespace std;
using ll = long long;
using pli = pair<ll, int>;

const int MX = 1e5 + 5;

int N, M;
int T[MX], L[MX], R[MX], C[MX], U[MX];
vector<int> cp;

priority_queue<pli> st[MX];
vector<int> v;

void upd(int t, int x) {
	while (t<=cp.size())
		st[t].em(-(L[x]+T[x]), x), t+=t&-t;
}

void get(int t, int x) {
	while (t) {
		while (st[t].size()&&-st[t].top().fi<=x)
			v.eb(st[t].top().se),
			st[t].pop();
		t-=t&-t;
	}
}

int main() {
	cin.tie(0)->sync_with_stdio(0);

	cin>>N>>M;
	for (int i=1; i<=M; i++)
		cin>>T[i]>>L[i]>>R[i]>>C[i],
		cp.eb(L[i]-T[i]);
	
	sort(cp.begin(), cp.end());
	cp.resize(unique(cp.begin(), cp.end())-cp.begin());

	for (int i=1; i<=M; i++)
		upd(lower_bound(cp.begin(), cp.end(), L[i]-T[i])-cp.begin()+1, i);

	priority_queue<pli> pq;
	for (int i=1; i<=M; i++) if (L[i]==1)
		pq.em(-C[i], i),
		U[i]=1;

	while (pq.size()) {
		auto k=pq.top();
		pq.pop();

		int n=k.se;
		if (R[n]==N) {
			cout<<-k.fi<<'\n';
			return 0;
		}

		v.clear();
		get(upper_bound(cp.begin(), cp.end(), R[n]-T[n]+1)-cp.begin(), R[n]+T[n]+1);

		for (auto &i:v) if (!U[i]) {
			U[i]=1;
			pq.em(k.fi-C[i], i);
		}
	}

	cout<<"-1\n";
	return 0;
}

Compilation message

treatment.cpp: In function 'void upd(int, int)':
treatment.cpp:20:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  while (t<=cp.size())
      |         ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 266 ms 23792 KB Output is correct
2 Correct 207 ms 23536 KB Output is correct
3 Correct 281 ms 28004 KB Output is correct
4 Correct 260 ms 28268 KB Output is correct
5 Correct 108 ms 17008 KB Output is correct
6 Correct 142 ms 17720 KB Output is correct
7 Correct 159 ms 24040 KB Output is correct
8 Correct 66 ms 13932 KB Output is correct
9 Correct 76 ms 17140 KB Output is correct
10 Correct 90 ms 22632 KB Output is correct
11 Correct 178 ms 27572 KB Output is correct
12 Correct 198 ms 27416 KB Output is correct
13 Correct 250 ms 27240 KB Output is correct
14 Correct 252 ms 27124 KB Output is correct
15 Correct 264 ms 25324 KB Output is correct
16 Correct 257 ms 24428 KB Output is correct
17 Correct 266 ms 24940 KB Output is correct
18 Correct 184 ms 27748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 3 ms 3584 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 2 ms 3456 KB Output is correct
8 Correct 2 ms 3456 KB Output is correct
9 Correct 2 ms 3456 KB Output is correct
10 Correct 2 ms 3456 KB Output is correct
11 Correct 2 ms 3456 KB Output is correct
12 Correct 3 ms 3456 KB Output is correct
13 Correct 2 ms 3456 KB Output is correct
14 Correct 2 ms 3456 KB Output is correct
15 Correct 2 ms 3456 KB Output is correct
16 Correct 3 ms 3456 KB Output is correct
17 Correct 3 ms 3456 KB Output is correct
18 Correct 2 ms 3456 KB Output is correct
19 Correct 3 ms 3584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 3 ms 3584 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 2 ms 3456 KB Output is correct
8 Correct 2 ms 3456 KB Output is correct
9 Correct 2 ms 3456 KB Output is correct
10 Correct 2 ms 3456 KB Output is correct
11 Correct 2 ms 3456 KB Output is correct
12 Correct 3 ms 3456 KB Output is correct
13 Correct 2 ms 3456 KB Output is correct
14 Correct 2 ms 3456 KB Output is correct
15 Correct 2 ms 3456 KB Output is correct
16 Correct 3 ms 3456 KB Output is correct
17 Correct 3 ms 3456 KB Output is correct
18 Correct 2 ms 3456 KB Output is correct
19 Correct 3 ms 3584 KB Output is correct
20 Correct 12 ms 4512 KB Output is correct
21 Correct 10 ms 4480 KB Output is correct
22 Correct 9 ms 4352 KB Output is correct
23 Correct 9 ms 4352 KB Output is correct
24 Correct 10 ms 4496 KB Output is correct
25 Correct 13 ms 4480 KB Output is correct
26 Correct 10 ms 4480 KB Output is correct
27 Correct 9 ms 4480 KB Output is correct
28 Correct 9 ms 4480 KB Output is correct
29 Correct 11 ms 4352 KB Output is correct
30 Correct 7 ms 4352 KB Output is correct
31 Correct 7 ms 4352 KB Output is correct
32 Correct 9 ms 4568 KB Output is correct
33 Correct 9 ms 4608 KB Output is correct
34 Correct 11 ms 4480 KB Output is correct
35 Correct 8 ms 4480 KB Output is correct
36 Correct 9 ms 4608 KB Output is correct
37 Correct 10 ms 4352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 266 ms 23792 KB Output is correct
2 Correct 207 ms 23536 KB Output is correct
3 Correct 281 ms 28004 KB Output is correct
4 Correct 260 ms 28268 KB Output is correct
5 Correct 108 ms 17008 KB Output is correct
6 Correct 142 ms 17720 KB Output is correct
7 Correct 159 ms 24040 KB Output is correct
8 Correct 66 ms 13932 KB Output is correct
9 Correct 76 ms 17140 KB Output is correct
10 Correct 90 ms 22632 KB Output is correct
11 Correct 178 ms 27572 KB Output is correct
12 Correct 198 ms 27416 KB Output is correct
13 Correct 250 ms 27240 KB Output is correct
14 Correct 252 ms 27124 KB Output is correct
15 Correct 264 ms 25324 KB Output is correct
16 Correct 257 ms 24428 KB Output is correct
17 Correct 266 ms 24940 KB Output is correct
18 Correct 184 ms 27748 KB Output is correct
19 Correct 2 ms 3456 KB Output is correct
20 Correct 2 ms 3456 KB Output is correct
21 Correct 2 ms 3456 KB Output is correct
22 Correct 2 ms 3456 KB Output is correct
23 Correct 3 ms 3584 KB Output is correct
24 Correct 2 ms 3456 KB Output is correct
25 Correct 2 ms 3456 KB Output is correct
26 Correct 2 ms 3456 KB Output is correct
27 Correct 2 ms 3456 KB Output is correct
28 Correct 2 ms 3456 KB Output is correct
29 Correct 2 ms 3456 KB Output is correct
30 Correct 3 ms 3456 KB Output is correct
31 Correct 2 ms 3456 KB Output is correct
32 Correct 2 ms 3456 KB Output is correct
33 Correct 2 ms 3456 KB Output is correct
34 Correct 3 ms 3456 KB Output is correct
35 Correct 3 ms 3456 KB Output is correct
36 Correct 2 ms 3456 KB Output is correct
37 Correct 3 ms 3584 KB Output is correct
38 Correct 12 ms 4512 KB Output is correct
39 Correct 10 ms 4480 KB Output is correct
40 Correct 9 ms 4352 KB Output is correct
41 Correct 9 ms 4352 KB Output is correct
42 Correct 10 ms 4496 KB Output is correct
43 Correct 13 ms 4480 KB Output is correct
44 Correct 10 ms 4480 KB Output is correct
45 Correct 9 ms 4480 KB Output is correct
46 Correct 9 ms 4480 KB Output is correct
47 Correct 11 ms 4352 KB Output is correct
48 Correct 7 ms 4352 KB Output is correct
49 Correct 7 ms 4352 KB Output is correct
50 Correct 9 ms 4568 KB Output is correct
51 Correct 9 ms 4608 KB Output is correct
52 Correct 11 ms 4480 KB Output is correct
53 Correct 8 ms 4480 KB Output is correct
54 Correct 9 ms 4608 KB Output is correct
55 Correct 10 ms 4352 KB Output is correct
56 Correct 269 ms 26476 KB Output is correct
57 Correct 231 ms 24684 KB Output is correct
58 Correct 235 ms 25964 KB Output is correct
59 Correct 239 ms 25840 KB Output is correct
60 Correct 237 ms 23280 KB Output is correct
61 Correct 241 ms 25964 KB Output is correct
62 Correct 268 ms 26288 KB Output is correct
63 Correct 208 ms 23280 KB Output is correct
64 Correct 199 ms 23280 KB Output is correct
65 Correct 270 ms 23788 KB Output is correct
66 Correct 247 ms 23280 KB Output is correct
67 Correct 315 ms 25072 KB Output is correct
68 Correct 257 ms 24688 KB Output is correct
69 Correct 210 ms 24168 KB Output is correct
70 Correct 302 ms 25188 KB Output is correct
71 Correct 272 ms 23920 KB Output is correct
72 Correct 203 ms 24428 KB Output is correct
73 Correct 310 ms 23532 KB Output is correct
74 Correct 154 ms 24436 KB Output is correct
75 Correct 120 ms 23460 KB Output is correct
76 Correct 202 ms 27884 KB Output is correct
77 Correct 198 ms 25584 KB Output is correct
78 Correct 265 ms 26608 KB Output is correct
79 Correct 338 ms 24816 KB Output is correct
80 Correct 270 ms 24432 KB Output is correct
81 Correct 175 ms 23028 KB Output is correct
82 Correct 269 ms 25060 KB Output is correct
83 Correct 272 ms 25196 KB Output is correct
84 Correct 318 ms 24428 KB Output is correct
85 Correct 273 ms 24588 KB Output is correct
86 Correct 239 ms 24432 KB Output is correct
87 Correct 283 ms 24428 KB Output is correct
88 Correct 269 ms 27364 KB Output is correct
89 Correct 242 ms 24536 KB Output is correct
90 Correct 203 ms 26732 KB Output is correct
91 Correct 169 ms 24176 KB Output is correct
92 Correct 248 ms 25584 KB Output is correct
93 Correct 305 ms 24296 KB Output is correct
94 Correct 253 ms 24812 KB Output is correct
95 Correct 272 ms 24812 KB Output is correct
96 Correct 185 ms 25320 KB Output is correct
97 Correct 224 ms 27288 KB Output is correct
98 Correct 224 ms 27880 KB Output is correct
99 Correct 206 ms 26600 KB Output is correct
100 Correct 176 ms 24824 KB Output is correct
101 Correct 250 ms 27172 KB Output is correct
102 Correct 215 ms 27744 KB Output is correct
103 Correct 227 ms 24944 KB Output is correct