# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
758195 |
2023-06-14T09:02:38 Z |
PixelCat |
Rope (JOI17_rope) |
C++14 |
|
2314 ms |
202200 KB |
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
#define INF (int)(1e18)
using namespace std;
using LL = long long;
using pii = pair<int, int>;
void chmin(int &x, int a) {
x = min(x, a);
}
void chmax(int &x, int a) {
x = max(x, a);
}
#ifdef NYAOWO
int64_t LAST_TIMER = -1;
inline void timer() {
auto now = clock();
if (LAST_TIMER != -1) {
cerr << "Elapsed: "
<< (double)(now - LAST_TIMER) / CLOCKS_PER_SEC << " s\n";
} else {
cerr << fixed << setprecision(3);
}
LAST_TIMER = now;
}
#else
#define timer()
#endif
const int MAXN = 1000010;
int ans[MAXN];
int cnt1[MAXN];
int owo[MAXN];
struct Ayaya {
priority_queue<int, vector<int>, greater<int>> pq, gg;
Ayaya(int n) {
memset(owo, 0, sizeof(owo));
For(i, 1, n) pq.emplace(0);
}
void add(int i, int x) {
gg.emplace(owo[i]);
owo[i] += x;
pq.emplace(owo[i]);
}
int min() {
while(sz(gg) && pq.top() == gg.top()) {
pq.pop(); gg.pop();
}
return pq.top();
}
};
vector<int> vv[MAXN];
void solve(int n, int m, vector<pii> v2, vector<int> v1) {
timer();
memset(cnt1, 0, sizeof(cnt1));
For(i, 1, m) vv[i].clear();
Ayaya aya(m);
timer();
for(auto &i:v2) {
cnt1[i.F]++;
cnt1[i.S]++;
vv[i.F].eb(i.S);
vv[i.S].eb(i.F);
}
For(c2, 1, m) aya.add(c2, n - cnt1[c2]);
timer();
For(c1, 1, m) {
int add = 0;
for(auto &p:vv[c1]) aya.add(p, 1);
for(auto &i:v1) {
aya.add(i, -1);
add -= (i == c1);
}
aya.add(c1, INF);
chmin(ans[c1], aya.min() - cnt1[c1] + add);
aya.add(c1, -INF);
for(auto &i:v1) aya.add(i, 1);
for(auto &p:vv[c1]) aya.add(p, -1);
chmin(ans[c1], n - cnt1[c1] + add);
}
timer();
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
// =^-w-^=
int n, m; cin >> n >> m;
vector<int> a(n);
for(auto &i:a) cin >> i;
For(i, 1, m) {
ans[i] = INF;
}
if(n % 2) {
For(_, 0, 1) {
vector<pii> v2;
for(int i = 1; i < n; i += 2) {
v2.eb(pii(a[i - 1], a[i]));
}
solve(n, m, v2, { a.back() });
reverse(all(a));
}
} else {
vector<pii> v2;
for(int i = 1; i < n; i += 2) {
v2.eb(pii(a[i - 1], a[i]));
}
solve(n, m, v2, {});
v2.clear();
for(int i = 2; i < n; i += 2) {
v2.eb(pii(a[i - 1], a[i]));
}
solve(n, m, v2, { a.front(), a.back() });
}
For(i, 1, m) cout << ans[i] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
39380 KB |
Output is correct |
2 |
Correct |
21 ms |
39392 KB |
Output is correct |
3 |
Correct |
22 ms |
39380 KB |
Output is correct |
4 |
Correct |
22 ms |
39516 KB |
Output is correct |
5 |
Correct |
21 ms |
39380 KB |
Output is correct |
6 |
Correct |
22 ms |
39348 KB |
Output is correct |
7 |
Correct |
21 ms |
39372 KB |
Output is correct |
8 |
Correct |
23 ms |
39396 KB |
Output is correct |
9 |
Correct |
23 ms |
39400 KB |
Output is correct |
10 |
Correct |
21 ms |
39424 KB |
Output is correct |
11 |
Correct |
21 ms |
39432 KB |
Output is correct |
12 |
Correct |
21 ms |
39468 KB |
Output is correct |
13 |
Correct |
22 ms |
39380 KB |
Output is correct |
14 |
Correct |
21 ms |
39380 KB |
Output is correct |
15 |
Correct |
23 ms |
39436 KB |
Output is correct |
16 |
Correct |
21 ms |
39372 KB |
Output is correct |
17 |
Correct |
22 ms |
39380 KB |
Output is correct |
18 |
Correct |
21 ms |
39452 KB |
Output is correct |
19 |
Correct |
21 ms |
39400 KB |
Output is correct |
20 |
Correct |
20 ms |
39464 KB |
Output is correct |
21 |
Correct |
21 ms |
39376 KB |
Output is correct |
22 |
Correct |
22 ms |
39356 KB |
Output is correct |
23 |
Correct |
20 ms |
39404 KB |
Output is correct |
24 |
Correct |
21 ms |
39456 KB |
Output is correct |
25 |
Correct |
23 ms |
39464 KB |
Output is correct |
26 |
Correct |
21 ms |
39380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
39380 KB |
Output is correct |
2 |
Correct |
21 ms |
39392 KB |
Output is correct |
3 |
Correct |
22 ms |
39380 KB |
Output is correct |
4 |
Correct |
22 ms |
39516 KB |
Output is correct |
5 |
Correct |
21 ms |
39380 KB |
Output is correct |
6 |
Correct |
22 ms |
39348 KB |
Output is correct |
7 |
Correct |
21 ms |
39372 KB |
Output is correct |
8 |
Correct |
23 ms |
39396 KB |
Output is correct |
9 |
Correct |
23 ms |
39400 KB |
Output is correct |
10 |
Correct |
21 ms |
39424 KB |
Output is correct |
11 |
Correct |
21 ms |
39432 KB |
Output is correct |
12 |
Correct |
21 ms |
39468 KB |
Output is correct |
13 |
Correct |
22 ms |
39380 KB |
Output is correct |
14 |
Correct |
21 ms |
39380 KB |
Output is correct |
15 |
Correct |
23 ms |
39436 KB |
Output is correct |
16 |
Correct |
21 ms |
39372 KB |
Output is correct |
17 |
Correct |
22 ms |
39380 KB |
Output is correct |
18 |
Correct |
21 ms |
39452 KB |
Output is correct |
19 |
Correct |
21 ms |
39400 KB |
Output is correct |
20 |
Correct |
20 ms |
39464 KB |
Output is correct |
21 |
Correct |
21 ms |
39376 KB |
Output is correct |
22 |
Correct |
22 ms |
39356 KB |
Output is correct |
23 |
Correct |
20 ms |
39404 KB |
Output is correct |
24 |
Correct |
21 ms |
39456 KB |
Output is correct |
25 |
Correct |
23 ms |
39464 KB |
Output is correct |
26 |
Correct |
21 ms |
39380 KB |
Output is correct |
27 |
Correct |
105 ms |
44056 KB |
Output is correct |
28 |
Correct |
104 ms |
44444 KB |
Output is correct |
29 |
Correct |
107 ms |
44396 KB |
Output is correct |
30 |
Correct |
103 ms |
44312 KB |
Output is correct |
31 |
Correct |
112 ms |
44236 KB |
Output is correct |
32 |
Correct |
104 ms |
44432 KB |
Output is correct |
33 |
Correct |
102 ms |
44176 KB |
Output is correct |
34 |
Correct |
103 ms |
44272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
39380 KB |
Output is correct |
2 |
Correct |
21 ms |
39392 KB |
Output is correct |
3 |
Correct |
22 ms |
39380 KB |
Output is correct |
4 |
Correct |
22 ms |
39516 KB |
Output is correct |
5 |
Correct |
21 ms |
39380 KB |
Output is correct |
6 |
Correct |
22 ms |
39348 KB |
Output is correct |
7 |
Correct |
21 ms |
39372 KB |
Output is correct |
8 |
Correct |
23 ms |
39396 KB |
Output is correct |
9 |
Correct |
23 ms |
39400 KB |
Output is correct |
10 |
Correct |
21 ms |
39424 KB |
Output is correct |
11 |
Correct |
21 ms |
39432 KB |
Output is correct |
12 |
Correct |
21 ms |
39468 KB |
Output is correct |
13 |
Correct |
22 ms |
39380 KB |
Output is correct |
14 |
Correct |
21 ms |
39380 KB |
Output is correct |
15 |
Correct |
23 ms |
39436 KB |
Output is correct |
16 |
Correct |
21 ms |
39372 KB |
Output is correct |
17 |
Correct |
22 ms |
39380 KB |
Output is correct |
18 |
Correct |
21 ms |
39452 KB |
Output is correct |
19 |
Correct |
21 ms |
39400 KB |
Output is correct |
20 |
Correct |
20 ms |
39464 KB |
Output is correct |
21 |
Correct |
21 ms |
39376 KB |
Output is correct |
22 |
Correct |
22 ms |
39356 KB |
Output is correct |
23 |
Correct |
20 ms |
39404 KB |
Output is correct |
24 |
Correct |
21 ms |
39456 KB |
Output is correct |
25 |
Correct |
23 ms |
39464 KB |
Output is correct |
26 |
Correct |
21 ms |
39380 KB |
Output is correct |
27 |
Correct |
105 ms |
44056 KB |
Output is correct |
28 |
Correct |
104 ms |
44444 KB |
Output is correct |
29 |
Correct |
107 ms |
44396 KB |
Output is correct |
30 |
Correct |
103 ms |
44312 KB |
Output is correct |
31 |
Correct |
112 ms |
44236 KB |
Output is correct |
32 |
Correct |
104 ms |
44432 KB |
Output is correct |
33 |
Correct |
102 ms |
44176 KB |
Output is correct |
34 |
Correct |
103 ms |
44272 KB |
Output is correct |
35 |
Correct |
50 ms |
48004 KB |
Output is correct |
36 |
Correct |
49 ms |
47904 KB |
Output is correct |
37 |
Correct |
54 ms |
48952 KB |
Output is correct |
38 |
Correct |
50 ms |
49024 KB |
Output is correct |
39 |
Correct |
50 ms |
48976 KB |
Output is correct |
40 |
Correct |
77 ms |
45604 KB |
Output is correct |
41 |
Correct |
81 ms |
45584 KB |
Output is correct |
42 |
Correct |
79 ms |
44208 KB |
Output is correct |
43 |
Correct |
76 ms |
44508 KB |
Output is correct |
44 |
Correct |
62 ms |
47472 KB |
Output is correct |
45 |
Correct |
64 ms |
47564 KB |
Output is correct |
46 |
Correct |
69 ms |
46340 KB |
Output is correct |
47 |
Correct |
66 ms |
46476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
39380 KB |
Output is correct |
2 |
Correct |
21 ms |
39392 KB |
Output is correct |
3 |
Correct |
22 ms |
39380 KB |
Output is correct |
4 |
Correct |
22 ms |
39516 KB |
Output is correct |
5 |
Correct |
21 ms |
39380 KB |
Output is correct |
6 |
Correct |
22 ms |
39348 KB |
Output is correct |
7 |
Correct |
21 ms |
39372 KB |
Output is correct |
8 |
Correct |
23 ms |
39396 KB |
Output is correct |
9 |
Correct |
23 ms |
39400 KB |
Output is correct |
10 |
Correct |
21 ms |
39424 KB |
Output is correct |
11 |
Correct |
21 ms |
39432 KB |
Output is correct |
12 |
Correct |
21 ms |
39468 KB |
Output is correct |
13 |
Correct |
22 ms |
39380 KB |
Output is correct |
14 |
Correct |
21 ms |
39380 KB |
Output is correct |
15 |
Correct |
23 ms |
39436 KB |
Output is correct |
16 |
Correct |
21 ms |
39372 KB |
Output is correct |
17 |
Correct |
22 ms |
39380 KB |
Output is correct |
18 |
Correct |
21 ms |
39452 KB |
Output is correct |
19 |
Correct |
21 ms |
39400 KB |
Output is correct |
20 |
Correct |
20 ms |
39464 KB |
Output is correct |
21 |
Correct |
21 ms |
39376 KB |
Output is correct |
22 |
Correct |
22 ms |
39356 KB |
Output is correct |
23 |
Correct |
20 ms |
39404 KB |
Output is correct |
24 |
Correct |
21 ms |
39456 KB |
Output is correct |
25 |
Correct |
23 ms |
39464 KB |
Output is correct |
26 |
Correct |
21 ms |
39380 KB |
Output is correct |
27 |
Correct |
105 ms |
44056 KB |
Output is correct |
28 |
Correct |
104 ms |
44444 KB |
Output is correct |
29 |
Correct |
107 ms |
44396 KB |
Output is correct |
30 |
Correct |
103 ms |
44312 KB |
Output is correct |
31 |
Correct |
112 ms |
44236 KB |
Output is correct |
32 |
Correct |
104 ms |
44432 KB |
Output is correct |
33 |
Correct |
102 ms |
44176 KB |
Output is correct |
34 |
Correct |
103 ms |
44272 KB |
Output is correct |
35 |
Correct |
50 ms |
48004 KB |
Output is correct |
36 |
Correct |
49 ms |
47904 KB |
Output is correct |
37 |
Correct |
54 ms |
48952 KB |
Output is correct |
38 |
Correct |
50 ms |
49024 KB |
Output is correct |
39 |
Correct |
50 ms |
48976 KB |
Output is correct |
40 |
Correct |
77 ms |
45604 KB |
Output is correct |
41 |
Correct |
81 ms |
45584 KB |
Output is correct |
42 |
Correct |
79 ms |
44208 KB |
Output is correct |
43 |
Correct |
76 ms |
44508 KB |
Output is correct |
44 |
Correct |
62 ms |
47472 KB |
Output is correct |
45 |
Correct |
64 ms |
47564 KB |
Output is correct |
46 |
Correct |
69 ms |
46340 KB |
Output is correct |
47 |
Correct |
66 ms |
46476 KB |
Output is correct |
48 |
Correct |
315 ms |
119448 KB |
Output is correct |
49 |
Correct |
319 ms |
119364 KB |
Output is correct |
50 |
Correct |
317 ms |
129884 KB |
Output is correct |
51 |
Correct |
299 ms |
121212 KB |
Output is correct |
52 |
Correct |
289 ms |
118804 KB |
Output is correct |
53 |
Correct |
580 ms |
97136 KB |
Output is correct |
54 |
Correct |
633 ms |
82164 KB |
Output is correct |
55 |
Correct |
643 ms |
81560 KB |
Output is correct |
56 |
Correct |
671 ms |
76776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
39380 KB |
Output is correct |
2 |
Correct |
21 ms |
39392 KB |
Output is correct |
3 |
Correct |
22 ms |
39380 KB |
Output is correct |
4 |
Correct |
22 ms |
39516 KB |
Output is correct |
5 |
Correct |
21 ms |
39380 KB |
Output is correct |
6 |
Correct |
22 ms |
39348 KB |
Output is correct |
7 |
Correct |
21 ms |
39372 KB |
Output is correct |
8 |
Correct |
23 ms |
39396 KB |
Output is correct |
9 |
Correct |
23 ms |
39400 KB |
Output is correct |
10 |
Correct |
21 ms |
39424 KB |
Output is correct |
11 |
Correct |
21 ms |
39432 KB |
Output is correct |
12 |
Correct |
21 ms |
39468 KB |
Output is correct |
13 |
Correct |
22 ms |
39380 KB |
Output is correct |
14 |
Correct |
21 ms |
39380 KB |
Output is correct |
15 |
Correct |
23 ms |
39436 KB |
Output is correct |
16 |
Correct |
21 ms |
39372 KB |
Output is correct |
17 |
Correct |
22 ms |
39380 KB |
Output is correct |
18 |
Correct |
21 ms |
39452 KB |
Output is correct |
19 |
Correct |
21 ms |
39400 KB |
Output is correct |
20 |
Correct |
20 ms |
39464 KB |
Output is correct |
21 |
Correct |
21 ms |
39376 KB |
Output is correct |
22 |
Correct |
22 ms |
39356 KB |
Output is correct |
23 |
Correct |
20 ms |
39404 KB |
Output is correct |
24 |
Correct |
21 ms |
39456 KB |
Output is correct |
25 |
Correct |
23 ms |
39464 KB |
Output is correct |
26 |
Correct |
21 ms |
39380 KB |
Output is correct |
27 |
Correct |
105 ms |
44056 KB |
Output is correct |
28 |
Correct |
104 ms |
44444 KB |
Output is correct |
29 |
Correct |
107 ms |
44396 KB |
Output is correct |
30 |
Correct |
103 ms |
44312 KB |
Output is correct |
31 |
Correct |
112 ms |
44236 KB |
Output is correct |
32 |
Correct |
104 ms |
44432 KB |
Output is correct |
33 |
Correct |
102 ms |
44176 KB |
Output is correct |
34 |
Correct |
103 ms |
44272 KB |
Output is correct |
35 |
Correct |
50 ms |
48004 KB |
Output is correct |
36 |
Correct |
49 ms |
47904 KB |
Output is correct |
37 |
Correct |
54 ms |
48952 KB |
Output is correct |
38 |
Correct |
50 ms |
49024 KB |
Output is correct |
39 |
Correct |
50 ms |
48976 KB |
Output is correct |
40 |
Correct |
77 ms |
45604 KB |
Output is correct |
41 |
Correct |
81 ms |
45584 KB |
Output is correct |
42 |
Correct |
79 ms |
44208 KB |
Output is correct |
43 |
Correct |
76 ms |
44508 KB |
Output is correct |
44 |
Correct |
62 ms |
47472 KB |
Output is correct |
45 |
Correct |
64 ms |
47564 KB |
Output is correct |
46 |
Correct |
69 ms |
46340 KB |
Output is correct |
47 |
Correct |
66 ms |
46476 KB |
Output is correct |
48 |
Correct |
315 ms |
119448 KB |
Output is correct |
49 |
Correct |
319 ms |
119364 KB |
Output is correct |
50 |
Correct |
317 ms |
129884 KB |
Output is correct |
51 |
Correct |
299 ms |
121212 KB |
Output is correct |
52 |
Correct |
289 ms |
118804 KB |
Output is correct |
53 |
Correct |
580 ms |
97136 KB |
Output is correct |
54 |
Correct |
633 ms |
82164 KB |
Output is correct |
55 |
Correct |
643 ms |
81560 KB |
Output is correct |
56 |
Correct |
671 ms |
76776 KB |
Output is correct |
57 |
Correct |
2314 ms |
192796 KB |
Output is correct |
58 |
Correct |
1219 ms |
198044 KB |
Output is correct |
59 |
Correct |
1255 ms |
197760 KB |
Output is correct |
60 |
Correct |
1319 ms |
201964 KB |
Output is correct |
61 |
Correct |
1283 ms |
202200 KB |
Output is correct |
62 |
Correct |
1037 ms |
160748 KB |
Output is correct |
63 |
Correct |
1190 ms |
174972 KB |
Output is correct |
64 |
Correct |
1113 ms |
167928 KB |
Output is correct |
65 |
Correct |
844 ms |
119732 KB |
Output is correct |