Skip to content

Commit

Permalink
AtCoder: ARC181
Browse files Browse the repository at this point in the history
  • Loading branch information
Macesuted committed Aug 5, 2024
1 parent 5008c3f commit 5b18b89
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 0 deletions.
60 changes: 60 additions & 0 deletions AtCoder/arc181_a.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @file arc181_a.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-08-04
*
* @copyright Copyright (c) 2024
*
*/

#include <bits/stdc++.h>
using namespace std;

#ifndef LOCAL
#define endl '\n'
#endif

bool mem1;

#define maxn 200005

int a[maxn];

void solve(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];

bool chk = true;
for (int i = 1; i <= n; i++) chk &= (a[i] == i);
if (chk) return cout << 0 << endl, void();

for (int i = 1, maxv = 0; i <= n; i++) {
maxv = max(maxv, a[i - 1]);
if (a[i] == i && maxv == i - 1) return cout << 1 << endl, void();
}

if (a[1] != n || a[n] != 1) return cout << 2 << endl, void();

cout << 3 << endl;

return;
}

bool mem2;

int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
#ifdef LOCAL
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
#endif

int _ = 1;
cin >> _;
while (_--) solve();

#ifdef LOCAL
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
#endif
return 0;
}
53 changes: 53 additions & 0 deletions AtCoder/arc181_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @file arc181_b.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-08-04
*
* @copyright Copyright (c) 2024
*
*/

#include <bits/stdc++.h>
using namespace std;

#ifndef LOCAL
#define endl '\n'
#endif

bool mem1;

bool solve(void) {
string a, X, Y;
cin >> a >> X >> Y;
int64_t n = a.size(), cnt[2][2] = {{0, 0}, {0, 0}};
for (char c : X) cnt[0][c - '0']++;
for (char c : Y) cnt[1][c - '0']++;
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;
int64_t x = abs(cnt[0][0] - cnt[1][0]), y = abs(cnt[0][1] - cnt[1][1]);
if (x == 0) return true;
if (y == 0) return false;
if (x * n % y) return false;
int64_t m = x * n / y;
int len = gcd(n, m);
for (int i = 0; i + len < n; i++)
if (a[i] != a[i + len]) return false;
return true;
}

bool mem2;

int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
#ifdef LOCAL
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
#endif

int _ = 1;
cin >> _;
while (_--) cout << (solve() ? "Yes" : "No") << endl;

#ifdef LOCAL
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
#endif
return 0;
}
52 changes: 52 additions & 0 deletions AtCoder/arc181_c.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @file arc181_b.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-08-04
*
* @copyright Copyright (c) 2024
*
*/

#include <bits/stdc++.h>
using namespace std;

#ifndef LOCAL
#define endl '\n'
#endif

bool mem1;

#define maxn 505

int p[maxn], q[maxn], a[maxn][maxn];

void solve(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> p[i];
for (int i = 1; i <= n; i++) cin >> q[i];
for (int i = 1; i <= n; i++)
for (int j = n - i + 1; j <= n; j++) a[p[i]][q[j]] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) cout << a[i][j];
cout << endl;
}
return;
}

bool mem2;

int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
#ifdef LOCAL
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
#endif

int _ = 1;
while (_--) solve();

#ifdef LOCAL
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
#endif
return 0;
}
69 changes: 69 additions & 0 deletions AtCoder/arc181_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @file arc181_b.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-08-04
*
* @copyright Copyright (c) 2024
*
*/

#include <bits/stdc++.h>
using namespace std;

#ifndef LOCAL
#define endl '\n'
#endif

bool mem1;

#define maxn 200005

class FenwickTree {
private:
int tree[maxn];

public:
void insert(int p) {
for (int i = p; i < maxn; i += i & -i) tree[i]++;
return;
}
int query(int p) {
int sum = 0;
for (int i = p; i; i -= i & -i) sum += tree[i];
return sum;
}
} FT;

int a[maxn], p[maxn], pos[maxn], dt[maxn];

void solve(void) {
int n, q;
cin >> n;
int64_t ans = 0;
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];
cin >> q;
for (int i = 1; i <= q; i++) cin >> pos[i];
for (int i = 1, j = 1; i <= n; i++) {
while (j <= q && pos[j] < i) j++;
if (j <= q) dt[j]--, dt[min(q + 1, j + p[i])]++;
}
for (int i = 1; i <= q; i++) cout << (ans += (dt[i] += dt[i - 1])) << endl;
return;
}

bool mem2;

int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
#ifdef LOCAL
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
#endif

int _ = 1;
while (_--) solve();

#ifdef LOCAL
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
#endif
return 0;
}

0 comments on commit 5b18b89

Please sign in to comment.