Submission #261374

# Submission time Handle Problem Language Result Execution time Memory
261374 2020-08-11T16:51:07 Z Saboon Treatment Project (JOI20_treatment) C++14
100 / 100
2008 ms 202844 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 1e5 + 10;
const ll maxl = 20;

ll T[maxn], fen[maxn], L[maxn], R[maxn], C[maxn], p[maxn];
ll dp[maxn*maxl];
vector<pair<ll,ll>> g[maxn*maxl];
ll newll;

void dijkstra(ll v){
	memset(dp, -1, sizeof dp);
	set<pair<ll,ll>> s;
	dp[v] = 0;
	s.insert({dp[v], v});
	while (!s.empty()){
		v = (*s.begin()).second;
		s.erase(s.begin());
		for (auto [u, w] : g[v]){
			if (dp[u] == -1 or dp[u] > dp[v] + w){
				s.erase({dp[u],u});
				dp[u] = dp[v] + w;
				s.insert({dp[u],u});
			}
		}
	}
}

void add(ll idx, ll val){
	for (; idx < maxn; idx += idx & -idx){
		ll then = newll ++;
		if (fen[idx] != 0)
			g[then].push_back({fen[idx],0});
		fen[idx] = then;
		g[then].push_back({val,C[val]});
	}
}

void get(ll idx, ll val){
	for (; idx; idx -= idx & -idx)
		if (fen[idx] != 0)
			g[val].push_back({fen[idx],0});
}

int main(){
	ios_base::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	for (ll i = 1; i <= m; i++)
		cin >> T[i] >> L[i] >> R[i] >> C[i];
	for (ll i = 1; i <= m; i++)
		p[i] = i;
	sort(p+1, p+m+1, [](ll a, ll b){ return T[a] < T[b];});
	newll = m+3;
	for (ll iit = 1; iit <= m; iit++){
		ll i = p[iit];
		if (L[i] == 1)
			g[0].push_back({i,C[i]});
		if (R[i] == n)
			g[i].push_back({m+1, 0});
	}
	vector<pair<ll,ll>> event;
	for (ll iit = 1; iit <= m; iit++){
		ll i = p[iit];
		event.push_back({L[i]-T[i], -iit});
		event.push_back({R[i]-T[i]+1, +iit});
	}
	sort(event.begin(), event.end());
	for (auto [chert,iit] : event){
		if (iit < 0)
			add(-iit, p[-iit]);
		else
			get(iit, p[iit]);
	}
	event.clear();
	memset(fen, 0, sizeof fen);
	reverse(p+1, p+m+1);
	for (ll iit = 1; iit <= m; iit++){
		ll i = p[iit];
		event.push_back({L[i]+T[i], -iit});
		event.push_back({R[i]+T[i]+1, +iit});
	}
	sort(event.begin(), event.end());
	for (auto [chert,iit] : event){
		if (iit < 0)
			add(-iit, p[-iit]);
		else
			get(iit, p[iit]);
	}
	dijkstra(0);
	cout << dp[m+1] << endl;
}

Compilation message

treatment.cpp: In function 'void dijkstra(ll)':
treatment.cpp:20:13: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
   for (auto [u, w] : g[v]){
             ^
treatment.cpp: In function 'int main()':
treatment.cpp:70:12: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
  for (auto [chert,iit] : event){
            ^
treatment.cpp:70:22: warning: unused variable 'chert' [-Wunused-variable]
  for (auto [chert,iit] : event){
                      ^
treatment.cpp:85:12: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
  for (auto [chert,iit] : event){
            ^
treatment.cpp:85:22: warning: unused variable 'chert' [-Wunused-variable]
  for (auto [chert,iit] : event){
                      ^
# Verdict Execution time Memory Grader output
1 Correct 1128 ms 188772 KB Output is correct
2 Correct 746 ms 190944 KB Output is correct
3 Correct 1407 ms 196576 KB Output is correct
4 Correct 1333 ms 196432 KB Output is correct
5 Correct 1303 ms 195340 KB Output is correct
6 Correct 1127 ms 187784 KB Output is correct
7 Correct 870 ms 185060 KB Output is correct
8 Correct 479 ms 188380 KB Output is correct
9 Correct 461 ms 186264 KB Output is correct
10 Correct 456 ms 184112 KB Output is correct
11 Correct 1674 ms 200540 KB Output is correct
12 Correct 1758 ms 200416 KB Output is correct
13 Correct 1608 ms 195252 KB Output is correct
14 Correct 1616 ms 195296 KB Output is correct
15 Correct 1238 ms 190892 KB Output is correct
16 Correct 1203 ms 190820 KB Output is correct
17 Correct 1356 ms 190052 KB Output is correct
18 Correct 1723 ms 202844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 63736 KB Output is correct
2 Correct 46 ms 63776 KB Output is correct
3 Correct 45 ms 63736 KB Output is correct
4 Correct 46 ms 63736 KB Output is correct
5 Correct 45 ms 63736 KB Output is correct
6 Correct 44 ms 63736 KB Output is correct
7 Correct 47 ms 63736 KB Output is correct
8 Correct 44 ms 63736 KB Output is correct
9 Correct 50 ms 63736 KB Output is correct
10 Correct 47 ms 63868 KB Output is correct
11 Correct 44 ms 63736 KB Output is correct
12 Correct 53 ms 63736 KB Output is correct
13 Correct 45 ms 63736 KB Output is correct
14 Correct 46 ms 63736 KB Output is correct
15 Correct 45 ms 63736 KB Output is correct
16 Correct 46 ms 63744 KB Output is correct
17 Correct 45 ms 63736 KB Output is correct
18 Correct 45 ms 63776 KB Output is correct
19 Correct 45 ms 63744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 63736 KB Output is correct
2 Correct 46 ms 63776 KB Output is correct
3 Correct 45 ms 63736 KB Output is correct
4 Correct 46 ms 63736 KB Output is correct
5 Correct 45 ms 63736 KB Output is correct
6 Correct 44 ms 63736 KB Output is correct
7 Correct 47 ms 63736 KB Output is correct
8 Correct 44 ms 63736 KB Output is correct
9 Correct 50 ms 63736 KB Output is correct
10 Correct 47 ms 63868 KB Output is correct
11 Correct 44 ms 63736 KB Output is correct
12 Correct 53 ms 63736 KB Output is correct
13 Correct 45 ms 63736 KB Output is correct
14 Correct 46 ms 63736 KB Output is correct
15 Correct 45 ms 63736 KB Output is correct
16 Correct 46 ms 63744 KB Output is correct
17 Correct 45 ms 63736 KB Output is correct
18 Correct 45 ms 63776 KB Output is correct
19 Correct 45 ms 63744 KB Output is correct
20 Correct 87 ms 70900 KB Output is correct
21 Correct 84 ms 70900 KB Output is correct
22 Correct 78 ms 70136 KB Output is correct
23 Correct 73 ms 70136 KB Output is correct
24 Correct 90 ms 70900 KB Output is correct
25 Correct 91 ms 70648 KB Output is correct
26 Correct 85 ms 70520 KB Output is correct
27 Correct 80 ms 70520 KB Output is correct
28 Correct 87 ms 70896 KB Output is correct
29 Correct 83 ms 70648 KB Output is correct
30 Correct 66 ms 70520 KB Output is correct
31 Correct 68 ms 70524 KB Output is correct
32 Correct 91 ms 71028 KB Output is correct
33 Correct 94 ms 71028 KB Output is correct
34 Correct 87 ms 70776 KB Output is correct
35 Correct 96 ms 71156 KB Output is correct
36 Correct 95 ms 71156 KB Output is correct
37 Correct 89 ms 70648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1128 ms 188772 KB Output is correct
2 Correct 746 ms 190944 KB Output is correct
3 Correct 1407 ms 196576 KB Output is correct
4 Correct 1333 ms 196432 KB Output is correct
5 Correct 1303 ms 195340 KB Output is correct
6 Correct 1127 ms 187784 KB Output is correct
7 Correct 870 ms 185060 KB Output is correct
8 Correct 479 ms 188380 KB Output is correct
9 Correct 461 ms 186264 KB Output is correct
10 Correct 456 ms 184112 KB Output is correct
11 Correct 1674 ms 200540 KB Output is correct
12 Correct 1758 ms 200416 KB Output is correct
13 Correct 1608 ms 195252 KB Output is correct
14 Correct 1616 ms 195296 KB Output is correct
15 Correct 1238 ms 190892 KB Output is correct
16 Correct 1203 ms 190820 KB Output is correct
17 Correct 1356 ms 190052 KB Output is correct
18 Correct 1723 ms 202844 KB Output is correct
19 Correct 46 ms 63736 KB Output is correct
20 Correct 46 ms 63776 KB Output is correct
21 Correct 45 ms 63736 KB Output is correct
22 Correct 46 ms 63736 KB Output is correct
23 Correct 45 ms 63736 KB Output is correct
24 Correct 44 ms 63736 KB Output is correct
25 Correct 47 ms 63736 KB Output is correct
26 Correct 44 ms 63736 KB Output is correct
27 Correct 50 ms 63736 KB Output is correct
28 Correct 47 ms 63868 KB Output is correct
29 Correct 44 ms 63736 KB Output is correct
30 Correct 53 ms 63736 KB Output is correct
31 Correct 45 ms 63736 KB Output is correct
32 Correct 46 ms 63736 KB Output is correct
33 Correct 45 ms 63736 KB Output is correct
34 Correct 46 ms 63744 KB Output is correct
35 Correct 45 ms 63736 KB Output is correct
36 Correct 45 ms 63776 KB Output is correct
37 Correct 45 ms 63744 KB Output is correct
38 Correct 87 ms 70900 KB Output is correct
39 Correct 84 ms 70900 KB Output is correct
40 Correct 78 ms 70136 KB Output is correct
41 Correct 73 ms 70136 KB Output is correct
42 Correct 90 ms 70900 KB Output is correct
43 Correct 91 ms 70648 KB Output is correct
44 Correct 85 ms 70520 KB Output is correct
45 Correct 80 ms 70520 KB Output is correct
46 Correct 87 ms 70896 KB Output is correct
47 Correct 83 ms 70648 KB Output is correct
48 Correct 66 ms 70520 KB Output is correct
49 Correct 68 ms 70524 KB Output is correct
50 Correct 91 ms 71028 KB Output is correct
51 Correct 94 ms 71028 KB Output is correct
52 Correct 87 ms 70776 KB Output is correct
53 Correct 96 ms 71156 KB Output is correct
54 Correct 95 ms 71156 KB Output is correct
55 Correct 89 ms 70648 KB Output is correct
56 Correct 1193 ms 198016 KB Output is correct
57 Correct 1252 ms 198368 KB Output is correct
58 Correct 1020 ms 185184 KB Output is correct
59 Correct 1045 ms 185556 KB Output is correct
60 Correct 967 ms 170148 KB Output is correct
61 Correct 918 ms 185232 KB Output is correct
62 Correct 1143 ms 198112 KB Output is correct
63 Correct 548 ms 161124 KB Output is correct
64 Correct 541 ms 161120 KB Output is correct
65 Correct 1129 ms 191200 KB Output is correct
66 Correct 747 ms 170172 KB Output is correct
67 Correct 1649 ms 190520 KB Output is correct
68 Correct 1365 ms 188980 KB Output is correct
69 Correct 1158 ms 189152 KB Output is correct
70 Correct 1563 ms 191200 KB Output is correct
71 Correct 1355 ms 189792 KB Output is correct
72 Correct 1119 ms 189048 KB Output is correct
73 Correct 1489 ms 191208 KB Output is correct
74 Correct 534 ms 189664 KB Output is correct
75 Correct 521 ms 188260 KB Output is correct
76 Correct 1826 ms 200928 KB Output is correct
77 Correct 1902 ms 201056 KB Output is correct
78 Correct 1826 ms 195424 KB Output is correct
79 Correct 1528 ms 190816 KB Output is correct
80 Correct 1282 ms 191196 KB Output is correct
81 Correct 596 ms 190432 KB Output is correct
82 Correct 1504 ms 191072 KB Output is correct
83 Correct 1604 ms 191204 KB Output is correct
84 Correct 1593 ms 190048 KB Output is correct
85 Correct 964 ms 190604 KB Output is correct
86 Correct 1030 ms 190556 KB Output is correct
87 Correct 1132 ms 190460 KB Output is correct
88 Correct 977 ms 187744 KB Output is correct
89 Correct 1020 ms 189536 KB Output is correct
90 Correct 1652 ms 196968 KB Output is correct
91 Correct 1358 ms 193572 KB Output is correct
92 Correct 1060 ms 190540 KB Output is correct
93 Correct 1586 ms 190720 KB Output is correct
94 Correct 1368 ms 191460 KB Output is correct
95 Correct 1295 ms 189152 KB Output is correct
96 Correct 1702 ms 197212 KB Output is correct
97 Correct 1835 ms 199132 KB Output is correct
98 Correct 1906 ms 199220 KB Output is correct
99 Correct 2008 ms 198876 KB Output is correct
100 Correct 1595 ms 199656 KB Output is correct
101 Correct 1907 ms 198804 KB Output is correct
102 Correct 1834 ms 200656 KB Output is correct
103 Correct 1139 ms 191504 KB Output is correct