Skip to content

Commit 5b18b89

Browse files
committed
AtCoder: ARC181
1 parent 5008c3f commit 5b18b89

File tree

4 files changed

+234
-0
lines changed

4 files changed

+234
-0
lines changed

AtCoder/arc181_a.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @file arc181_a.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2024-08-04
5+
*
6+
* @copyright Copyright (c) 2024
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
#define maxn 200005
20+
21+
int a[maxn];
22+
23+
void solve(void) {
24+
int n;
25+
cin >> n;
26+
for (int i = 1; i <= n; i++) cin >> a[i];
27+
28+
bool chk = true;
29+
for (int i = 1; i <= n; i++) chk &= (a[i] == i);
30+
if (chk) return cout << 0 << endl, void();
31+
32+
for (int i = 1, maxv = 0; i <= n; i++) {
33+
maxv = max(maxv, a[i - 1]);
34+
if (a[i] == i && maxv == i - 1) return cout << 1 << endl, void();
35+
}
36+
37+
if (a[1] != n || a[n] != 1) return cout << 2 << endl, void();
38+
39+
cout << 3 << endl;
40+
41+
return;
42+
}
43+
44+
bool mem2;
45+
46+
int main() {
47+
ios::sync_with_stdio(false), cin.tie(nullptr);
48+
#ifdef LOCAL
49+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
50+
#endif
51+
52+
int _ = 1;
53+
cin >> _;
54+
while (_--) solve();
55+
56+
#ifdef LOCAL
57+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
58+
#endif
59+
return 0;
60+
}

AtCoder/arc181_b.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @file arc181_b.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2024-08-04
5+
*
6+
* @copyright Copyright (c) 2024
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
bool solve(void) {
20+
string a, X, Y;
21+
cin >> a >> X >> Y;
22+
int64_t n = a.size(), cnt[2][2] = {{0, 0}, {0, 0}};
23+
for (char c : X) cnt[0][c - '0']++;
24+
for (char c : Y) cnt[1][c - '0']++;
25+
if ((cnt[0][0] > cnt[1][0] && cnt[0][1] > cnt[1][1]) || (cnt[0][0] < cnt[1][0] && cnt[0][1] < cnt[1][1])) return false;
26+
int64_t x = abs(cnt[0][0] - cnt[1][0]), y = abs(cnt[0][1] - cnt[1][1]);
27+
if (x == 0) return true;
28+
if (y == 0) return false;
29+
if (x * n % y) return false;
30+
int64_t m = x * n / y;
31+
int len = gcd(n, m);
32+
for (int i = 0; i + len < n; i++)
33+
if (a[i] != a[i + len]) return false;
34+
return true;
35+
}
36+
37+
bool mem2;
38+
39+
int main() {
40+
ios::sync_with_stdio(false), cin.tie(nullptr);
41+
#ifdef LOCAL
42+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
43+
#endif
44+
45+
int _ = 1;
46+
cin >> _;
47+
while (_--) cout << (solve() ? "Yes" : "No") << endl;
48+
49+
#ifdef LOCAL
50+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
51+
#endif
52+
return 0;
53+
}

AtCoder/arc181_c.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @file arc181_b.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2024-08-04
5+
*
6+
* @copyright Copyright (c) 2024
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
#define maxn 505
20+
21+
int p[maxn], q[maxn], a[maxn][maxn];
22+
23+
void solve(void) {
24+
int n;
25+
cin >> n;
26+
for (int i = 1; i <= n; i++) cin >> p[i];
27+
for (int i = 1; i <= n; i++) cin >> q[i];
28+
for (int i = 1; i <= n; i++)
29+
for (int j = n - i + 1; j <= n; j++) a[p[i]][q[j]] = 1;
30+
for (int i = 1; i <= n; i++) {
31+
for (int j = 1; j <= n; j++) cout << a[i][j];
32+
cout << endl;
33+
}
34+
return;
35+
}
36+
37+
bool mem2;
38+
39+
int main() {
40+
ios::sync_with_stdio(false), cin.tie(nullptr);
41+
#ifdef LOCAL
42+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
43+
#endif
44+
45+
int _ = 1;
46+
while (_--) solve();
47+
48+
#ifdef LOCAL
49+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
50+
#endif
51+
return 0;
52+
}

AtCoder/arc181_d.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @file arc181_b.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2024-08-04
5+
*
6+
* @copyright Copyright (c) 2024
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
#define maxn 200005
20+
21+
class FenwickTree {
22+
private:
23+
int tree[maxn];
24+
25+
public:
26+
void insert(int p) {
27+
for (int i = p; i < maxn; i += i & -i) tree[i]++;
28+
return;
29+
}
30+
int query(int p) {
31+
int sum = 0;
32+
for (int i = p; i; i -= i & -i) sum += tree[i];
33+
return sum;
34+
}
35+
} FT;
36+
37+
int a[maxn], p[maxn], pos[maxn], dt[maxn];
38+
39+
void solve(void) {
40+
int n, q;
41+
cin >> n;
42+
int64_t ans = 0;
43+
for (int i = 1; i <= n; i++) cin >> a[i], p[i] = i - 1 - FT.query(a[i]), FT.insert(a[i]), ans += p[i];
44+
cin >> q;
45+
for (int i = 1; i <= q; i++) cin >> pos[i];
46+
for (int i = 1, j = 1; i <= n; i++) {
47+
while (j <= q && pos[j] < i) j++;
48+
if (j <= q) dt[j]--, dt[min(q + 1, j + p[i])]++;
49+
}
50+
for (int i = 1; i <= q; i++) cout << (ans += (dt[i] += dt[i - 1])) << endl;
51+
return;
52+
}
53+
54+
bool mem2;
55+
56+
int main() {
57+
ios::sync_with_stdio(false), cin.tie(nullptr);
58+
#ifdef LOCAL
59+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
60+
#endif
61+
62+
int _ = 1;
63+
while (_--) solve();
64+
65+
#ifdef LOCAL
66+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
67+
#endif
68+
return 0;
69+
}

0 commit comments

Comments
 (0)