Exemplo n.º 1
0
int main()
{
    FastIO(); 
    LL n,i,var,e,l,ans=0;
    VLL v;
    cin >>n;
    for(i=0;i<n;i++)
    {
        cin >>var;
        if(var%2==0)
            ans=ans+var;
        else
            v.PB(var);
    }
    sort(all(v));
    l=v.size();
    if(l%2==0)
        e=0;
    else
        e=1;
    for(i=l-1;i>=e;i--)
        ans=ans+v[i];
    cout <<ans<<"\n";
    return 0;
}
Exemplo n.º 2
0
int main()
{
    FastIO();
    int n,i,var,steps=0;
    VLL b;
    cin >>n;
    for(i=0;i<n;i++)
    {
        cin >>var;
        b.PB(var);
    }
    int cum=0;
    for(i=0;i<n;i++)
    {
        if(cum==b[i])
            continue;
        if(b[i]>cum)
        {
            steps+=(b[i]-cum);
            cum=b[i];
        }
        else 
        {
            if(b[i]<cum)
            {
                steps+=(cum-b[i]);;
                cum=b[i];
            }
        }
    }
    cout <<steps<<"\n";
    return 0;
}
Exemplo n.º 3
0
int main()
{
    int t; si(t); while(t--)
    {
        LL x; cin>>x;
        VLL tp = f(x);
        cout<<tp.size()<<endl;
        for(auto c : tp) cout<<c<<" "; cout<<endl;
    }
    return 0;	
}
Exemplo n.º 4
0
int main()
{
	LL N, K;
	cin >> N >> K;
	VLL v;
	REP(i,N)
	{
		LL x;
		cin >> x;
		v.PB(x);
	}
Exemplo n.º 5
0
int main(){
    scanf("%lld%lld%d",&m,&d,&n);
    REP(i,n){
        LL c;
        scanf("%lld",&c);
        taks.PB(c);
    }
Exemplo n.º 6
0
		fenwickTree(LL N): n(N) {
			LL val;
			tree.resize(n + 10, 0);
			for (LL i = 0; i < n; i++) {
				SLL(val);
				update(i, val);
			}
		}
Exemplo n.º 7
0
// ===  FUNCTION  ======================================================================
//         Name:  sieve
//  Description:  
// =====================================================================================
    void
sieve ( int limit ){
    fill(isPrime, 1);
    isPrime[0] = isPrime[1] = 0;// 0 and 1 are not prime
    primeSum.pb(0);
    for(int i = 2; i<limit; i++){
        if(isPrime[i]){
            for(LL j = (LL)i*i; j<=limit; j+= i){
               isPrime[int(j)] = 0; 
            }
            primes.pb(i);
            noOfPrimes++;
        }
    }
    LL sum = 0;
    REP(i, sz(primes)){
        sum = sum + primes[i];
        primeSum.pb(sum);
    }
Exemplo n.º 8
0
VLL f(LL x)
{
    VLL ret;
    if(x==0)return ret;
    if(x==1)
    {
        ret.PB(1ll); return ret;
    }
    if(x%2==0)
    {
        ret = f(x/2);
        for(auto &c : ret) c*=2;
        return ret;
    }
    LL y = 1;
    while(y<=x)
        y*=3;
    y/=3;
    ret = f(x-y);
    ret.PB(y);
    return ret;
}
Exemplo n.º 9
0
int main()
{
	getFactors();
	LL t, n, m, q, r;
	SLL(t);
	while (t--)
	{
		nr.clear();
		dr.clear();
		SLL(n), SLL(m), SLL(q);
		if (n <= 500)
		{
			query.resize(q);
			answers.resize(q);
			for (LL i = 0; i < q; i++)
			{
				SLL(r);
				query[i] = mp(min(r, n - r), i);
			}
			sortv(query);
			LL lim, start = 1, end = n;
			for (LL i = 0; i < q; i++)
			{
				lim = query[i].f;
				for (; start <= lim; start++)
				{
					LL sz = factor[start].size();
					for (LL k = 0; k < sz; k++)
					{
						LL val = factor[start][k].f;
						LL v = dr[val];
						v += factor[start][k].s;
						dr[val] = v;
					}
				}
				start = lim + 1;
				for (; end >= n - lim + 1; end--)
				{
					LL sz = factor[end].size();
					for (LL k = 0; k < sz; k++)
					{
						LL val = factor[end][k].f;
						LL v = nr[val];
						v += factor[end][k].s;
						nr[val] = v;
					}
				}
				end = n - lim;
				LL ans = 1;
				for (map_it = nr.begin(); map_it != nr.end(); map_it++)
				{
					LL prod = powMod(map_it->first, map_it->second - dr[map_it->first], m);
					ans = (ans * prod) % m;
				}
				if (ans < 0)
					ans += m;
				answers[query[i].s] = ans;
			}
			for (LL i = 0; i < q; i++)
				printf("%lld\n", answers[i]);
		}
		else
		{
			powers.resize(n + 1);
			inverse.resize(n + 1);
			answers.resize(n + 1);
			inverse[0] = powers[0] = 1;
			LL phi = etf(m);
			for (LL i = 1; i <= n; i++)
			{
				powers[i] = powMod(i%m, i, m);
				inverse[i] = powMod(powMod(i, phi - 1, m), i, m);
			}
			answers[1] = answers[n - 1] = powers[n];
			for (LL i = 2; i <= n/2; i++)
			{
				LL val = answers[i - 1];
				val = (val * powers[n - i + 1]) % m;
				val = (val * inverse[i]) % m;
				answers[i] = answers[n - i] = val;
			}
			while (q--)
			{
				SLL(r);
				printf("%lld\n", answers[r]);
			}
		}
	}
	return 0;
}
Exemplo n.º 10
0
#define PLL pair<LL,LL>
#define VPII vector<PII>
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define FORE(a,b) for(auto &&a:b)
#define FIND(s,n) s.find(n)!=s.end()

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF=1e9;
const int MOD=INF+7;
#define int LL
VLL a;
int n;
LL func(int num){
    LL res=0;
    REP(i,n) res+=a[num][i];
    return res;
}
LL sum(int num){
    LL res=0;
    REP(i,n) res+=a[i][num];
    return res;
}
PLL naname(){
    LL res1=0,res2=0;
    REP(i,n) res1+=a[i][i],res2+=a[n-i-1][i];
    return MP(res1,res2);