-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 feat: initial commit for gplt L3-016-020
- Loading branch information
Showing
4 changed files
with
250 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
struct node { | ||
int num, lchild, rchild, parent, level; | ||
node() { | ||
lchild = rchild = parent = -1; | ||
} | ||
}Tree[128]; | ||
int n, m, a, b, in, cnt, root = 1, f; | ||
map<int, int> Find; | ||
string t; | ||
void insert(int x) { | ||
int now = root; | ||
while(Tree[now].num != x) { | ||
if (x < Tree[now].num) { | ||
if (Tree[now].lchild == -1) { | ||
Tree[cnt].num = x; | ||
Tree[cnt].level = Tree[now].level + 1; | ||
Tree[cnt].parent = now; | ||
Tree[now].lchild = cnt; | ||
} | ||
now = Tree[now].lchild; | ||
} else { | ||
if (Tree[now].rchild == -1) { | ||
Tree[cnt].num = x; | ||
Tree[cnt].level = Tree[now].level + 1; | ||
Tree[cnt].parent = now; | ||
Tree[now].rchild = cnt; | ||
} | ||
now = Tree[now].rchild; | ||
} | ||
} | ||
} | ||
int main() { | ||
cin >> n >> in; | ||
Tree[++cnt].num = in; | ||
Find[in] = cnt; | ||
for (int i = 1; i < n; i++) { | ||
cin >> in; | ||
Find[in] = ++cnt; | ||
insert(in); | ||
} | ||
cin >> m; | ||
while (m--) { | ||
f = 0; | ||
cin >> a >> t; | ||
if (t == "is") { | ||
cin >> t >> t; | ||
if (t == "root") { | ||
if (Find[a] == root) f = 1; | ||
} else if (t == "parent") { | ||
cin >> t >> b; | ||
if (Tree[Find[b]].parent == Find[a]) f = 1; | ||
} else if (t == "left") { | ||
cin >> t >> t >> b; | ||
if (Tree[Find[b]].lchild == Find[a]) f = 1; | ||
} else { | ||
cin >> t >> t >> b; | ||
if (Tree[Find[b]].rchild == Find[a]) f = 1; | ||
} | ||
} else { | ||
cin >> b >> t >> t; | ||
if (t == "siblings") { | ||
if (Find[a] && Find[b] && Tree[Find[a]].parent == Tree[Find[b]].parent) f = 1; | ||
} else { | ||
cin >> t >> t >> t; | ||
if (Find[a] && Find[b] && Tree[Find[a]].level == Tree[Find[b]].level) f = 1; | ||
} | ||
} | ||
cout << (f ? "Yes" : "No") << '\n'; | ||
} | ||
return 0; | ||
} |
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,71 @@ | ||
#include <bits/stdc++.h> | ||
#define Lx(a) (a << 1) + 1 | ||
#define Rx(a) (a << 1) + 2 | ||
using namespace std; | ||
int n, m, Size; | ||
long long ans, temp; | ||
pair<int, int> B[100000]; | ||
struct segtree { | ||
vector<long long> values, mins; | ||
void init(int n) { | ||
Size = 1; | ||
while (Size < n) Size *= 2; | ||
values.assign(2 * Size, 0LL); | ||
mins.assign(2 * Size, 0LL); | ||
build(0, 0, Size, n); | ||
} | ||
void build(int x, int lx, int rx, int R) { | ||
if (rx - lx == 1) { | ||
if (lx < R) { | ||
cin >> mins[x]; | ||
values[x] = mins[x]; | ||
} | ||
return; | ||
} | ||
int mid = lx + rx >> 1; | ||
build(Lx(x), lx, mid, R); | ||
build(Rx(x), mid, rx, R); | ||
mins[x] = min(mins[Lx(x)], mins[Rx(x)]) + values[x]; | ||
} | ||
void modify(int l, int r, int v, int x, int lx, int rx) { | ||
if (lx >= r || rx <= l) return; | ||
if (lx >= l && rx <= r) { | ||
mins[x] += v; | ||
values[x] += v; | ||
return; | ||
} | ||
int mid = lx + rx >> 1; | ||
modify(l, r, v, Lx(x), lx, mid); | ||
modify(l, r, v, Rx(x), mid, rx); | ||
mins[x] = min(mins[Lx(x)], mins[Rx(x)]) + values[x]; | ||
return; | ||
} | ||
long long get_min(int l, int r, int x, int lx, int rx) { | ||
if (lx >= r || rx <= l) return LLONG_MAX; | ||
if (lx >= l && rx <= r) return mins[x]; | ||
int mid = lx + rx >> 1; | ||
long long s1 = get_min(l, r, Lx(x), lx, mid); | ||
long long s2 = get_min(l, r, Rx(x), mid, rx); | ||
return min(s1, s2) + values[x]; | ||
} | ||
}st; | ||
bool cmp (const pair<int, int> &a, const pair<int, int> &b) { | ||
if (a.second != b.second) return a.second < b.second; | ||
return a.first < b.first; | ||
} | ||
int main() { | ||
cin >> n >> m; | ||
st.init(--n); | ||
for (int i = 0; i < m; i++) { | ||
cin >> B[i].first >> B[i].second; | ||
if (B[i].first > B[i].second) swap(B[i].first, B[i].second); | ||
} | ||
sort(B, B + m, cmp); | ||
for (int i = 0; i < m; i++) { | ||
temp = st.get_min(B[i].first, B[i].second, 0, 0, Size); | ||
ans += temp; | ||
st.modify(B[i].first, B[i].second, -temp, 0, 0, Size); | ||
} | ||
cout << ans; | ||
return 0; | ||
} |
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,88 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
int point, space = 2, mark, tp, cnt, use, temp; | ||
string s; | ||
int Function(int c) { | ||
if (c == 0) while (s[point] == ' ') point++; | ||
else if (c == 1) for (int i = 0; i < space; i++) cout << ' '; | ||
else if (c == 2) { | ||
if (s.substr(point, 2) == "if" && (s[point + 2] == '(' || s[point + 2] == ' ')) return 2; | ||
else if (s.substr(point, 3) == "for" && (s[point + 3] == '(' || s[point + 3] == ' ')) return 3; | ||
else if (s.substr(point, 4) == "else" && (s[point + 4] == '(' || s[point + 4] == ' ')) return 4; | ||
else if (s.substr(point, 5) == "while" && (s[point + 5] == '(' || s[point + 5] == ' ')) return 5; | ||
} else if (c == 3) { | ||
Function(0); | ||
if (Function(2) == 4) return 0; | ||
while (mark) { | ||
space -= 2; | ||
Function(1); | ||
cout << "}\n"; | ||
mark--; | ||
} | ||
} | ||
return 0; | ||
} | ||
int main() { | ||
getline(cin, s); | ||
Function(0); | ||
for (int i = point; s[i] != ')'; i++) cout << s[i]; | ||
cout << ")\n{\n"; | ||
point = s.find('{') + 1; | ||
while (1) { | ||
Function(0); | ||
temp = Function(2); | ||
if (s[point] == '{') { | ||
Function(1); | ||
cout << "{\n"; | ||
space += 2; | ||
point++; | ||
} else if (s[point] == '}') { | ||
space -= 2; | ||
Function(1); | ||
cout << "}\n"; | ||
if (space == 0) return 0; | ||
Function(3); | ||
point++; | ||
} else if (temp) { | ||
Function(1); | ||
cout << s.substr(point, temp); | ||
point += temp; | ||
if (temp != 4) { | ||
Function(0); | ||
tp = point; | ||
cnt = 0; | ||
while(tp < s.size()) { | ||
if (s[tp] == '(') cnt++; | ||
else if (s[tp] == ')') cnt--; | ||
tp++; | ||
if (cnt == 0) break; | ||
} | ||
cout << ' ' << s.substr(point, tp - point); | ||
point = tp; | ||
} | ||
cout << " {\n"; | ||
space += 2; | ||
Function(0); | ||
if (s[point] != '{') { | ||
use = 1; | ||
mark++; | ||
} else { | ||
use = 0; | ||
point++; | ||
} | ||
} else { | ||
Function(1); | ||
cnt = s.find(';', point); | ||
cout << s.substr(point, cnt - point + 1) << '\n'; | ||
point = cnt + 1; | ||
if (use && mark) { | ||
space -= 2; | ||
Function(1); | ||
cout << "}\n"; | ||
mark--; | ||
Function(3); | ||
} | ||
} | ||
} | ||
return 0; | ||
} |
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,18 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
string s; | ||
long long dp[1000001][4], vis[128], last; | ||
int main() { | ||
cin >> s; | ||
for (int i = 0; i <= s.size(); i++) dp[i][0] = 1; | ||
for (int i = 1; i <= s.size(); i++) { | ||
last = vis[s[i - 1]]; | ||
vis[s[i - 1]] = i; | ||
for (int j = 1; j <= 3; j++) { | ||
dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1]; | ||
if (last && j - (i - last) >= 0) dp[i][j] -= dp[last - 1][j - (i - last)]; | ||
} | ||
} | ||
cout << dp[s.size()][0] + dp[s.size()][1] + dp[s.size()][2] + dp[s.size()][3]; | ||
return 0; | ||
} |