Submission #1110743


Source Code Expand

#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define lc (x << 1)
#define rc (x << 1 | 1)
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();

	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 100000 + 5;
const int mo = 1000000007;

int n;
LL A, B;
LL s[N];

struct Segment_Tree {
	int sum[N << 2];
	int tag[N << 2];

	Segment_Tree() {
		memset(sum, 0, sizeof sum);
		memset(tag, 0, sizeof tag);
	}

	void upd(int x) {sum[x] = (sum[lc] + sum[rc]) % mo;}

	void make_tag(int x) {
		sum[x] = 0;
		tag[x] = 1;
	}

	void push_down(int x) {
		if (tag[x]) {
			make_tag(lc);
			make_tag(rc);
			tag[x] = 0;
		}
	}

	void reset() {make_tag(1);}

	void set(int x, int l, int r, int pos, int val) {
		if (l == r) {sum[x] = val; return;}
		push_down(x);
		int m = (l + r) >> 1;
		if (pos <= m) set(lc, l, m, pos, val);
		else set(rc, m + 1, r, pos, val);
		upd(x);
	}

	LL getsum(int x, int l, int r, int s, int t) {
		if (s <= l && r <= t) return sum[x];
		push_down(x);
		int m = (l + r) >> 1, ans = 0;
		if (s <= m) (ans += getsum(lc, l, m, s, t)) %= mo;
		if (m < t) (ans += getsum(rc, m + 1, r, s, t)) %= mo;
		return ans;
	}
} T1, T2;

int main() {
	read(n), read(A), read(B);
	for (int i = 1; i <= n; i++) read(s[i]);
	T1.set(1, 0, n, 0, 1);
	T2.set(1, 0, n, 0, 1);
	s[0] = -INF;
	int flagA0, flagB0;
	int la = 0, lb = 0;
	for (int i = 1; i <= n; i++) {
		flagA0 = flagB0 = 0;
		if (s[i] - s[i - 1] < A) flagA0 = 1;
		if (s[i] - s[i - 1] < B) flagB0 = 1;
		while (la + 1 <= i && s[i] - s[la + 1] >= A) la++;
		while (lb + 1 <= i && s[i] - s[lb + 1] >= B) lb++;
		int tmpA = T2.getsum(1, 0, n, 0, la);
		int tmpB = T1.getsum(1, 0, n, 0, lb);
		if (flagA0) T1.reset();
		if (flagB0) T2.reset();
		T1.set(1, 0, n, i - 1, tmpA);
		T2.set(1, 0, n, i - 1, tmpB);
	}
	int ans = (T1.getsum(1, 0, n, 0, n) + T2.getsum(1, 0, n, 0, n)) % mo;
	printf("%d\n", (ans + mo) % mo);
	return 0;
}

Submission Info

Submission Time
Task C - Division into Two
User cicada
Language C++14 (GCC 5.4.1)
Score 1100
Code Size 2215 Byte
Status AC
Exec Time 79 ms
Memory 7424 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1100 / 1100
Status
AC × 4
AC × 68
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, 61.txt, 62.txt, 63.txt, 64.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt AC 79 ms 7296 KB
02.txt AC 76 ms 7296 KB
03.txt AC 78 ms 7296 KB
04.txt AC 77 ms 7296 KB
05.txt AC 75 ms 7296 KB
06.txt AC 77 ms 7296 KB
07.txt AC 79 ms 7296 KB
08.txt AC 78 ms 7296 KB
09.txt AC 79 ms 7296 KB
10.txt AC 79 ms 7296 KB
11.txt AC 78 ms 7296 KB
12.txt AC 74 ms 7296 KB
13.txt AC 77 ms 7296 KB
14.txt AC 79 ms 7296 KB
15.txt AC 77 ms 7296 KB
16.txt AC 65 ms 7296 KB
17.txt AC 67 ms 7296 KB
18.txt AC 69 ms 7296 KB
19.txt AC 70 ms 7296 KB
20.txt AC 73 ms 7296 KB
21.txt AC 72 ms 7296 KB
22.txt AC 70 ms 7296 KB
23.txt AC 68 ms 7296 KB
24.txt AC 71 ms 7296 KB
25.txt AC 75 ms 7296 KB
26.txt AC 75 ms 7296 KB
27.txt AC 75 ms 7296 KB
28.txt AC 77 ms 7296 KB
29.txt AC 73 ms 7296 KB
30.txt AC 75 ms 7296 KB
31.txt AC 72 ms 7296 KB
32.txt AC 73 ms 7296 KB
33.txt AC 75 ms 7296 KB
34.txt AC 69 ms 7296 KB
35.txt AC 76 ms 7296 KB
36.txt AC 62 ms 7296 KB
37.txt AC 67 ms 7296 KB
38.txt AC 67 ms 7296 KB
39.txt AC 78 ms 7296 KB
40.txt AC 67 ms 7424 KB
41.txt AC 70 ms 7296 KB
42.txt AC 73 ms 7296 KB
43.txt AC 74 ms 7296 KB
44.txt AC 73 ms 7296 KB
45.txt AC 75 ms 7296 KB
46.txt AC 74 ms 7296 KB
47.txt AC 76 ms 7296 KB
48.txt AC 75 ms 7296 KB
49.txt AC 9 ms 6528 KB
50.txt AC 9 ms 6528 KB
51.txt AC 9 ms 6528 KB
52.txt AC 9 ms 6528 KB
53.txt AC 9 ms 6528 KB
54.txt AC 9 ms 6528 KB
55.txt AC 8 ms 6528 KB
56.txt AC 9 ms 6528 KB
57.txt AC 9 ms 6528 KB
58.txt AC 9 ms 6528 KB
59.txt AC 9 ms 6528 KB
60.txt AC 9 ms 6528 KB
61.txt AC 9 ms 6528 KB
62.txt AC 9 ms 6528 KB
63.txt AC 9 ms 6528 KB
64.txt AC 9 ms 6528 KB
s1.txt AC 9 ms 6528 KB
s2.txt AC 10 ms 6528 KB
s3.txt AC 9 ms 6528 KB
s4.txt AC 9 ms 6528 KB