Submission #847656


Source Code Expand

Copy
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

typedef pair<ll,ll> PLL;

const int MAXN=100050;
const int MAXQ=100050;
vector<ll> q;

ll ans[MAXN];

int main() {
	int N, Q; scanf("%d%d",&N,&Q);
	q.PB(N);
	for(int i=0;i<Q;i++) {
		debug("i=%d\n",i);
		ll in;
		scanf("%lld",&in);
		while(SZ(q)>0 && q.back()>=in) q.pop_back();
		q.PB(in);
	}
	priority_queue<PLL> pq;
	pq.push(MP(q.back(), 1));
	for(int i=SZ(q)-1;i>=0;i--) {
		debug("q[%d]=%lld\n",i,q[i]);
		ll cnt=0;
		while(SZ(pq)>0 && pq.top().F>q[i]) {
			auto p=pq.top(); pq.pop();
			debug("SZ:%d [%lld, %lld]\n",SZ(pq),p.F,p.S);
			cnt+=(p.F/q[i])*p.S;
			if(ll t=p.F%q[i]) {
				debug("push: %lld,%lld\n",t,p.S);
				pq.push( MP(t, 1*p.S) );
			}
		}
		if(cnt) pq.push( MP(q[i], cnt) );
	}
	while(!pq.empty()) {
		auto p=pq.top(); pq.pop();
		debug("-- [%lld, %lld]\n",p.F,p.S);
		ans[1]+=p.S;
		ans[p.F+1]-=p.S;
	}
	for(int i=1;i<=N;i++) ans[i]+=ans[i-1];
	for(int i=1;i<=N;i++) printf("%lld\n",ans[i]);
	return 0;
}

Submission Info

Submission Time
Task E - Sequential operations on Sequence
User t1016d
Language C++14 (GCC 5.4.1)
Score 1400
Code Size 1350 Byte
Status AC
Exec Time 243 ms
Memory 4976 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:27:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  int N, Q; scanf("%d%d",&N,&Q);
                               ^
./Main.cpp:32:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&in);
                    ^

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 58 ms 2304 KB
02.txt AC 61 ms 2432 KB
03.txt AC 59 ms 2432 KB
04.txt AC 60 ms 2432 KB
05.txt AC 59 ms 2432 KB
06.txt AC 154 ms 4848 KB
07.txt AC 177 ms 4976 KB
08.txt AC 169 ms 4976 KB
09.txt AC 186 ms 4848 KB
10.txt AC 156 ms 4848 KB
11.txt AC 145 ms 4976 KB
12.txt AC 178 ms 4848 KB
13.txt AC 182 ms 4976 KB
14.txt AC 153 ms 4848 KB
15.txt AC 150 ms 4848 KB
16.txt AC 166 ms 4848 KB
17.txt AC 170 ms 4976 KB
18.txt AC 156 ms 4848 KB
19.txt AC 143 ms 4848 KB
20.txt AC 168 ms 4976 KB
21.txt AC 243 ms 3696 KB
22.txt AC 143 ms 4592 KB
23.txt AC 183 ms 4848 KB
24.txt AC 101 ms 4848 KB
25.txt AC 99 ms 4720 KB
26.txt AC 90 ms 3696 KB
27.txt AC 36 ms 1152 KB
28.txt AC 35 ms 1152 KB
29.txt AC 35 ms 1152 KB
30.txt AC 37 ms 1152 KB
31.txt AC 4 ms 256 KB
32.txt AC 19 ms 1152 KB
33.txt AC 4 ms 256 KB
34.txt AC 28 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