-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
1,196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// @check-accepted: examples Nsmall Nmedium Nlarge | ||
#include <iostream> | ||
#include <vector> | ||
using namespace std; | ||
|
||
int main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(0); | ||
int n; | ||
cin >> n; | ||
string s; | ||
cin >> s; | ||
int bal = 0, mn = 0; | ||
for (char c : s) { | ||
bal += c == '(' ? 1 : -1; | ||
mn = min(mn, bal); | ||
} | ||
vector<pair<int, int>> ans; | ||
int l = 0, r = n - 1; | ||
while (mn < 0) { | ||
while (s[l] == '(') l++; | ||
while (s[r] == ')') r--; | ||
ans.push_back({l, r}); | ||
swap(s[l], s[r]); | ||
mn += 2; | ||
} | ||
cout << ans.size() << "\n"; | ||
for (auto& [l, r] : ans) { | ||
cout << l << " " << r << "\n"; | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python3 | ||
# @check-accepted: examples Nsmall Nmedium Nlarge | ||
|
||
input() | ||
s = list(input().strip()) | ||
|
||
mn, sum = 0, 0 | ||
for i in s: | ||
sum += 1 if i == '(' else -1 | ||
mn = min(mn, sum) | ||
|
||
ans = [] | ||
|
||
l, r = 0, len(s)-1 | ||
while l<r and mn < 0: | ||
if s[l]=='(': | ||
l += 1 | ||
elif s[r]==')': | ||
r -= 1 | ||
else: | ||
assert s[l]==')' and s[r]=='(' | ||
ans.append((l, r)) | ||
s[l], s[r] = s[r], s[l] | ||
mn+=2 | ||
|
||
print(len(ans)) | ||
print(*[f"{x[0]} {x[1]}" for x in ans], sep='\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// @check-accepted: examples quadratic X=Y no-limits | ||
#include <algorithm> | ||
#include <iostream> | ||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
#define int long long | ||
using namespace std; | ||
int N; | ||
string A, B; | ||
constexpr int mod = 1e9 + 7; | ||
constexpr int base1 = 2; | ||
constexpr int base2 = 7; | ||
vector<int> p1; | ||
vector<int> p2; | ||
struct Hash { | ||
vector<int> h1; | ||
vector<int> h2; | ||
Hash(const string& s) { | ||
int n = s.size(); | ||
h1.resize(n + 1); | ||
h2.resize(n + 1); | ||
for (int i = 0; i < n; ++i) { | ||
h1[i + 1] = (h1[i] * base1 + s[i] - '0') % mod; | ||
h2[i + 1] = (h2[i] * base2 + s[i] - '0') % mod; | ||
} | ||
} | ||
pair<int, int> get(int l, int r) { | ||
return {(h1[r + 1] - h1[l] * p1[r - l + 1] % mod + mod) % mod, (h2[r + 1] - h2[l] * p2[r - l + 1] % mod + mod) % mod}; | ||
} | ||
}; | ||
signed main() { | ||
ios_base::sync_with_stdio(0); | ||
cin.tie(0); | ||
cin >> N; | ||
p1.resize(N + 1); | ||
p1[0] = 1; | ||
for (int i = 1; i <= N; ++i) { | ||
p1[i] = p1[i - 1] * base1 % mod; | ||
} | ||
p2.resize(N + 1); | ||
p2[0] = 1; | ||
for (int i = 1; i <= N; ++i) { | ||
p2[i] = p2[i - 1] * base2 % mod; | ||
} | ||
cin >> A; | ||
cin >> B; | ||
for (int i = 0; i < N; ++i) { | ||
B[i] = 1 - (B[i] - '0') + '0'; | ||
} | ||
Hash ha(A), hb(B); | ||
|
||
int Q; | ||
cin >> Q; | ||
|
||
for (int i = 0; i < Q; ++i) { | ||
int X, Y, L; | ||
cin >> X >> Y >> L; | ||
|
||
int l = 0, r = L; | ||
while (l < r) { | ||
int m = (l + r) / 2; | ||
if (ha.get(X, X + m) == hb.get(Y, Y + m)) { | ||
l = m + 1; | ||
} else { | ||
r = m; | ||
} | ||
} | ||
if (l == L) { | ||
cout << 1 << " "; | ||
} else { | ||
cout << B[Y + l] << " "; | ||
} | ||
} | ||
cout << '\n'; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
# @check-accepted: examples quadratic | ||
# @check-time-limit-exceeded: X=Y no-limits | ||
|
||
# Constants | ||
MOD = 10**9 + 7 | ||
BASE = 2 | ||
|
||
n = int(input().strip()) | ||
|
||
# Precompute powers | ||
p = [1] | ||
for i in range(1, n + 1): | ||
p.append(p[i - 1] * BASE % MOD) | ||
|
||
A = input().strip() | ||
B = input().strip() | ||
|
||
# Invert bits of B | ||
B = ''.join(['1' if b == '0' else '0' for b in B]) | ||
|
||
# Hash functions | ||
|
||
|
||
def get_hash(s): | ||
n = len(s) | ||
h = [0] * (n + 1) | ||
for i in range(n): | ||
h[i + 1] = (h[i] * BASE + ord(s[i]) - ord('0')) % MOD | ||
return h | ||
|
||
|
||
ha = get_hash(A) | ||
hb = get_hash(B) | ||
|
||
q = int(input().strip()) | ||
result = [] | ||
|
||
for _ in range(q): | ||
X, Y, L = map(int, input().split()) | ||
l, r = 0, L | ||
while l < r: | ||
m = (l + r) // 2 | ||
if (ha[X + m + 1] - ha[X] * p[m + 1]) % MOD == (hb[Y + m + 1] - hb[Y] * p[m + 1] ) % MOD: | ||
l = m + 1 | ||
else: | ||
r = m | ||
if l == L: | ||
result.append("1") | ||
else: | ||
result.append(B[Y + l]) | ||
|
||
print(' '.join(result)) |
Oops, something went wrong.