Advertisement
Guest User

Untitled

a guest
Aug 9th, 2023
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.39 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef unsigned int uint;
  4. typedef unsigned long long ull;
  5. typedef long long ll;
  6. typedef long double ld;
  7. typedef pair <int, int> pii;
  8. typedef pair <ll, int> pli;
  9. typedef pair <int, ll> pil;
  10. typedef pair <ll, ll> pll;
  11. typedef pair <ld, ld> pdd;
  12. #define cio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  13. #define cases int _; cin >> _; while(_--)
  14. #define pb push_back
  15. #define eb emplace_back
  16. #define space << " " <<
  17. #define lb lower_bound
  18. #define ub upper_bound
  19. #define F first
  20. #define S second
  21. #define all(v) v.begin(), v.end()
  22. #define rall(v) v.rbegin(), v.rend()
  23. #define Unique(v) v.erase(unique(all(v)), v.end())
  24. #define mset(x) memset(x, 0, sizeof(x))
  25. #define sflush fflush(stdout)
  26. #define cflush cout.flush()
  27. #define yes cout << "YES\n"
  28. #define no cout << "NO\n"
  29. #define lyes cout << "Yes\n"
  30. #define lno cout << "No\n"
  31. #define nl cout << "\n";
  32. #define binary(len, num) bitset <len> (num)
  33. #define vt vector
  34. #define ar array
  35. #define Mat vt <vt <int> >
  36. #define uid uniform_int_distribution <int>
  37.  
  38. template <typename T> istream& operator >> (istream& in, vector<T>& a) {for(auto &x : a) in >> x; return in;};
  39. template <typename T> ostream& operator << (ostream& out, vector<T>& a) {for(auto &x : a) out << x << ' '; return out;};
  40.  
  41. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  42.  
  43. int read(){
  44.     int w = 1, c, ret;
  45.     while((c = getchar()) > '9' || c < '0'){
  46.         w = (c == '-' ? -1 : 1);
  47.     }
  48.     ret = c - '0';
  49.     while((c = getchar()) >= '0' && c <= '9'){
  50.         ret = ret * 10 + c - '0';
  51.     }
  52.     return ret * w;
  53. }
  54.  
  55. int rd(){
  56.     int in;
  57.     cin >> in;
  58.     return in;
  59. }
  60.  
  61. void write(int x){
  62.     if(x < 0){
  63.         putchar('-');
  64.         x = -x;
  65.     }
  66.     if(x > 9){
  67.         write(x / 10);
  68.     }
  69.     putchar(x % 10 + '0');
  70. }
  71.  
  72. const int MAXN = 2e5 + 5, MAXM = 2e5 + 5, INF = 1e9 + 5, MOD = 1e9 + 7;
  73. const ll LINF = 1e18 + 5;
  74. const ld ep = 1e-8, Pi = acos(-1.0);
  75.  
  76. int n, m, k, x;
  77. int a[MAXN], b[MAXN];
  78. bool vis[MAXN];
  79. string s;
  80.  
  81.  
  82.  
  83. void clear(){
  84.    
  85. }
  86.  
  87. int main(){
  88.     cio;
  89.     freopen("photo.in", "r", stdin);
  90.     freopen("photo.out", "w", stdout);
  91.     cin >> n;
  92.     for(int i = 1; i < n; ++i){
  93.         cin >> b[i];
  94.     }
  95.     if(n == 2){
  96.         cout << 1 space 2 << '\n';
  97.         return 0;
  98.     }
  99.     if(n == 3){
  100.         for(int i = 1; i <= 3; ++i){
  101.             for(int j = 1; j <= 3; ++j){
  102.                 for(int k = 1; k <= 3; ++k){
  103.                     if(i != j && i != k && j != k){
  104.                         if(i + j == b[1] && j + k == b[2]){
  105.                             cout << i space j space k << "\n";
  106.                             return 0;
  107.                         }
  108.                     }
  109.                 }
  110.             }
  111.         }
  112.     }
  113.     int mn1 = 0, mx1 = 0, mn2 = 0, mx2 = 0, cur1 = 0, cur2 = 0;
  114.     for(int i = 2; i < n; ++i){
  115.         if(i % 2 == 0){
  116.             cur1 += b[i] - b[i - 1];
  117.             mn1 = min(mn1, cur1);
  118.             mx1 = max(mx1, cur1);
  119.         }
  120.         else{
  121.             cur2 += b[i] - b[i - 1];
  122.             mn2 = min(mn2, cur2);
  123.             mx2 = max(mx2, cur2);
  124.         }
  125.     }
  126.     {
  127.         // if ai = 1 for some odd i
  128.         int cur = 0;
  129.         for(int i = 1; i <= n; i += 2){
  130.             a[i] = 1 + (cur - mn1);
  131.             vis[a[i]] = 1;
  132.             cur += b[i + 1] - b[i];
  133.         }
  134.         int mn = INF;
  135.         for(int i = 1; i <= n; ++i){
  136.             if(!vis[i]){
  137.                 mn = i;
  138.                 break;
  139.             }
  140.         }
  141.         cur = 0;
  142.         for(int i = 2; i <= n; i += 2){
  143.             a[i] = mn + (cur - mn2);
  144.             vis[a[i]] = 1;
  145.             cur += b[i + 1] - b[i];
  146.         }
  147.         bool flag = 1;
  148.         for(int i = 1; i <= n && flag; ++i){
  149.             if(!vis[i]){
  150.                 flag = 0;
  151.             }
  152.         }
  153.         for(int i = 1; i < n && flag; ++i){
  154.             if(b[i] != a[i] + a[i + 1]){
  155.                 flag = 0;
  156.             }
  157.         }
  158.         if(flag){
  159.             for(int i = 1; i <= n; ++i){
  160.                 cout << a[i] << " \n"[i == n];
  161.             }
  162.             return 0;
  163.         }
  164.         else{
  165.             for(int i = 1; i <= n; ++i){
  166.                 a[i] = vis[i] = 0;
  167.             }
  168.         }
  169.     }
  170.     {
  171.         // if ai = 1 for some even i
  172.         int cur = 0;
  173.         for(int i = 2; i <= n; i += 2){
  174.             a[i] = 1 + (cur - mn2);
  175.             vis[a[i]] = 1;
  176.             cur += b[i + 1] - b[i];
  177.         }
  178.         int mn = INF;
  179.         for(int i = 1; i <= n; ++i){
  180.             if(!vis[i]){
  181.                 mn = i;
  182.                 break;
  183.             }
  184.         }
  185.         cur = 0;
  186.         for(int i = 1; i <= n; i += 2){
  187.             a[i] = mn + (cur - mn1);
  188.             cur += b[i + 1] - b[i];
  189.         }
  190.         for(int i = 1; i <= n; ++i){
  191.             cout << a[i] << " \n"[i == n];
  192.         }
  193.     }
  194.  
  195.     return 0;
  196. }  
  197.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement