1397C - Multiples of Length - CodeForces Solution


constructive algorithms greedy math number theory *1600

Please click on ads to support us..

C++ Code:

/*...Bismillahir Rahmanir Rahim...*/
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;

//debug..........
#ifdef Abdul_Aziz
#include "debug.cpp"
#else
#define dbg(x...)
#endif

#define   int  long long
#define   ll   long long
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int>
#define   bitcount(x)  (int)__builtin_popcount(x)
#define   Lsb(x)  (int)__builtin_ctzll(x)
#define   fast  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define   sz(x)  (int)x.size()
#define   all(a) (a).begin(),(a).end()
#define   Yes  cout << "YES\n"
#define   No  cout << "NO\n"
#define   ff   first
#define   ss   second
#define   endl  "\n"
#define   pi   acos(-1.0)
#define   pii  pair<int,int>
#define   lcm(a,b) (a/__gcd(a, b)*b)

const int  mod = 998244353 ;
const int N = 200005 ;
const int inf = 2147483647;

signed main()
{
    fast ;
    // cout << (-5%4) << endl;
    int n; cin >> n;
    vi a(n+1), rem(n, 0) ;
    for (int i=1;i<=n;++i) cin >> a[i] ;
    if (n==1) {
        cout << "1 1" << endl;
        cout << 0 << endl;
        cout << "1 1" << endl;
        cout << 0 << endl;
        cout << "1 1" << endl;
        cout << -a[1] << endl;
        return 0;
    }
    int cnt = 0;
    for (int i=n;1;i+=n) {
        int r = i%(n-1);
        if (!rem[r]) ++cnt;
        rem[r] = i;
        if (cnt==n-1) break;
    }
    cout << "1 " << n << endl;
    for (int i=1;i<=n;++i) {
        int r = ((n-1) - a[i]%(n-1))%(n-1) ;
        cout << rem[r] << " " ;
        a[i] += rem[r] ;
    }
    cout << endl;
    cout << "1 " << n-1 << endl;
    for (int i=1;i<n;++i) {
        cout << -a[i] << " ";
    }
    cout << endl;
    cout << n << " " << n << endl;
    cout << -a[n] << endl;
    return 0 ;
}


Comments

Submit
0 Comments
More Questions

1382A - Common Subsequence
1512D - Corrupted Array
667B - Coat of Anticubism
284B - Cows and Poker Game
1666D - Deletive Editing
1433D - Districts Connection
2B - The least round way
1324A - Yet Another Tetris Problem
246B - Increase and Decrease
22E - Scheme
1566A - Median Maximization
1278A - Shuffle Hashing
1666F - Fancy Stack
1354A - Alarm Clock
1543B - Customising the Track
1337A - Ichihime and Triangle
1366A - Shovels and Swords
919A - Supermarket
630C - Lucky Numbers
1208B - Uniqueness
1384A - Common Prefixes
371A - K-Periodic Array
1542A - Odd Set
1567B - MEXor Mixup
669A - Little Artem and Presents
691B - s-palindrome
851A - Arpa and a research in Mexican wave
811A - Vladik and Courtesy
1006B - Polycarp's Practice
1422A - Fence