Submission #847459
Source Code Expand
Copy
//In the name of Allah #include <bits/stdc++.h> using namespace std; const int maxN = 1000 * 100 + 100; typedef long long ll; ll a[maxN]; ll z[maxN]; ll pref[maxN]; ll ans[maxN]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n,q; cin >> n >> q; a[0] = n; int en = 1; for( int i = 0 ; i < q ; i++ ) { ll x; cin >> x; while( en > 0 && a[en-1] >= x ) en--; a[en++] = x; } q = en; z[q-1] = 1; for( int i = q - 1 ; i > 0 ; i-- ) { ll d = a[i] / a[i-1]; z[i-1] += d * z[i]; ll rem = a[i] % a[i-1]; while( rem > a[0] ) { int ind = upper_bound( a , a + i , rem ) - a - 1; z[ind] += rem / a[ind] * z[i]; rem = rem % a[ind]; //cerr << "H " << rem << endl; } //cerr << " ! " << rem << endl; pref[rem]+= z[i]; } for( int i = n - 1 ; i >= 0 ; i-- ) { pref[i] += pref[i+1]; ans[i] = pref[i+1] + z[0]; if( i >= a[0] ) ans[i] = 0; } for( int i = 0 ; i < n ; i++ ) cout << ans[i] << '\n'; }
Submission Info
Submission Time | |
---|---|
Task | E - Sequential operations on Sequence |
User | LiTi |
Language | C++14 (GCC 5.4.1) |
Score | 1400 |
Code Size | 1028 Byte |
Status | AC |
Exec Time | 97 ms |
Memory | 4864 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1400 / 1400 | ||||
Status |
|
|
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 | 54 ms | 3072 KB |
02.txt | AC | 55 ms | 3200 KB |
03.txt | AC | 55 ms | 3200 KB |
04.txt | AC | 55 ms | 3200 KB |
05.txt | AC | 57 ms | 3200 KB |
06.txt | AC | 69 ms | 4736 KB |
07.txt | AC | 72 ms | 4864 KB |
08.txt | AC | 70 ms | 4864 KB |
09.txt | AC | 76 ms | 4736 KB |
10.txt | AC | 69 ms | 4736 KB |
11.txt | AC | 65 ms | 4864 KB |
12.txt | AC | 73 ms | 4736 KB |
13.txt | AC | 77 ms | 4864 KB |
14.txt | AC | 67 ms | 4736 KB |
15.txt | AC | 66 ms | 4736 KB |
16.txt | AC | 70 ms | 4736 KB |
17.txt | AC | 72 ms | 4864 KB |
18.txt | AC | 69 ms | 4736 KB |
19.txt | AC | 64 ms | 4736 KB |
20.txt | AC | 73 ms | 4864 KB |
21.txt | AC | 97 ms | 3584 KB |
22.txt | AC | 63 ms | 4480 KB |
23.txt | AC | 81 ms | 4736 KB |
24.txt | AC | 49 ms | 4736 KB |
25.txt | AC | 48 ms | 4608 KB |
26.txt | AC | 39 ms | 3584 KB |
27.txt | AC | 31 ms | 2048 KB |
28.txt | AC | 31 ms | 2048 KB |
29.txt | AC | 31 ms | 2048 KB |
30.txt | AC | 32 ms | 2048 KB |
31.txt | AC | 4 ms | 256 KB |
32.txt | AC | 17 ms | 2048 KB |
33.txt | AC | 4 ms | 256 KB |
34.txt | AC | 26 ms | 3328 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 |