Submission #847998


Source Code Expand

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


int main() {
	LL N,Q;
	cin >> N >> Q;
	vector<LL> pos;
	pos.push_back(0);
	pos.push_back(N);
	for(int i=0; i<Q; i++) {
		LL q;
		cin >> q;
		while(q <= pos.back())
			pos.pop_back();
		pos.push_back(q);
	}
	
//	vector<LL> nums;
	priority_queue<PII> num;
	LL mult = 1;
//	num.push(ma);
	for(int i=pos.size()-2; i>=1; i--) {
		assert(pos[i+1] > pos[i]);
		num.push(PII(pos[i+1] % pos[i], mult));
		
		mult = mult * (pos[i+1] / pos[i]);
		while(true) {
			if(num.empty()) break;
			if(num.top().first < pos[i]) break;
			PII cur = num.top(); num.pop();
			mult += (cur.first / pos[i]) * cur.second;
			num.push(PII(cur.first % pos[i], cur.second));	
		}
	}
	
	vector<LL> imos(N+1, 0);
	while(!num.empty()) {
		PII cur = num.top(); num.pop();
		if(cur.first>0)
			imos[cur.first-1] += cur.second;
	}
	for(int i=N-1; i>=0; i--) {
		imos[i] += imos[i+1];
	}
	for(int i=0; i<pos[1]; i++)
		imos[i] += mult;
	LL sum = 0;
	for(int i=0; i<N; i++) {
		cout << imos[i] << endl;
		sum += imos[i];
	}
	assert(sum == pos.back());
	
	return 0;
}

Submission Info

Submission Time
Task E - Sequential operations on Sequence
User tokoharu
Language C++14 (GCC 5.4.1)
Score 1400
Code Size 1184 Byte
Status AC
Exec Time 882 ms
Memory 4848 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 722 ms 2304 KB
02.txt AC 705 ms 2432 KB
03.txt AC 704 ms 2432 KB
04.txt AC 719 ms 2432 KB
05.txt AC 701 ms 2432 KB
06.txt AC 776 ms 4720 KB
07.txt AC 804 ms 4848 KB
08.txt AC 807 ms 4848 KB
09.txt AC 816 ms 4720 KB
10.txt AC 788 ms 4720 KB
11.txt AC 784 ms 4848 KB
12.txt AC 808 ms 4720 KB
13.txt AC 814 ms 4848 KB
14.txt AC 789 ms 4720 KB
15.txt AC 784 ms 4720 KB
16.txt AC 795 ms 4720 KB
17.txt AC 792 ms 4848 KB
18.txt AC 790 ms 4720 KB
19.txt AC 779 ms 4720 KB
20.txt AC 812 ms 4848 KB
21.txt AC 882 ms 3568 KB
22.txt AC 754 ms 4464 KB
23.txt AC 819 ms 4720 KB
24.txt AC 702 ms 4720 KB
25.txt AC 702 ms 4592 KB
26.txt AC 679 ms 3568 KB
27.txt AC 625 ms 1280 KB
28.txt AC 628 ms 1152 KB
29.txt AC 626 ms 1152 KB
30.txt AC 634 ms 1152 KB
31.txt AC 4 ms 256 KB
32.txt AC 584 ms 1280 KB
33.txt AC 4 ms 256 KB
34.txt AC 594 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