QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#468726#1944. Circle of FriendsinksamuraiWA 286ms32064kbC++236.3kb2024-07-08 23:43:192024-07-08 23:43:20

Judging History

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

  • [2024-07-08 23:43:20]
  • 评测
  • 测评结果:WA
  • 用时:286ms
  • 内存:32064kb
  • [2024-07-08 23:43:19]
  • 提交

answer

#include <bits/stdc++.h>

// cut here
#ifdef _MSC_VER
#include <intrin.h>
#endif
 
namespace atcoder {
 
namespace internal {
 
int ceil_pow2(int n) {
    int x = 0;
    while ((1U << x) < (unsigned int)(n)) x++;
    return x;
}
 
int bsf(unsigned int n) {
#ifdef _MSC_VER
    unsigned long index;
    _BitScanForward(&index, n);
    return index;
#else
    return __builtin_ctz(n);
#endif
}
 
}  // namespace internal
 
}  // namespace atcoder
 
 
namespace atcoder {
 
template <class S, S (*op)(S, S), S (*e)()> struct segtree {
  public:
    segtree() : segtree(0) {}
    segtree(int n) : segtree(std::vector<S>(n, e())) {}
    segtree(const std::vector<S>& v) : _n(int(v.size())) {
        log = internal::ceil_pow2(_n);
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }
 
    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }
 
    S get(int p) {
        assert(0 <= p && p < _n);
        return d[p + size];
    }
 
    S prod(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        S sml = e(), smr = e();
        l += size;
        r += size;
 
        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }
 
    S all_prod() { return d[1]; }
 
    template <bool (*f)(S)> int max_right(int l) {
        return max_right(l, [](S x) { return f(x); });
    }
    template <class F> int max_right(int l, F f) {
        assert(0 <= l && l <= _n);
        assert(f(e()));
        if (l == _n) return _n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = (2 * l);
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }
 
    template <bool (*f)(S)> int min_left(int r) {
        return min_left(r, [](S x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }
 
  private:
    int _n, size, log;
    std::vector<S> d;
 
    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};
 
}  // namespace atcoder
// cut here 

#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int) a.size()
#define all(a) a.begin(),a.end()
#define vec(...) vector<__VA_ARGS__>
#define _3zlqvu8 ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

// snuke's mod int
template <ll mod>
struct modint{
	ll x;
	modint(ll x=0):x((x%mod+mod)%mod){}
	modint operator-()const{return modint(-x);}
	modint& operator+=(const modint a){if((x+=a.x)>=mod) x-=mod; return *this;}
	modint& operator-=(const modint a){if((x+=mod-a.x)>=mod) x-=mod; return *this;}
	modint& operator*=(const modint a){(x*=a.x)%=mod; return *this;}
	modint operator+(const modint a)const{modint res(*this); return res+=a;}
	modint operator-(const modint a)const{modint res(*this); return res-=a;}
	modint operator*(const modint a)const{modint res(*this); return res*=a;}
	modint pow(ll n)const{
		modint res=1,x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modint inv()const{return pow(mod-2);}
};

using mint=modint<998244353>;

using vm=vec(mint);

int op(int l,int r){
	return l&r;
}

int e(){
	return (1ll<<60)-1;
}

void slv(){
	int n;
	cin>>n;

	vi a(n);
	rep(i,n){
		cin>>a[i];
	}

	vi tmp={0};
	int x=a[0];
	rep(i,n){
		x&=a[i];
		tmp.pb(x);
	}
	sort(all(tmp)); tmp.erase(unique(all(tmp)),tmp.end());
	const int si=sz(tmp);

	atcoder::segtree<int,op,e> seg(n);
	rep(i,n){
		seg.set(i,a[i]);
	}

	// dp(i, j) = {denote number of divisions such that last block & tmp[j] > 0}
	vec(vm) dp(n,vm(si));
	vec(vm) sf(n,vm(si));
	auto range_sum=[&](int i,int l,int r)->mint{
		return sf[l][i]-(r+1>=n?0:sf[r+1][i]);
	};
	per(i,n){
		// axali subarray avige
		// bolomde
		{
			int now=seg.prod(i,n);
			rep(j,si){
				if((tmp[j]&now)>0){
					dp[i][j]+=1;
				}
			}
			if(now){
				dp[i][0]+=1;
			}
		}
		if(i<n-1){
			int l=i,r=n-2;
			int opt=i;
			while(l<=r){
				int m=(l+r)/2;
				if(seg.prod(i,m+1)>0){
					opt=m,l=m+1;
				}else{
					r=m-1;
				}
			}
			rep(k,si){
				// if(i==n-2 and k==0) print(sf[i+1][0].x,range_sum(k,i+1,opt+1).x);
				dp[i][k]+=range_sum(k,i+1,opt+1);
			}
		}
		rep(k,si){
			if(i+1<n) sf[i][k]+=sf[i+1][k];
			sf[i][k]+=dp[i][k];
		}
		// {
		// 	int now=a[i];
		// 	rng(j,i,n-1){
		// 		now&=a[j];
		// 		if(!now) break;
		// 		rep(k,si){
		// 			dp[i][k]+=dp[j+1][k];
		// 		}
		// 	}
		// }
		// print(dp[i][0].x);
	}

	mint ans=dp[0][0];
	int now=a[0];
	rep(i,n-1){
		now&=a[i];
		if(!now) break;
		int id=lower_bound(all(tmp),now)-tmp.begin();
		// print(i,id,dp[i+1][id].x);
		ans+=dp[i+1][id];
	}
	cout<<ans.x<<"\n";
}

signed main(){
_3zlqvu8;
	slv();
}

詳細信息

Test #1:

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

input:

1
1

output:

1

result:

ok single line: '1'

Test #2:

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

input:

1
1152921504606846975

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 286ms
memory: 32064kb

input:

200000
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:

792253080

result:

wrong answer 1st lines differ - expected: '792053081', found: '792253080'