結果

問題 No.2653 [Cherry 6th Tune] Re: start! (Make it Zero!)
ユーザー shobonvipshobonvip
提出日時 2024-02-23 23:38:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,059 bytes
コンパイル時間 5,172 ms
コンパイル使用メモリ 263,744 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-23 23:38:20
合計ジャッジ時間 10,049 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 AC 27 ms
6,676 KB
testcase_64 AC 27 ms
6,676 KB
testcase_65 AC 28 ms
6,676 KB
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}


// [ DUAL SEGMENT TREE ] BY SHOBON
// REFERENCE --- ATCODER LIBRARY
// VERSION 1.0 (2022/08/28)

int ceil_pow2(int n) {
	int x = 0;
	while ((1U << x) < (unsigned int)(n)) x++;
	return x;
}

template <class F, F (*composition)(F, F), F (*id)()> struct dual_segtree{
		public:
			dual_segtree() : dual_segtree(0) {}
			explicit dual_segtree(int n) : dual_segtree(std::vector<F>(n, id())) {}
			explicit dual_segtree(const std::vector<F>& v) : _n(int(v.size())) {
				log = ceil_pow2(_n);
				size = 1 << log;
				lz = std::vector<F>(2 * size, id());
				for (int i = 0; i < _n; i++) lz[size + i] = v[i];
			}
 
			void apply(int l, int r, F f){
				assert (0 <= l && l <= r && r <= _n);
				if (l == r) return;
 
				l += size;
				r += size;
 
				for (int i = log; i >= 1; i--){
					if (((l >> i) << i) != l) push(l >> i);
					if (((r >> i) << i) != r) push((r - 1) >> i);
				}
 
				while (l < r){
					if (l & 1) all_apply(l++, f);
					if (r & 1) all_apply(--r, f);
					l >>= 1;
					r >>= 1;
				}
			}
			
			F get(int p) {
				assert(0 <= p && p < _n);
				p += size;
				for (int i = log; i >= 1; i--) push(p >> i);
				return lz[p];
			}
		
		private:
			int _n, size, log;
			std::vector<F> lz;
 
			void all_apply(int k, F f){
				lz[k] = composition(f, lz[k]);
			}
 
			void push(int k){
				all_apply(2 * k, lz[k]);
				all_apply(2 * k + 1, lz[k]);
				lz[k] = id();
			}
 
};

// ---- END : DUAL SEGMENT TREE ----

struct F{
	mint b;
	mint c;
};

F composition(F g, F f){
	return {f.b * g.b, f.c * g.b + g.c};
}

F id(){
	return {1, 0};
}

// defcomp
template <typename T>
vector<T> compress(vector<T> &X) {
	vector<T> vals = X;
	sort(vals.begin(), vals.end());
	vals.erase(unique(vals.begin(), vals.end()), vals.end());
	return vals;
}
// -----

// importbisect
template <typename T>
int bisect_left(vector<T> &X, T v){
	return lower_bound(X.begin(), X.end(), v) - X.begin();
}

template <typename T>
int bisect_right(vector<T> &X, T v){
	return upper_bound(X.begin(), X.end(), v) - X.begin();
}
// -----


void solve(){
	int n, m; cin >> n >> m;
	vector<int> x(n);
	vector<ll> battle(n + 1);
	
	ll tmp = 0;
	rep(i,0,n){
		cin >> x[i];
		if (x[i] >= 0){
			tmp += x[i];
			tmp %= m;
		}
		battle[i + 1] = tmp;
	}

	int cnt = 0;
	rep(i,0,n){
		if (x[i] == -1) cnt++;
	}

	if (cnt == 0){
		ll tmp = 0;
		ll ans = 0;
		rep(i,0,n){
			tmp += x[i];
			tmp %= m;
			if (tmp != 0){
				ans++;
			}
		}
		if (tmp != 0){
			ans = 0;
		}
		cout << ans << '\n';
		return;
	}

	int now = (x[0] == -1);
	mint ans = 0;
	rep(i,0,n-1){
		// i - i+1
		if (now == 0){
			if (battle[i + 1] != 0) continue;
		}
		if (cnt-now == 0){
			if (battle[n] - battle[i + 1] != 0) continue;
		}
		ll tar = max(now - (battle[i+1] == 0), 0) + max(cnt - now - (battle[n] - battle[i+1] == 0), 0);
		ans -= mint(m).pow(tar);
		now += (x[i+1] == -1);
	}

	ans = mint(m).pow(cnt - 1) * (n - 1) + ans;
	cout << ans.val() << '\n';

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t; cin >> t;
	while(t--) solve();
}

0