Submission #848807


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	int n;
	int q;
	cin >> n >> q;
	vector<LL > c;
	for(int i = 0; i < q; i++){
		LL a;
		cin >> a;
		c.push_back(a);
	}
	LL m = 2e18;
	vector<LL> b;
	for(int i = q-1; i >= 0; i--){
		if(c[i] < m){
			b.push_back(c[i]);
			m = c[i];
		}
	}
	if(n < m){
		b.push_back(n);
		m = n;
	}
	map<LL,LL> freq;
	freq[b[0]] = 1;
	//cout << b[0] << endl;
	for(int i = 1; i < b.size(); i++){
		/*for(map<LL,LL>::iterator it = freq.begin(); it != freq.end(); it++){
			cout << it->first << " " << it->second << endl;
		}*/
		while(freq.rbegin()->first > b[i]){
			LL d = freq.rbegin()->first;
			//cout << b[i] << " " << d << endl;
			LL a = freq.rbegin()->second;
			//cout << d << " " << a << " " << endl;
			freq[b[i]] += (d/b[i])*a;
			freq[d%b[i]] += a;
			freq[d] = 0;
			freq.erase(d);
		}
	}
	LL diff[n+5];
	for(int i = 0; i <= n+3; i++){
		diff[i] = 0;
	}
	/*for(map<LL,LL>::iterator it = freq.begin(); it != freq.end(); it++){
		cout << it->first << " " << it->second << endl;
	}*/
	while(!freq.empty() && freq.rbegin()->first > 0){
		LL d = freq.rbegin()->first;
		LL a = freq.rbegin()->second;
		diff[d] += a;
		freq[d] = 0;
		freq.erase(d);
	}
	for(int i = m; i >= 1; i--){
		diff[i] = diff[i] + diff[i+1];
	}
	for(int i = 1; i <= n; i++){
		cout << diff[i] << endl;
	}
}

Submission Info

Submission Time
Task E - Sequential operations on Sequence
User ksun48
Language C++14 (GCC 5.4.1)
Score 1400
Code Size 1413 Byte
Status AC
Exec Time 1072 ms
Memory 10228 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1400 / 1400
Status
AC × 2
AC × 38
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 848 ms 3188 KB
02.txt AC 857 ms 3316 KB
03.txt AC 733 ms 3316 KB
04.txt AC 850 ms 3316 KB
05.txt AC 710 ms 3316 KB
06.txt AC 913 ms 8820 KB
07.txt AC 1001 ms 8948 KB
08.txt AC 1001 ms 8948 KB
09.txt AC 936 ms 8820 KB
10.txt AC 1033 ms 8820 KB
11.txt AC 879 ms 8948 KB
12.txt AC 910 ms 8820 KB
13.txt AC 921 ms 8948 KB
14.txt AC 897 ms 8820 KB
15.txt AC 908 ms 8820 KB
16.txt AC 1042 ms 8820 KB
17.txt AC 1022 ms 8948 KB
18.txt AC 1027 ms 8820 KB
19.txt AC 908 ms 8820 KB
20.txt AC 929 ms 8948 KB
21.txt AC 1042 ms 8948 KB
22.txt AC 1072 ms 9844 KB
23.txt AC 956 ms 10228 KB
24.txt AC 818 ms 3956 KB
25.txt AC 745 ms 3828 KB
26.txt AC 693 ms 2932 KB
27.txt AC 679 ms 2164 KB
28.txt AC 722 ms 2164 KB
29.txt AC 699 ms 2164 KB
30.txt AC 652 ms 2164 KB
31.txt AC 4 ms 256 KB
32.txt AC 585 ms 1152 KB
33.txt AC 4 ms 256 KB
34.txt AC 597 ms 2432 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