Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef unsigned int uint;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double ld;
- typedef pair <int, int> pii;
- typedef pair <ll, int> pli;
- typedef pair <int, ll> pil;
- typedef pair <ll, ll> pll;
- typedef pair <ld, ld> pdd;
- #define cio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
- #define cases int _; cin >> _; while(_--)
- #define pb push_back
- #define eb emplace_back
- #define space << " " <<
- #define lb lower_bound
- #define ub upper_bound
- #define F first
- #define S second
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define Unique(v) v.erase(unique(all(v)), v.end())
- #define mset(x) memset(x, 0, sizeof(x))
- #define sflush fflush(stdout)
- #define cflush cout.flush()
- #define yes cout << "YES\n"
- #define no cout << "NO\n"
- #define lyes cout << "Yes\n"
- #define lno cout << "No\n"
- #define nl cout << "\n";
- #define binary(len, num) bitset <len> (num)
- #define vt vector
- #define ar array
- #define Mat vt <vt <int> >
- #define uid uniform_int_distribution <int>
- template <typename T> istream& operator >> (istream& in, vector<T>& a) {for(auto &x : a) in >> x; return in;};
- template <typename T> ostream& operator << (ostream& out, vector<T>& a) {for(auto &x : a) out << x << ' '; return out;};
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- int read(){
- int w = 1, c, ret;
- while((c = getchar()) > '9' || c < '0'){
- w = (c == '-' ? -1 : 1);
- }
- ret = c - '0';
- while((c = getchar()) >= '0' && c <= '9'){
- ret = ret * 10 + c - '0';
- }
- return ret * w;
- }
- int rd(){
- int in;
- cin >> in;
- return in;
- }
- void write(int x){
- if(x < 0){
- putchar('-');
- x = -x;
- }
- if(x > 9){
- write(x / 10);
- }
- putchar(x % 10 + '0');
- }
- const int MAXN = 2e5 + 5, MAXM = 2e5 + 5, INF = 1e9 + 5, MOD = 1e9 + 7;
- const ll LINF = 1e18 + 5;
- const ld ep = 1e-8, Pi = acos(-1.0);
- int n, m, k, x;
- int a[MAXN], b[MAXN];
- bool vis[MAXN];
- string s;
- void clear(){
- }
- int main(){
- cio;
- freopen("photo.in", "r", stdin);
- freopen("photo.out", "w", stdout);
- cin >> n;
- for(int i = 1; i < n; ++i){
- cin >> b[i];
- }
- if(n == 2){
- cout << 1 space 2 << '\n';
- return 0;
- }
- if(n == 3){
- for(int i = 1; i <= 3; ++i){
- for(int j = 1; j <= 3; ++j){
- for(int k = 1; k <= 3; ++k){
- if(i != j && i != k && j != k){
- if(i + j == b[1] && j + k == b[2]){
- cout << i space j space k << "\n";
- return 0;
- }
- }
- }
- }
- }
- }
- int mn1 = 0, mx1 = 0, mn2 = 0, mx2 = 0, cur1 = 0, cur2 = 0;
- for(int i = 2; i < n; ++i){
- if(i % 2 == 0){
- cur1 += b[i] - b[i - 1];
- mn1 = min(mn1, cur1);
- mx1 = max(mx1, cur1);
- }
- else{
- cur2 += b[i] - b[i - 1];
- mn2 = min(mn2, cur2);
- mx2 = max(mx2, cur2);
- }
- }
- {
- // if ai = 1 for some odd i
- int cur = 0;
- for(int i = 1; i <= n; i += 2){
- a[i] = 1 + (cur - mn1);
- vis[a[i]] = 1;
- cur += b[i + 1] - b[i];
- }
- int mn = INF;
- for(int i = 1; i <= n; ++i){
- if(!vis[i]){
- mn = i;
- break;
- }
- }
- cur = 0;
- for(int i = 2; i <= n; i += 2){
- a[i] = mn + (cur - mn2);
- vis[a[i]] = 1;
- cur += b[i + 1] - b[i];
- }
- bool flag = 1;
- for(int i = 1; i <= n && flag; ++i){
- if(!vis[i]){
- flag = 0;
- }
- }
- for(int i = 1; i < n && flag; ++i){
- if(b[i] != a[i] + a[i + 1]){
- flag = 0;
- }
- }
- if(flag){
- for(int i = 1; i <= n; ++i){
- cout << a[i] << " \n"[i == n];
- }
- return 0;
- }
- else{
- for(int i = 1; i <= n; ++i){
- a[i] = vis[i] = 0;
- }
- }
- }
- {
- // if ai = 1 for some even i
- int cur = 0;
- for(int i = 2; i <= n; i += 2){
- a[i] = 1 + (cur - mn2);
- vis[a[i]] = 1;
- cur += b[i + 1] - b[i];
- }
- int mn = INF;
- for(int i = 1; i <= n; ++i){
- if(!vis[i]){
- mn = i;
- break;
- }
- }
- cur = 0;
- for(int i = 1; i <= n; i += 2){
- a[i] = mn + (cur - mn1);
- cur += b[i + 1] - b[i];
- }
- for(int i = 1; i <= n; ++i){
- cout << a[i] << " \n"[i == n];
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement