ソースコード 拡げる

Copy
```#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

#ifdef __WIN32
#define LLFORMAT "I64"
#define Rand() ((rand() << 15) | rand())
#else
#define LLFORMAT "ll"
#define Rand() (rand())
#endif

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxlog = 70;
const int maxN = 100100, maxq = 100100;

int N, n;
LL a[maxq + 5];

struct data
{
LL num[maxN + 5];

data() { memset(num, 0, sizeof num); }

friend data operator+(const data &x, const data &y)
{
data ans;
REP(i, 0, N) ans.num[i] = x.num[i] + y.num[i];
return ans;
}

data &operator+=(const data &x)
{
REP(i, 0, N) num[i] += x.num[i];
return *this;
}

friend data operator*(const data &x, const LL &y)
{
data ans;
REP(i, 0, N) ans.num[i] = x.num[i] * y;
return ans;
}

data &operator*=(const LL &x)
{
REP(i, 0, N) num[i] *= x;
return *this;
}

void print()
{
REP(i, 0, N) debug("%lld ", num[i]);
}

};

int tot = 0;
data val[maxlog + 5];
LL len[maxlog + 5];

vector<LL> all;

inline data calc(int id)
{
if (!id)
{
data ret;
for (auto u : all) if (u > 0) ++ret.num[u - 1];
for (int i = N - 2; i >= 0; --i) ret.num[i] += ret.num[i + 1];
return ret;
}
LL cnt = 0;
for (auto &u : all)
{
cnt += u / len[id - 1];
u %= len[id - 1];
}
data ret = val[id - 1] * cnt;
ret += calc(id - 1);
return ret;
}

int main()
{
#ifdef matthew99
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int qn;
scanf("%d%d", &N, &qn);
LL x;
n = 0;
a[n++] = N;
REP(i, 0, qn)
{
scanf("%" LLFORMAT "d", &x);
while (n && a[n - 1] >= x) --n;
a[n++] = x;
}
int lst = 0;
REP(i, 0, a[0]) val[0].num[i] = 1;
len[0] = a[0];
++tot;
REP(i, 1, n)
{
if (!~lst || a[i] >= (a[lst] << 1) || (i == n - 1))
{
len[tot] = a[i];
val[tot] = calc(tot - 1);
val[tot] += val[tot - 1];
val[tot] *= a[i] / a[i - 1];
all.clear();
all.pb(a[i] % a[i - 1]);
val[tot] += calc(tot - 1);
++tot;
all.clear();
lst = i;
}
else all.pb(a[i] - a[i - 1]);
}
REP(i, 0, N) printf("%" LLFORMAT "d\n", val[tot - 1].num[i]);
return 0;
}
```

#### 提出情報

提出日時 2016-08-21 22:54:07+0900 E - Sequential operations on Sequence matthew99 C++14 (GCC 5.4.1) 0 2665 Byte WA 1519 ms 110204 KB

#### コンパイルエラー

```./Main.cpp: In function ‘int main()’:
./Main.cpp:107:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &qn);
^
./Main.cpp:113:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%" LLFORMAT "d", &x);
^
```

#### ジャッジ結果

セット名 Sample All

 AC × 2
 AC × 14 WA × 23 RE × 1
セット名 テストケース
Sample s1.txt, s2.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, s1.txt, s2.txt
ケース名 結果 実行時間 メモリ
01.txt WA 162 ms 66432 KB
02.txt WA 219 ms 71936 KB
03.txt WA 189 ms 69632 KB
04.txt WA 181 ms 68864 KB
05.txt WA 240 ms 74368 KB
06.txt WA 389 ms 81788 KB
07.txt WA 407 ms 81788 KB
08.txt WA 387 ms 81912 KB
09.txt WA 460 ms 84216 KB
10.txt WA 406 ms 81784 KB
11.txt WA 372 ms 81144 KB
12.txt WA 436 ms 82552 KB
13.txt WA 422 ms 82680 KB
14.txt WA 391 ms 81784 KB
15.txt WA 389 ms 81784 KB
16.txt WA 405 ms 81784 KB
17.txt WA 409 ms 81912 KB
18.txt WA 407 ms 81788 KB
19.txt WA 350 ms 79480 KB
20.txt WA 393 ms 81912 KB
21.txt AC 1519 ms 110204 KB
22.txt WA 593 ms 89212 KB
23.txt AC 878 ms 97276 KB
24.txt RE 313 ms 61312 KB
25.txt WA 888 ms 97664 KB
26.txt WA 1205 ms 104448 KB
27.txt AC 113 ms 59136 KB
28.txt AC 117 ms 59136 KB
29.txt AC 115 ms 59136 KB
30.txt AC 120 ms 61440 KB
31.txt AC 96 ms 58880 KB
32.txt AC 110 ms 59136 KB
33.txt AC 95 ms 58880 KB
34.txt AC 111 ms 62720 KB
35.txt AC 101 ms 61312 KB
36.txt AC 92 ms 62848 KB
s1.txt AC 87 ms 61184 KB
s2.txt AC 89 ms 62080 KB