- 248's solution
-
P248's Solution
- @ 2026-4-4 22:59:01
运用差分思想,做以下操作:
- 对 ,做操作 ,其中 相当于 。
- 再做一次 。
这样,对 ,,。
此时 ,对 有 ,。
一步一步还原即可。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
cout << n << ' ' << n << endl;
cout << n << ' ';
for (int i = 1; i <= n - 1; i++)
cout << i << ' ';
cout << n + 1 << endl;
for (int i = 1; i <= n; i++)
cout << i << ' ';
cout << n + 1 << endl;
return 0;
}
/* ATTENTION!!! THIS IS THE BARRIER!!! */
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 12;
int a[N], b[N];
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> b[i];
a[n - 1] = -b[n];
for (int i = n - 2; i >= 1; i--)
a[i] = a[i + 1] - b[i + 1];
a[n] = a[1] - b[1];
for (int i = 1; i <= n - 1; i++)
cout << a[i] << ' ';
cout << a[n] << endl;
return 0;
}