Submission #2161033
Source Code Expand
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b) ((a >> b) & 1)
#define bitset(a,b) ( a |= (1 << b))
#define bitunset(a,b) (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#include <nmmintrin.h>
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
std::fill((T*)array, (T*)(array + N), val);
}
struct Edge {
int from, to;
};
template<class T, class OP, class PROP>
class Lazy_Segment_Tree {//0-indexed 半開
public:
vector<T> data, lazy;
vector<bool> isupd;
int n;
Lazy_Segment_Tree(int a) :n(1) {
while (n < a) n *= 2;
data.resize(n * 2 - 1);
lazy.resize(n * 2 - 1);
isupd.resize(n * 2 - 1);
}
void prop(int num, int s) {
if (isupd[num]) {
data[num] = PROP()(data[num], lazy[num], 1, s);
if (num < n - 1) {
lazy[num * 2 + 1] = PROP()(lazy[num * 2 + 1], lazy[num]);
lazy[num * 2 + 2] = PROP()(lazy[num * 2 + 2], lazy[num]);
isupd[num * 2 + 1] = 1;
isupd[num * 2 + 2] = 1;
}
lazy[num] = T();
isupd[num] = 0;
}
}
void op(int a, int b, T v, int num = 0, int base = 1) {
int l = (num + 1 - base) * (n / base), r = l + n / base;
prop(num, r - l);
if (a == l && b == r) {
isupd[num] = 1;
lazy[num] = PROP()(lazy[num], v);
prop(num, r - l);
}
else {
int nr = (l + r) / 2;
if (nr > a) op(a, min(b, nr), v, num * 2 + 1, base * 2);
if (nr < b) op(max(a, nr), b, v, num * 2 + 2, base * 2);
prop(num * 2 + 1, (r - l) / 2), prop(num * 2 + 2, (r - l) / 2);
data[num] = OP()(data[num * 2 + 1], data[num * 2 + 2]);
}
}
T query(int a, int b, int num = 0, int base = 1) {
int l = (num + 1 - base) * (n / base), r = l + n / base;
prop(num, r - l);
if (a == l && b == r)
return data[num];
else {
int nr = (l + r) / 2;
T ret = T();
if (nr > a) ret = OP()(ret, query(a, min(b, nr), num * 2 + 1, base * 2));
if (nr < b) ret = OP()(ret, query(max(a, nr), b, num * 2 + 2, base * 2));
return ret;
}
}
};
template<class T>
class ADD {
public:
T operator ()(const T a, const T b, const int ra = 1, int rb = 1) {
return a*ra + b*rb;
}
};
template<class T>
class UPD {
public:
T operator ()(const T a, const T b, const int ra = 1, int rb = 1) {
return b;
}
};
template<class T>
class RMQ {
public:
T operator ()(const T a, const T b) {
return min(a, b);
}
};
template<class T>
class SUM {
public:
T operator ()(const T a, const T b) {
return a + b;
}
};
struct N {
public:
ll num;
N(ll num) : num(num%MODU) {}
N() :num(0) {}
N operator + (const N obj) const {
return N(obj.num + num);
}
N operator * (const N obj) const {
return N(obj.num * num);
}
bool operator < (const N obj)const {
return obj.num > num;
}
};
int main() {
int n, a, b;
cin >> n >> a >> b;
if (a < b) swap(a, b);
vector<ll> num(n);
REP(i, n) {
scanf("%lld", &num[i]);
}
vector<int> cb(n, 1),ca(n,1);
REP(i, n - 1) {
if (num[i] + b <= num[i + 1]) {
cb[i + 1] = cb[i] + 1;
}
}
for (int i = n - 1; 0 < i; i--) {
if (num[i-1] + a <= num[i]) {
ca[i - 1] = ca[i] + 1;
}
}
Lazy_Segment_Tree<N, SUM<N>, ADD<N>> seg(n + 1);
seg.op(0, ca[0] + 1,1);
rep(i, 1, n-1) {
if (num[i + 1] - num[i - 1] < b) {
continue;
}
int l = i-cb[i-1],r = upper_bound(num.begin(),num.begin() + i, num[i]-a) - num.begin();
ll sum = seg.query(l,r + 1).num;
seg.op(i + 1, i + 1 + ca[i], sum);
}
int l = n-1 - cb[n - 2], r = upper_bound(num.begin(), num.begin() + n-1, num[n-1]-a) - num.begin();
ll sum = seg.query(l, r + 1).num;
sum += seg.query(n-cb[n - 1],n).num;
sum += seg.query(n,n+1).num;
sum %= MODU;
cout << sum << endl;
return 0;
}
Submission Info
Submission Time
2018-03-04 23:44:29+0900
Task
C - Division into Two
User
Gear
Language
C++14 (GCC 5.4.1)
Score
0
Code Size
4973 Byte
Status
WA
Exec Time
181 ms
Memory
5888 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:179:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &num[i]);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
0 / 1100
Status
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
WA
135 ms
5888 KB
02.txt
WA
180 ms
5888 KB
03.txt
WA
178 ms
5888 KB
04.txt
WA
177 ms
5888 KB
05.txt
WA
146 ms
5888 KB
06.txt
WA
171 ms
5888 KB
07.txt
WA
135 ms
5888 KB
08.txt
WA
155 ms
5888 KB
09.txt
WA
178 ms
5888 KB
10.txt
WA
178 ms
5888 KB
11.txt
WA
173 ms
5888 KB
12.txt
WA
145 ms
5888 KB
13.txt
WA
135 ms
5888 KB
14.txt
WA
181 ms
5888 KB
15.txt
WA
177 ms
5888 KB
16.txt
AC
63 ms
5888 KB
17.txt
AC
65 ms
5888 KB
18.txt
WA
78 ms
5888 KB
19.txt
AC
65 ms
5888 KB
20.txt
WA
72 ms
5888 KB
21.txt
WA
74 ms
5888 KB
22.txt
WA
70 ms
5888 KB
23.txt
WA
70 ms
5888 KB
24.txt
WA
71 ms
5888 KB
25.txt
WA
77 ms
5888 KB
26.txt
WA
76 ms
5888 KB
27.txt
WA
76 ms
5888 KB
28.txt
WA
74 ms
5888 KB
29.txt
AC
73 ms
5888 KB
30.txt
WA
73 ms
5888 KB
31.txt
AC
71 ms
5888 KB
32.txt
WA
70 ms
5888 KB
33.txt
WA
80 ms
5888 KB
34.txt
WA
64 ms
5888 KB
35.txt
WA
79 ms
5888 KB
36.txt
WA
138 ms
5888 KB
37.txt
AC
74 ms
5888 KB
38.txt
AC
73 ms
5888 KB
39.txt
WA
178 ms
5888 KB
40.txt
AC
68 ms
5888 KB
41.txt
AC
68 ms
5888 KB
42.txt
WA
62 ms
5888 KB
43.txt
WA
135 ms
5888 KB
44.txt
WA
155 ms
5888 KB
45.txt
WA
148 ms
5888 KB
46.txt
WA
150 ms
5888 KB
47.txt
WA
137 ms
5888 KB
48.txt
WA
133 ms
5888 KB
49.txt
WA
1 ms
256 KB
50.txt
AC
1 ms
256 KB
51.txt
AC
1 ms
256 KB
52.txt
WA
1 ms
256 KB
53.txt
WA
1 ms
256 KB
54.txt
AC
1 ms
256 KB
55.txt
AC
1 ms
256 KB
56.txt
AC
1 ms
256 KB
57.txt
AC
1 ms
256 KB
58.txt
AC
1 ms
256 KB
59.txt
AC
1 ms
256 KB
60.txt
AC
1 ms
256 KB
61.txt
AC
1 ms
256 KB
62.txt
AC
1 ms
256 KB
63.txt
AC
1 ms
256 KB
64.txt
AC
1 ms
256 KB
s1.txt
AC
1 ms
256 KB
s2.txt
AC
1 ms
256 KB
s3.txt
AC
1 ms
256 KB
s4.txt
AC
1 ms
256 KB