#include <bits/stdc++.h>
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
using namespace std;
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;
const int inf = 1e9, maxn = 4e5 + 148, mod = 777777777, N = 2e5 + 61;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 455;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;
int t[N], n, h, x, y, z, m, p[N], l[N], r[N], dp[N], sum;
bool was[N];
vpii gg[N];
vi g[N];
void inc (int pos, int x) {
while (pos < N) {
t[pos] += x;
pos |= pos + 1;
}
}
int Get (int r) {
int res = 0;
while (r >= 0) {
res += t[r];
r = (r & (r + 1)) - 1;
}
return res;
}
int update (int l, int r, int x) {
inc(l, x);
inc(r + 1, -x);
}
int get (int v) {
return v == p[v] ? v : p[v] = get(p[v]);
}
void merge (int v, int u) {
v = get(v);
u = get(u);
if (r[u] - l[u] > r[v] - l[u])
swap(v, u);
// cerr << " + " << l[v] << ' ' << r[v] << ' ' << dp[u] << endl;
// cerr << " + " << l[u] << ' ' << r[u] << ' ' << dp[v] << endl;
update(l[v], r[v], dp[u]);
update(l[u], r[u], dp[v]);
p[u] = v;
dp[v] += dp[u];
l[v] = min(l[v], l[u]);
r[v] = max(r[v], r[u]);
}
main () {
// file("");
scanf("%lld", &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &h);
g[h].pb(i);
}
for (int i = 1; i <= n; ++i)
l[i] = r[i] = p[i] = i;
scanf("%lld", &m);
for (int i = 1; i <= m; ++i) {
scanf("%lld%lld%lld", &x, &y, &z);
gg[y].pb({x, z});
sum += z;
}
for (int j = 1; j <= n; ++j) {
for (auto i : gg[j])
dp[get(i.f)] = max(dp[get(i.f)], Get(i.f) + i.s);
for (auto i : g[j]) {
was[i] = 1;
if (was[i - 1])
merge(i - 1, i);
if (was[i + 1])
merge(i + 1, i);
}
/* for (int i = 1; i <= n; ++i)
if (i == get(i))
cout << i << ' ' << dp[i] << endl;
cout << endl; */
}
int ans = 0;
for (int i = 1; i <= n; ++i)
ans = max(ans, dp[i]);
cout << sum - ans << endl;
}
Compilation message
constellation3.cpp: In function 'long long int update(long long int, long long int, long long int)':
constellation3.cpp:63:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
constellation3.cpp: At global scope:
constellation3.cpp:90:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
constellation3.cpp: In function 'int main()':
constellation3.cpp:92:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &n);
~~~~~^~~~~~~~~~~~
constellation3.cpp:94:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &h);
~~~~~^~~~~~~~~~~~
constellation3.cpp:101:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &m);
~~~~~^~~~~~~~~~~~
constellation3.cpp:103:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld", &x, &y, &z);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Output is correct |
2 |
Correct |
9 ms |
9856 KB |
Output is correct |
3 |
Correct |
10 ms |
9856 KB |
Output is correct |
4 |
Correct |
10 ms |
9856 KB |
Output is correct |
5 |
Correct |
10 ms |
9856 KB |
Output is correct |
6 |
Correct |
11 ms |
9856 KB |
Output is correct |
7 |
Correct |
10 ms |
9856 KB |
Output is correct |
8 |
Correct |
10 ms |
9856 KB |
Output is correct |
9 |
Correct |
10 ms |
9856 KB |
Output is correct |
10 |
Correct |
10 ms |
9856 KB |
Output is correct |
11 |
Correct |
10 ms |
9856 KB |
Output is correct |
12 |
Correct |
10 ms |
9728 KB |
Output is correct |
13 |
Correct |
10 ms |
9856 KB |
Output is correct |
14 |
Correct |
10 ms |
9856 KB |
Output is correct |
15 |
Correct |
10 ms |
9856 KB |
Output is correct |
16 |
Correct |
10 ms |
9856 KB |
Output is correct |
17 |
Correct |
10 ms |
9856 KB |
Output is correct |
18 |
Correct |
10 ms |
9856 KB |
Output is correct |
19 |
Correct |
11 ms |
9856 KB |
Output is correct |
20 |
Correct |
10 ms |
9856 KB |
Output is correct |
21 |
Correct |
10 ms |
9856 KB |
Output is correct |
22 |
Correct |
10 ms |
9856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Output is correct |
2 |
Correct |
9 ms |
9856 KB |
Output is correct |
3 |
Correct |
10 ms |
9856 KB |
Output is correct |
4 |
Correct |
10 ms |
9856 KB |
Output is correct |
5 |
Correct |
10 ms |
9856 KB |
Output is correct |
6 |
Correct |
11 ms |
9856 KB |
Output is correct |
7 |
Correct |
10 ms |
9856 KB |
Output is correct |
8 |
Correct |
10 ms |
9856 KB |
Output is correct |
9 |
Correct |
10 ms |
9856 KB |
Output is correct |
10 |
Correct |
10 ms |
9856 KB |
Output is correct |
11 |
Correct |
10 ms |
9856 KB |
Output is correct |
12 |
Correct |
10 ms |
9728 KB |
Output is correct |
13 |
Correct |
10 ms |
9856 KB |
Output is correct |
14 |
Correct |
10 ms |
9856 KB |
Output is correct |
15 |
Correct |
10 ms |
9856 KB |
Output is correct |
16 |
Correct |
10 ms |
9856 KB |
Output is correct |
17 |
Correct |
10 ms |
9856 KB |
Output is correct |
18 |
Correct |
10 ms |
9856 KB |
Output is correct |
19 |
Correct |
11 ms |
9856 KB |
Output is correct |
20 |
Correct |
10 ms |
9856 KB |
Output is correct |
21 |
Correct |
10 ms |
9856 KB |
Output is correct |
22 |
Correct |
10 ms |
9856 KB |
Output is correct |
23 |
Correct |
13 ms |
9984 KB |
Output is correct |
24 |
Correct |
12 ms |
9984 KB |
Output is correct |
25 |
Correct |
12 ms |
9984 KB |
Output is correct |
26 |
Correct |
11 ms |
9984 KB |
Output is correct |
27 |
Correct |
12 ms |
9984 KB |
Output is correct |
28 |
Correct |
11 ms |
9984 KB |
Output is correct |
29 |
Correct |
11 ms |
9984 KB |
Output is correct |
30 |
Correct |
12 ms |
9984 KB |
Output is correct |
31 |
Correct |
13 ms |
9984 KB |
Output is correct |
32 |
Correct |
11 ms |
9984 KB |
Output is correct |
33 |
Correct |
11 ms |
9984 KB |
Output is correct |
34 |
Correct |
11 ms |
9984 KB |
Output is correct |
35 |
Correct |
11 ms |
9984 KB |
Output is correct |
36 |
Correct |
11 ms |
9984 KB |
Output is correct |
37 |
Correct |
11 ms |
9984 KB |
Output is correct |
38 |
Correct |
11 ms |
9984 KB |
Output is correct |
39 |
Correct |
11 ms |
9984 KB |
Output is correct |
40 |
Correct |
11 ms |
9984 KB |
Output is correct |
41 |
Correct |
11 ms |
9984 KB |
Output is correct |
42 |
Correct |
11 ms |
9984 KB |
Output is correct |
43 |
Correct |
11 ms |
9984 KB |
Output is correct |
44 |
Correct |
11 ms |
9984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Output is correct |
2 |
Correct |
9 ms |
9856 KB |
Output is correct |
3 |
Correct |
10 ms |
9856 KB |
Output is correct |
4 |
Correct |
10 ms |
9856 KB |
Output is correct |
5 |
Correct |
10 ms |
9856 KB |
Output is correct |
6 |
Correct |
11 ms |
9856 KB |
Output is correct |
7 |
Correct |
10 ms |
9856 KB |
Output is correct |
8 |
Correct |
10 ms |
9856 KB |
Output is correct |
9 |
Correct |
10 ms |
9856 KB |
Output is correct |
10 |
Correct |
10 ms |
9856 KB |
Output is correct |
11 |
Correct |
10 ms |
9856 KB |
Output is correct |
12 |
Correct |
10 ms |
9728 KB |
Output is correct |
13 |
Correct |
10 ms |
9856 KB |
Output is correct |
14 |
Correct |
10 ms |
9856 KB |
Output is correct |
15 |
Correct |
10 ms |
9856 KB |
Output is correct |
16 |
Correct |
10 ms |
9856 KB |
Output is correct |
17 |
Correct |
10 ms |
9856 KB |
Output is correct |
18 |
Correct |
10 ms |
9856 KB |
Output is correct |
19 |
Correct |
11 ms |
9856 KB |
Output is correct |
20 |
Correct |
10 ms |
9856 KB |
Output is correct |
21 |
Correct |
10 ms |
9856 KB |
Output is correct |
22 |
Correct |
10 ms |
9856 KB |
Output is correct |
23 |
Correct |
13 ms |
9984 KB |
Output is correct |
24 |
Correct |
12 ms |
9984 KB |
Output is correct |
25 |
Correct |
12 ms |
9984 KB |
Output is correct |
26 |
Correct |
11 ms |
9984 KB |
Output is correct |
27 |
Correct |
12 ms |
9984 KB |
Output is correct |
28 |
Correct |
11 ms |
9984 KB |
Output is correct |
29 |
Correct |
11 ms |
9984 KB |
Output is correct |
30 |
Correct |
12 ms |
9984 KB |
Output is correct |
31 |
Correct |
13 ms |
9984 KB |
Output is correct |
32 |
Correct |
11 ms |
9984 KB |
Output is correct |
33 |
Correct |
11 ms |
9984 KB |
Output is correct |
34 |
Correct |
11 ms |
9984 KB |
Output is correct |
35 |
Correct |
11 ms |
9984 KB |
Output is correct |
36 |
Correct |
11 ms |
9984 KB |
Output is correct |
37 |
Correct |
11 ms |
9984 KB |
Output is correct |
38 |
Correct |
11 ms |
9984 KB |
Output is correct |
39 |
Correct |
11 ms |
9984 KB |
Output is correct |
40 |
Correct |
11 ms |
9984 KB |
Output is correct |
41 |
Correct |
11 ms |
9984 KB |
Output is correct |
42 |
Correct |
11 ms |
9984 KB |
Output is correct |
43 |
Correct |
11 ms |
9984 KB |
Output is correct |
44 |
Correct |
11 ms |
9984 KB |
Output is correct |
45 |
Correct |
271 ms |
31480 KB |
Output is correct |
46 |
Correct |
264 ms |
31176 KB |
Output is correct |
47 |
Correct |
260 ms |
31096 KB |
Output is correct |
48 |
Correct |
253 ms |
31352 KB |
Output is correct |
49 |
Correct |
268 ms |
31096 KB |
Output is correct |
50 |
Correct |
261 ms |
30968 KB |
Output is correct |
51 |
Correct |
250 ms |
31096 KB |
Output is correct |
52 |
Correct |
263 ms |
31484 KB |
Output is correct |
53 |
Correct |
272 ms |
31232 KB |
Output is correct |
54 |
Correct |
219 ms |
33528 KB |
Output is correct |
55 |
Correct |
215 ms |
33144 KB |
Output is correct |
56 |
Correct |
207 ms |
33016 KB |
Output is correct |
57 |
Correct |
215 ms |
32888 KB |
Output is correct |
58 |
Correct |
180 ms |
28792 KB |
Output is correct |
59 |
Correct |
192 ms |
28792 KB |
Output is correct |
60 |
Correct |
157 ms |
33124 KB |
Output is correct |
61 |
Correct |
157 ms |
28524 KB |
Output is correct |
62 |
Correct |
203 ms |
30840 KB |
Output is correct |
63 |
Correct |
144 ms |
27448 KB |
Output is correct |
64 |
Correct |
142 ms |
28268 KB |
Output is correct |
65 |
Correct |
227 ms |
31084 KB |
Output is correct |
66 |
Correct |
144 ms |
27440 KB |
Output is correct |