QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#696878#7695. Double UpsnowythecatAC ✓5ms18900kbC++2011.5kb2024-11-01 04:46:592024-11-01 04:47:01

Judging History

你现在查看的是最新测评结果

  • [2024-11-01 04:47:01]
  • 评测
  • 测评结果:AC
  • 用时:5ms
  • 内存:18900kb
  • [2024-11-01 04:46:59]
  • 提交

answer

//must be compiled with c++20 
/*
#pragma GCC target ("avx2")
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
*/
#pragma GCC optimize ("unroll-loops")
#include <algorithm>
#include <bits/stdc++.h>
#include <cerrno>
#include <ext/pb_ds/assoc_container.hpp>
#include <type_traits>
using namespace __gnu_pbds;
using namespace std;
#define fasterthanlight cin.tie(0); ios::sync_with_stdio(0);
#define ll long long
#define lll __int128 
const ll inf = 1e9 + 7;
const ll inf2 = 1e9 + 9;
const ll inff= 998244353;
const ll infh = (1LL << 61) - 1;
#define pll pair<ll,ll>
#define pii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define f0(i,n) for (int i=0;i<n;i++)
#define f1(i,n) for (int i=1;i<=n;i++)
#define ff0(i,n) for (int i=n-1;i>-1;i--)
#define ff1(i,n) for (int i=n;i>0;i--)
#define fs(i,a,b) for (int i=a;i<b;i++)
#define testcases int tzxhicjkha; cin>>tzxhicjkha;while (tzxhicjkha--)
#define usingfloats cout<<setprecision(20)
#define ineedtohash mll iqknabxiopk=1;for (ll iqknabxiop=0;iqknabxiop<HASHPOWMAX;iqknabxiop++){pows[iqknabxiop]=iqknabxiopk;iqknabxiopk*=B;}
#define sz(x) ((int)(x.size()))
template <class T> auto vect(const T& v, int n) { return vector<T>(n, v); }
template <class T, class... D> auto vect(const T& v, int n, D... m) {
  return vector<decltype(vect(v, m...))>(n, vect(v, m...));
}

//2*10^6 powers for hashing
const ll HASHPOWMAX=2000005;
int msb(int n)
{
	if (n==0){
		//cout<<"F";
		return 0;
	}
    int k = __builtin_clz(n);
 
    return 31 - k;
}
ll lmsb(ll n)
{
	if (n==0){
		//cout<<"F";
		return 0;
	}
    int k = __builtin_clzll(n);
 
    return 63 - k;
}
//I have no idea if the below code is safe or good
istream &operator>>(istream &is,__int128 &v) {
    string s;
    is>>s;
    v=0;
    for(auto &it:s) if(isdigit(it)) v=v*10+it-'0';
    if(s[0]=='-') v*=-1;
    return is;
}


ostream &operator<<(ostream &os,const __int128 &v) {
    if(v==0) return (os<<"0");
    __int128 num=v;
    if(v<0) os<<'-',num=-num;
    string s;
    for(;num>0;num/=10) s.pb((char)(num%10)+'0');
    reverse(all(s));
    return (os<<s);
}

/*
template<typename T, typename Q>ostream &operator<<(ostream &os,const pair<T,Q> &v) {
    return (os<<v.first<<" "<<v.second);
}
*/

//some cursed cin vector shit
template<typename T> istream &operator>>(istream &is,vector<T> &v) {
    for (T&i:v){
        is>>i;
    }
    return is;

}
template<typename T> ostream &operator<<(ostream &os,const vector<T> &v) {
    if (v.empty()){
        return os;
    }
    for (int i=0;i<v.size()-1;i++){
        os<<v[i]<<" ";
    }
    return os<<v[v.size()-1];
}

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
//const ll B = 100;
const ll B = uniform_int_distribution<ll>(1000, inf - 1)(rng);

/*
//some cursed code
//allows int x=in;
struct {
	template<class T>
	operator T() {
		T x; std::cin >> x; return x;
	}
} in;
//breaks if string
//so do string s = (string)in;
*/

//ty Mark for modint code that I will change
template<long long MOD>
struct ModInt {
    long long v;
    ModInt() {
        v=0;
    }
    ModInt(long long _v) {
        v = _v % MOD;
        if (v < 0) {
            v += MOD;
        }
    }
 
    friend ModInt pow(ModInt base, long long exp) {
        ModInt res = 1;
        while (exp) {
            if (exp & 1) {
                res *= base;
            }
            base *= base;
            exp >>= 1;
        }
        return res;
    }
 
    ModInt &operator+=(ModInt b) {
        if ((v += b.v) >= MOD) {
            v -= MOD;
        }
        return *this;
    }
 
    ModInt &operator-=(ModInt b) {
        if ((v -= b.v) < 0) {
            v += MOD;
        }
        return *this;
    }
 
    ModInt &operator*=(ModInt b) {
        if constexpr (MOD==infh){
            //UNSAFE CODE PROBABLY
            uint64_t l1 = uint32_t(v), h1 = v >> 32;
            uint64_t l2 = uint32_t(b.v), h2 = b.v >> 32;
            uint64_t l = l1 * l2, m = l1 * h2 + l2 * h1, h = h1 * h2;
            uint64_t ret = (l & MOD) + (l >> 61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + 1;
            ret = (ret & MOD) + (ret >> 61);
            ret = (ret & MOD) + (ret >> 61);
            v = ret - 1;
            return *this;
        }
        else if constexpr (MOD<=INT_MAX){
            //if less than or equal to INT_MAX, lll isn't needed
            v=v * b.v % MOD;
            return *this;
        }
        else{
            v = (__int128)1 * v * b.v % MOD;
            return *this;
        }
    }

	//division is scuffed
    ModInt &operator/=(ModInt b) {
        *this *= pow(b, MOD - 2);
        return *this;
    }
 
    friend ModInt operator+(ModInt a, ModInt b) {
        return a += b;
    }
 
    friend ModInt operator-(ModInt a, ModInt b) {
        return a -= b;
    }
 
    friend ModInt operator*(ModInt a, ModInt b) {
        return a *= b;
    }
 
    friend ModInt operator/(ModInt a, ModInt b) {
        return a /= b;
    }
    
    friend istream &operator>>(istream &is, ModInt &a) {
        long long x;
        is >> x;
        a = ModInt(x);
        return is;
    }
 
    friend ostream &operator<<(ostream &os, ModInt a) {
        return os << a.v;
    }

    bool operator==(const ModInt& y) const{
        return v == y.v;
    }

    bool operator!=(const ModInt& y) const{
        return v != y.v;
    }
    ModInt& operator++() {
        v++;
        if (v == MOD) v = 0;
        return *this;
    }
    ModInt& operator--() {
        if (v == 0) v = MOD;
        v--;
        return *this;
    }
    ModInt operator++(int) {
        ModInt result = *this;
        ++*this;
        return result;
    }
    ModInt operator--(int) {
        ModInt result = *this;
        --*this;
        return result;
    }
    //bad operators for completeness sake
    bool operator>(const ModInt& y) const{
        return v > y.v;
    }
    bool operator>=(const ModInt& y) const{
        return v >= y.v;
    }
    bool operator<=(const ModInt& y) const{
        return v <= y.v;
    }
    bool operator<(const ModInt& y) const{
        return v < y.v;
    }

};
using mll = ModInt<infh>;
using mint = ModInt<inf>;
using minf = ModInt<inff>;
	


ll exp(ll x, ll n, ll m=inf) {
	assert(n >= 0);
	x %= m;  // note: m * m must be less than 2^63 to avoid ll overflow
	ll res = 1;
	while (n > 0) {
		if (n % 2 == 1) { res = res * x % m; }
		x = x * x % m;
		n /= 2;
	}
	return res;
}
ll expu(ll x, ll n) {
	assert(n >= 0);
	ll res = 1;
	while (n > 0) {
		if (n % 2 == 1) { res = res * x; }
		x = x * x;
		n /= 2;
	}
	return res;
}
mll exph(mll base, ll exp) {
    mll res = 1;
    while (exp) {
        if (exp & 1) {
            res *= base;
        }
        base *= base;
        exp >>= 1;
    }
    return res;
}
minf expf(minf base, ll exp) {
    minf res = 1;
    while (exp) {
        if (exp & 1) {
            res *= base;
        }
        base *= base;
        exp >>= 1;
    }
    return res;
}
mint expo(mint base, ll exp) {
    mint res = 1;
    while (exp) {
        if (exp & 1) {
            res *= base;
        }
        base *= base;
        exp >>= 1;
    }
    return res;
}
vector<mll> pows(HASHPOWMAX);
const mll HMODINV=exph(B,infh-2);
struct hashPart {
    mll value;
    int len;
    hashPart() {
        value=0;
        len=0;
    }
    hashPart(mll x, int y) : value(x), len(y) {}
    hashPart operator+=(hashPart b) {
        hashPart a=hashPart(value * pows[b.len] + b.value, len + b.len);
        (*this).value=a.value;
        (*this).len=a.len;
        return *this;
    }
    hashPart operator+(hashPart b) {
        return hashPart(value * pows[b.len] + b.value, len + b.len);
    }
 
    bool operator==(hashPart b) {
        return value == b.value;
    }
};
template<class T>
struct hashString {
    vector<mll> hash;
 
    hashString(T s) {
        hash.resize(int(s.size()) + 1);
        for (int i = 0; i < int(s.size()); i++) {
            hash[i + 1] = (hash[i] * B + s[i]);
        }
        while (int(pows.size()) < int(hash.size())) {
            pows.push_back(pows.back() * B);
        }
    }
 
    hashPart getHash(int l, int r) {
        return hashPart(hash[r] -hash[l] * pows[r - l], r - l);
    }
 
    hashPart getHash() {
        return getHash(0, hash.size() - 1);
    }
};


//I don't understand the below code, all I know is it's good for hashing apparently
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll es(ll x1, ll y1, ll x2, ll y2){
	return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
ll man(ll x1, ll y1, ll x2, ll y2){
	return abs(x1-x2)+abs(y1-y2);	
}



minf choose(int n,int k){
    if (k>n){
        return 0;
    }
    minf ret=1;
    for (int i=n;i>n-k;i--){
        ret*=i;
    }
    for (int i=1;i<=k;i++){
        ret/=i;
    }
    return ret;
}
//stolen from geeks for geeks
vector<int> sieve(int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));
 
    for (int p = 2; p * p <= n; p++) {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true) {
            // Update all multiples of p greater than or
            // equal to the square of it numbers which are
            // multiple of p and are less than p^2 are
            // already been marked.
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
    vector<int> ret;
    // Print all prime numbers
    for (int p = 2; p <= n; p++)
        if (prime[p])
            ret.pb(p);
    return ret;
}


void setup(){

}

typedef tree<double,null_type,less_equal<double>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;



void solve(){
    int n;
    cin>>n;
    vector<int> nums;
    for (int i=0;i<n;i++){
        lll a;
        cin>>a;
        int b=0;
        while (a>1){
            b++;
            a/=2;
        }
        nums.pb(b);
    }
    int dec=0;
    while (nums.size()>1){
        for (int i=0;i<nums.size();i++){
            if (nums[i]<dec){
                    nums.erase(nums.begin()+i);
                i--;
            }
        }
        for (int i=0;i<nums.size()-1;i++){
            if (nums[i]==dec){
                if (nums[i+1]==dec){
                    nums[i]++;
                    nums.erase(nums.begin()+i+1);
                }
                else{
                    nums.erase(nums.begin()+i);
                }
                i--;
            }
        }
        //cout<<nums<<"\n";
        dec++;
    }
    cout<<(((lll)1)<<nums[0])<<"\n";


}

signed main() {
    setup();
    //usingfloats;
	fasterthanlight;
	//ineedtohash;
    //testcases{
        solve();
    //}


}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 18740kb

input:

5
4 2 2 1 8

output:

16

result:

ok single line: '16'

Test #2:

score: 0
Accepted
time: 0ms
memory: 18756kb

input:

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

512

result:

ok single line: '512'

Test #3:

score: 0
Accepted
time: 2ms
memory: 18728kb

input:

1000
1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650...

output:

649037107316853453566312041152512

result:

ok single line: '649037107316853453566312041152512'

Test #4:

score: 0
Accepted
time: 0ms
memory: 18576kb

input:

1
1

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 18900kb

input:

1
2

output:

2

result:

ok single line: '2'

Test #6:

score: 0
Accepted
time: 0ms
memory: 18680kb

input:

1
4294967296

output:

4294967296

result:

ok single line: '4294967296'

Test #7:

score: 0
Accepted
time: 0ms
memory: 18648kb

input:

1
18446744073709551616

output:

18446744073709551616

result:

ok single line: '18446744073709551616'

Test #8:

score: 0
Accepted
time: 0ms
memory: 18628kb

input:

1
1267650600228229401496703205376

output:

1267650600228229401496703205376

result:

ok single line: '1267650600228229401496703205376'

Test #9:

score: 0
Accepted
time: 5ms
memory: 18644kb

input:

384
18014398509481984 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 10737418...

output:

618970019642690137449562112

result:

ok single line: '618970019642690137449562112'

Test #10:

score: 0
Accepted
time: 0ms
memory: 18652kb

input:

430
36893488147419103232 128 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248...

output:

158456325028528675187087900672

result:

ok single line: '158456325028528675187087900672'

Test #11:

score: 0
Accepted
time: 0ms
memory: 18700kb

input:

527
1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 1099511627776 10...

output:

158456325028528675187087900672

result:

ok single line: '158456325028528675187087900672'

Test #12:

score: 0
Accepted
time: 0ms
memory: 18772kb

input:

809
1073741824 77371252455336267181195264 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 2097152 20...

output:

19807040628566084398385987584

result:

ok single line: '19807040628566084398385987584'

Test #13:

score: 0
Accepted
time: 0ms
memory: 18596kb

input:

435
618970019642690137449562112 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 65536 128 128 128 128 128 128 128 128 128 128 128 128 128 ...

output:

316912650057057350374175801344

result:

ok single line: '316912650057057350374175801344'

Test #14:

score: 0
Accepted
time: 0ms
memory: 18560kb

input:

857
4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 4398046511104 43...

output:

1267650600228229401496703205376

result:

ok single line: '1267650600228229401496703205376'

Test #15:

score: 0
Accepted
time: 0ms
memory: 18604kb

input:

765
17592186044416 2417851639229258349412352 2417851639229258349412352 2417851639229258349412352 2417851639229258349412352 2417851639229258349412352 2417851639229258349412352 2417851639229258349412352 2417851639229258349412352 2417851639229258349412352 2417851639229258349412352 241785163922925834941...

output:

1237940039285380274899124224

result:

ok single line: '1237940039285380274899124224'

Test #16:

score: 0
Accepted
time: 0ms
memory: 18692kb

input:

122
2097152 18014398509481984 18014398509481984 18014398509481984 18014398509481984 18014398509481984 18014398509481984 18014398509481984 18014398509481984 18014398509481984 18014398509481984 18014398509481984 18014398509481984 18014398509481984 18014398509481984 18014398509481984 18014398509481984 ...

output:

10141204801825835211973625643008

result:

ok single line: '10141204801825835211973625643008'

Test #17:

score: 0
Accepted
time: 0ms
memory: 18684kb

input:

491
8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 8192 562949953421312 9444732965739290427392 9444732965739290427392 9444732965739290427392 9444732965739290427392 9444732965739290427392 94447329657392904273...

output:

1267650600228229401496703205376

result:

ok single line: '1267650600228229401496703205376'

Test #18:

score: 0
Accepted
time: 2ms
memory: 18804kb

input:

164
549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 549755813888 5497558138...

output:

20282409603651670423947251286016

result:

ok single line: '20282409603651670423947251286016'