题解:CF2157F Git Gud
WilliamFranklin · · 题解
Solution
以下
首先第一反应是分块,设每
接着我们考虑,每一次组内的一个数
从这个向后跳的过程中,有无感觉出树状数组的影子,就是每一次
还是不可以,但我们想到,我们分的组还是太少了,才不到
懒得算了,手动二分以下,
对于
:::success[AC Code (
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mp(Tx, Ty) make_pair(Tx, Ty)
#define For(Ti, Ta, Tb) for(auto Ti = (Ta); Ti <= (Tb); Ti++)
#define Dec(Ti, Ta, Tb) for(auto Ti = (Ta); Ti >= (Tb); Ti--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx)
const int N = 250005;
pair<int, pair<int, int> > a[N];
bool cmp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
if (a.x == b.x) return a.y.x > b.y.x;
return a.x < b.x;
}
int calc() {
long long ans = 0;
For(i, 1, 250000) ans += min(a[i].y.y, 250000 - a[i].y.x);
cout << 249999 << '\n';
For(i, 1, 250000) if (a[i].y.x != 250000)cout << a[i].y.x << ' ' << min(a[i].y.y, 250000 - a[i].y.x) << '\n';
For(i, 2, 250000) if (a[i].y.x != 250000) if (a[i].y > a[i - 1 - (a[i - 1].y.x == 250000)].y) ans += 1000;
return ans;
}
int work(int B) {
For(i, 1, 250000) {
int last = 1;
int x = i;
while (x % B == 0) {
last = last * B;
x /= B;
}
a[i].x = last * (x % B);
a[i].y.x = i;
a[i].y.y = last;
}
sort(a + 1, a + 250000 + 1, cmp);
long long ans = calc();
return ans;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
if (n == 4) {
cout << "4\n";
cout << "1 4\n";
cout << "3 1\n";
cout << "2 1\n";
cout << "3 1\n";
return 0;
}
int B = 100;
int ans = work(B);
//cout << ans;
return 0;
}
:::
:::success[AC Code (
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mp(Tx, Ty) make_pair(Tx, Ty)
#define For(Ti, Ta, Tb) for(auto Ti = (Ta); Ti <= (Tb); Ti++)
#define Dec(Ti, Ta, Tb) for(auto Ti = (Ta); Ti >= (Tb); Ti--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx)
const int N = 250005;
pair<int, pair<int, int> > a[N];
bool cmp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
if (a.x == b.x) return a.y.x > b.y.x;
return a.x < b.x;
}
int calc() {
long long ans = 0;
For(i, 1, 250000) ans += min(a[i].y.y, 250000 - a[i].y.x);
cout << 249999 << '\n';
For(i, 1, 250000) if (a[i].y.x != 250000)cout << a[i].y.x << ' ' << min(a[i].y.y, 250000 - a[i].y.x) << '\n';
For(i, 2, 250000) if (a[i].y.x != 250000) if (a[i].y > a[i - 1 - (a[i - 1].y.x == 250000)].y) ans += 1000;
return ans;
}
int work(int B) {
For(i, 1, 250000) {
int last = 1;
int x = i;
while (x % B == 0) {
last = last * B;
x /= B;
}
a[i].x = last * (x % B);
a[i].y.x = i;
a[i].y.y = last;
}
sort(a + 1, a + 250000 + 1, cmp);
long long ans = calc();
return ans;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
if (n == 4) {
cout << "4\n";
cout << "1 4\n";
cout << "3 1\n";
cout << "2 1\n";
cout << "3 1\n";
return 0;
}
int B = 63;
int ans = work(B);
//cout << ans;
return 0;
}
:::