Skip to content

Commit 15e9e02

Browse files
author
QuickSorting
committed
First commit
1 parent 3b1302a commit 15e9e02

File tree

632 files changed

+28927
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

632 files changed

+28927
-0
lines changed

Codeforces Global Round 10/A.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main(){
6+
ios::sync_with_stdio(false);
7+
cin.tie(NULL);
8+
9+
int t;
10+
cin >> t;
11+
12+
while(t--){
13+
int n;
14+
cin >> n;
15+
16+
vector<int> a(n);
17+
for(int i = 0; i < n; ++i)
18+
cin >> a[i];
19+
20+
bool ok = true;
21+
for(int i = 0; i < n - 1; ++i)
22+
if(a[i] != a[i + 1])
23+
ok = false;
24+
25+
if(ok) cout << n << "\n";
26+
else cout << "1\n";
27+
}
28+
}

Codeforces Global Round 10/B.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main(){
6+
ios::sync_with_stdio(false);
7+
cin.tie(NULL);
8+
9+
int t;
10+
cin >> t;
11+
12+
while(t--){
13+
int n;
14+
long long k;
15+
cin >> n >> k;
16+
17+
vector<int> a(n);
18+
for(int i = 0; i < n; ++i)
19+
cin >> a[i];
20+
21+
int mx = a[0], mn = a[0];
22+
for(int i = 0; i < n; ++i){
23+
mx = max(mx, a[i]);
24+
mn = min(mn, a[i]);
25+
}
26+
27+
if(k & 1){
28+
for(int i = 0; i < n; ++i)
29+
cout << mx - a[i] << " ";
30+
cout << "\n";
31+
}
32+
else{
33+
for(int i = 0; i < n; ++i)
34+
cout << a[i] - mn << " ";
35+
cout << "\n";
36+
}
37+
}
38+
}

Codeforces Global Round 10/C.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main(){
6+
ios::sync_with_stdio(false);
7+
cin.tie(NULL);
8+
9+
int t;
10+
cin >> t;
11+
12+
while(t--){
13+
int n;
14+
cin >> n;
15+
16+
vector<int> a(n);
17+
for(int i = 0; i < n; ++i)
18+
cin >> a[i];
19+
20+
long long ans = 0;
21+
vector<pair<int, int>> nums;
22+
nums.push_back({a[n - 1], 1});
23+
24+
for(int i = n - 2; i >= 0; --i){
25+
int cnt = 1;
26+
if(!nums.empty() && nums.back().first < a[i]){
27+
ans += a[i] - nums.back().first;
28+
while(!nums.empty() && nums.back().first < a[i]){
29+
cnt += nums.back().second;
30+
nums.pop_back();
31+
}
32+
}
33+
nums.push_back({a[i], cnt});
34+
}
35+
36+
cout << ans << "\n";
37+
}
38+
}

Codeforces Global Round 10/D.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
const int k_N = 2e5 + 3;
6+
7+
int n, iter;
8+
string s;
9+
pair<int, int> dp[k_N][4][4];
10+
11+
int get_dp(int pos, int two, int last){
12+
auto &[ans, solved] = dp[pos][two][last];
13+
if(pos == n + 2) return 0;
14+
if(solved == iter)
15+
return ans;
16+
17+
solved = iter;
18+
ans = k_N;
19+
20+
if(pos < n){
21+
if(last != 0){
22+
int new_last = (bool)(last & 2);
23+
ans = get_dp(pos + 1, two, new_last) + (s[pos] != 'L');
24+
}
25+
if(last != 3){
26+
int new_last = (bool)(last & 2) + 2;
27+
ans = min(ans, get_dp(pos + 1, two, new_last) + (s[pos] != 'R'));
28+
}
29+
}
30+
else if(pos == n){
31+
int x = two & 1;
32+
if(last == 3 && x == 1) ans = k_N;
33+
else if(last == 0 && x == 0) ans = k_N;
34+
else{
35+
int new_last = (bool)(last & 2) + x * 2;
36+
ans = get_dp(pos + 1, two, new_last);
37+
}
38+
}
39+
else if(pos == n + 1){
40+
int x = (bool)(two & 2);
41+
if(last == 3 && x == 1) ans = k_N;
42+
else if(last == 0 && x == 0) ans = k_N;
43+
else{
44+
int new_last = (bool)(last & 2) + x * 2;
45+
ans = get_dp(pos + 1, two, new_last);
46+
}
47+
}
48+
49+
return ans;
50+
}
51+
52+
void solve(){
53+
cin >> n >> s;
54+
int ans = k_N;
55+
for(int i = 0; i < 4; ++i){
56+
int sum = 0;
57+
if(s[0] == 'R' != ((bool)(i & 1)))
58+
sum++;
59+
if(s[1] == 'R' != ((bool)(i & 2)))
60+
sum++;
61+
ans = min(ans, get_dp(2, i, i) + sum);
62+
}
63+
cout << ans << "\n";
64+
}
65+
66+
int main(){
67+
ios::sync_with_stdio(false);
68+
cin.tie(NULL);
69+
70+
int t;
71+
cin >> t;
72+
73+
for(iter = 1; iter <= t; ++iter) solve();
74+
}

Codeforces Global Round 10/E.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
const int k_N = 25 + 3;
6+
7+
long long a[k_N][k_N];
8+
9+
int main(){
10+
int n;
11+
cin >> n;
12+
13+
for(int i = 1; i <= 2 * n - 1; ++i){
14+
int x, y;
15+
if(i <= n) x = i, y = 1;
16+
else x = n, y = i - (n - 1);
17+
18+
int cnt = 0;
19+
while(x >= 1 && y <= n){
20+
//cout << x << " " << y << " x y" << endl;
21+
//cout << cnt << " cnt" << endl;
22+
if(cnt & 1) a[x][y] = (1ll << (i - 1));
23+
else a[x][y] = 0;
24+
x--, y++;
25+
cnt++;
26+
}
27+
}
28+
29+
for(int i = 1; i <= n; ++i){
30+
for(int j = 1; j <= n; ++j)
31+
cout << a[i][j] << " ";
32+
cout << "\n";
33+
fflush(stdout);
34+
}
35+
36+
int q;
37+
cin >> q;
38+
39+
while(q--){
40+
long long k;
41+
cin >> k;
42+
43+
int cnt = 1;
44+
int x = 1, y = 1;
45+
while(x != n || y != n){
46+
cout << x << " " << y << "\n";
47+
fflush(stdout);
48+
49+
if(x == n) y++;
50+
else if(y == n) x++;
51+
else{
52+
long long t = (1ll << cnt) & k;
53+
//cout << t << " t" << "\n";
54+
if(a[x + 1][y] == t) x++;
55+
else y++;
56+
}
57+
cnt++;
58+
}
59+
cout << x << " " << y << "\n";
60+
fflush(stdout);
61+
}
62+
}

Codeforces Global Round 10/F.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
const long long k_H = 1e12;
6+
7+
int main(){
8+
ios::sync_with_stdio(false);
9+
cin.tie(NULL);
10+
11+
long long n;
12+
cin >> n;
13+
14+
long long sum = 0;
15+
vector<long long> h(n);
16+
for(int i = 0; i < n; ++i){
17+
cin >> h[i];
18+
sum += h[i];
19+
}
20+
21+
long long l = 0, r = k_H;
22+
while(l != r){
23+
long long mid = (l + r) >> 1;
24+
if(mid * n + n * (n - 1) / 2 >= sum) r = mid;
25+
else l = mid + 1;
26+
}
27+
28+
h[0] = l;
29+
sum -= h[0];
30+
bool pr = false;
31+
for(int i = 1; i < n; ++i){
32+
if(pr){
33+
h[i] = h[i - 1] + 1;
34+
sum -= h[i];
35+
pr = false;
36+
continue;
37+
}
38+
if(h[i - 1] * (n - i) + (n - i - 1) * (n - i) / 2 >= sum){
39+
h[i] = h[i - 1];
40+
sum -= h[i];
41+
pr = true;
42+
}
43+
else{
44+
h[i] = h[i - 1] + 1;
45+
sum -= h[i];
46+
pr = false;
47+
}
48+
}
49+
50+
for(int i = 0; i < n; ++i)
51+
cout << h[i] << " ";
52+
cout << "\n";
53+
}

Codeforces Global Round 10/G.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main(){
6+
ios::sync_with_stdio(false);
7+
cin.tie(NULL);
8+
}

Codeforces Global Round 10/H.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main(){
6+
ios::sync_with_stdio(false);
7+
cin.tie(NULL);
8+
}

Codeforces Global Round 10/I.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main(){
6+
ios::sync_with_stdio(false);
7+
cin.tie(NULL);
8+
}

Codeforces Global Round 8/A.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main(){
6+
ios::sync_with_stdio(false);
7+
cin.tie(NULL);
8+
9+
int t;
10+
cin >> t;
11+
12+
while(t--){
13+
long long a, b, n;
14+
cin >> a >> b >> n;
15+
16+
if(a < b)
17+
swap(a, b);
18+
19+
long long ans_even = 0, ans_odd = 0;
20+
long long new_a, new_b;
21+
22+
new_a = a;
23+
new_b = b;
24+
while(new_a <= n){
25+
new_b += new_a;
26+
new_a += new_b;
27+
ans_even += 2;
28+
}
29+
30+
new_a = a;
31+
new_b = b;
32+
while(new_a <= n){
33+
if(ans_odd >= ans_even - 2){
34+
new_a += new_b;
35+
if(new_a <= n){
36+
ans_odd += 3;
37+
break;
38+
}
39+
else{
40+
ans_odd++;
41+
break;
42+
}
43+
}
44+
new_b += new_a;
45+
new_a += new_b;
46+
ans_odd += 2;
47+
}
48+
49+
cout << min(ans_even, ans_odd) << "\n";
50+
}
51+
}

0 commit comments

Comments
 (0)