Contest Duration: - (local time) (110 minutes) Back to Home

Submission #848198

Source Code Expand

Copy
```#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

typedef long long ll;

using namespace std;

const int MAXN = 1 << 18;
const int MOD = 1; // 1000 * 1000 * 1000 + 7;
const int INF = 2e9;
const double PI = acos(-1.0);

int main() {
#ifdef _MSC_VER
freopen("input.txt", "r", stdin);
#endif

int n, q;
while (cin >> n >> q) {
vector<ll> a(q);
for (int i = 0; i < q; i++) cin >> a[i];

vector<ll> old = a;
vector<ll> b;
b.push_back(n);
for (int i = 0; i < q; i++) {
while (!b.empty() && b.back() >= a[i]) b.pop_back();
if (b.empty() || a[i] % b.back() != 0) b.push_back(a[i]);
}
a = b;

vector<vector<pair<int, ll> > > e(n);
for (int i = 1; i < (int)b.size(); i++) {
ll x = b[i] - b[i - 1];
while (1) {
int id = lower_bound(b.begin(), b.begin() + i, x + 1) - b.begin() - 1;
if (id == -1) break;
e[id].push_back(make_pair(i, x / b[id]));
x %= b[id];
}
}
vector<ll> cnt(b.size());
cnt[(int)b.size() - 1] = old[q - 1] / b.back();
for (int i = (int)b.size() - 2; i >= 0; i--) {
cnt[i] = cnt[i + 1];
for (auto o : e[i]) {
cnt[i] += cnt[o.first] * o.second;
}
}

vector<ll> ans(n);
for (int i = 1; i < (int)b.size(); i++) {
ll x = b[i] - b[i - 1];
while (1) {
int id = lower_bound(b.begin(), b.begin() + i, x + 1) - b.begin() - 1;
if (id == -1) {
if (x) ans[x - 1] += cnt[i];
break;
}
x %= b[id];
}
}
ans[b[0] - 1] += cnt[0];

for (int i = n - 2; i >= 0; i--) {
ans[i] += ans[i + 1];
}

for (int i = 0; i < n; i++) cout << ans[i] << "\n";
cout << "\n";
}

return 0;
}```

#### Submission Info

Submission Time 2016-08-21 22:43:29+0900 E - Sequential operations on Sequence izban C++14 (GCC 5.4.1) 0 1967 Byte RE 237 ms 13408 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1400
Status
 AC × 2
 AC × 37 RE × 1
Set Name Test Cases
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
Case Name Status Exec Time Memory
01.txt AC 151 ms 6144 KB
02.txt AC 153 ms 6272 KB
03.txt AC 180 ms 6272 KB
04.txt AC 153 ms 6272 KB
05.txt AC 153 ms 6272 KB
06.txt AC 198 ms 11104 KB
07.txt AC 207 ms 12124 KB
08.txt AC 206 ms 11612 KB
09.txt AC 220 ms 13408 KB
10.txt AC 194 ms 10848 KB
11.txt AC 189 ms 10208 KB
12.txt AC 237 ms 12636 KB
13.txt AC 212 ms 13024 KB
14.txt AC 195 ms 10464 KB
15.txt AC 191 ms 10336 KB
16.txt AC 200 ms 11744 KB
17.txt AC 204 ms 11872 KB
18.txt AC 193 ms 10720 KB
19.txt AC 183 ms 9696 KB
20.txt AC 206 ms 11528 KB
21.txt AC 125 ms 5120 KB
22.txt AC 177 ms 11360 KB
23.txt AC 153 ms 6272 KB
24.txt AC 135 ms 7780 KB
25.txt AC 132 ms 7652 KB
26.txt AC 113 ms 6772 KB
27.txt AC 76 ms 5120 KB
28.txt AC 77 ms 5120 KB
29.txt AC 77 ms 5120 KB
30.txt AC 84 ms 5120 KB
31.txt AC 4 ms 256 KB
32.txt RE 208 ms 2560 KB
33.txt AC 4 ms 256 KB
34.txt AC 34 ms 4864 KB
35.txt AC 4 ms 256 KB
36.txt AC 4 ms 256 KB
s1.txt AC 4 ms 256 KB
s2.txt AC 4 ms 256 KB