记录编号 406658 评测结果 AAAAAAAAAA
题目名称 天才魔法少女琪露诺爱计数 最终得分 100
用户昵称 GravatarkZime 是否通过 通过
代码语言 C++ 运行时间 0.027 s
提交时间 2017-05-19 12:55:30 内存使用 1.71 MiB
显示代码纯文本
# include <bits/stdc++.h>
# define CLJ 998244353
# define MAXN 100023
using namespace std;
//[>
char buf[1<<18], *fs, *ft;
inline char readc(){return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<18,stdin)),fs==ft)?EOF:*fs++;}
//*/
//# define readc getchar

inline int gn() {
	int k = 0; char c = readc();
	for(; !isdigit(c); c = readc()) ;
	for(; isdigit(c); c = readc()) k = k * 10 + c - '0';
	return k;
}

inline int mod(int x) {
	while(x < 0) x += CLJ;
	x %= CLJ;
	return x;
}

int s[MAXN], h[MAXN], dp[MAXN], n, l, r, t, maxh = 0;

inline int lowbit(int x) {
	return x&-x;
}

inline void add(int x, int k) {
	while(x <= n) {
		s[x] = mod(s[x] + k);
		//s[x] += k;
		x += lowbit(x);
	}
}

inline int query(int x) {
	int ans = 0;
	while(x) {
		ans = mod(ans + s[x]);
		//ans += s[x];
		x -= lowbit(x);
	}
	return ans;
}

int main() {
	freopen("cirnoisclever.in", "r", stdin);
	freopen("cirnoisclever.out", "w", stdout);

	n = gn(), l = gn(), r = gn(), t = gn();
	for(int i = 1; i <= n; i++) maxh = max(maxh, h[i] = gn());

	dp[1] = 1;
	add(h[1], dp[1]);
	
	for(int i = l + 1; i <= n; i++) {
		int lh = max(1, h[i] - t);
		int rh = min(h[i] + t, maxh);
	
		dp[i] = mod(query(rh) - query(lh - 1));
		//dp[i] = query(rh) - query(lh - 1);
		add(h[i - l + 1], dp[i - l + 1]);
		if(i > r) add(h[i - r], -dp[i - r]);
	}

	//for(int i = 1; i <= n; i++) printf("%d ", dp[i]);
	
	printf("%d", dp[n]);

	return 0;
}