Submission #847412


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++ ) { 
		int 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 0
Code Size 1029 Byte
Status WA
Exec Time 33 ms
Memory 2944 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1400
Status
AC × 2
AC × 10
WA × 28
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 WA 21 ms 2432 KB
02.txt WA 22 ms 2432 KB
03.txt WA 21 ms 2432 KB
04.txt WA 22 ms 2432 KB
05.txt WA 22 ms 2432 KB
06.txt WA 22 ms 2432 KB
07.txt WA 25 ms 2432 KB
08.txt WA 23 ms 2432 KB
09.txt WA 21 ms 2432 KB
10.txt WA 22 ms 2432 KB
11.txt WA 22 ms 2432 KB
12.txt WA 22 ms 2432 KB
13.txt WA 22 ms 2432 KB
14.txt WA 22 ms 2432 KB
15.txt WA 22 ms 2432 KB
16.txt WA 22 ms 2432 KB
17.txt WA 21 ms 2432 KB
18.txt WA 22 ms 2432 KB
19.txt WA 22 ms 2432 KB
20.txt WA 22 ms 2432 KB
21.txt WA 20 ms 2048 KB
22.txt WA 23 ms 2432 KB
23.txt WA 22 ms 2432 KB
24.txt WA 29 ms 2944 KB
25.txt WA 29 ms 2944 KB
26.txt WA 30 ms 2816 KB
27.txt AC 32 ms 2048 KB
28.txt AC 32 ms 2048 KB
29.txt AC 32 ms 2048 KB
30.txt AC 33 ms 2048 KB
31.txt AC 4 ms 256 KB
32.txt AC 18 ms 2048 KB
33.txt AC 4 ms 256 KB
34.txt WA 21 ms 2432 KB
35.txt AC 4 ms 256 KB
36.txt WA 4 ms 256 KB
s1.txt AC 4 ms 256 KB
s2.txt AC 4 ms 256 KB