Contest Duration: - (local time) (110 minutes) Back to Home

Submission #848263

Source Code Expand

Copy
```#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
// palindromic tree is better than splay tree!
#define lld I64d
#endif

struct /* ow the */ edge {
int v;
long long mult,rem;
edge() {}
edge(long long mult, int v, long long rem): v(v), mult(mult), rem(rem) {}
};

int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
int N,Q;
cin >> N >> Q;
vector<long long> L(Q+1);
vector< vector<edge> > E(Q+1);
vector< vector<long long> > RMQ(17,vector<long long>(Q+1,2e18));
L[0] =RMQ[0][0] =N;
for(int q =0; q < Q; q++) {
long long x;
cin >> x;
L[q+1] =RMQ[0][q+1] =x;
int cur =q+1;
for(int i =1; i < 17; i++) if(q+2 >= (1<<i)) RMQ[i][q+1] =min(RMQ[i-1][q+1],RMQ[i-1][q+1-(1<<(i-1))]);
while(x > 0) {
int nxt =cur-1;
for(int k =16; k >= 0; k--) if((1<<k) <= nxt+1 && RMQ[k][nxt] > x) nxt -=(1<<k);
/*			for(int i =cur-1; i >= 0; i--) if(L[i] < x) {
nxt =i;
break;}
*/
//			cout << x/L[nxt] << ".\n";
if(nxt == -1) {
E[q+1].push_back(edge(1,0,x));
break;}
E[q+1].push_back(edge(x/L[nxt],nxt,-1));
x =x%L[nxt];
cur =nxt;}
}
vector<long long> ans(N+1,0),mult(Q+1,0);
mult[Q] =1;
for(int q =Q; q > 0; q--)
ALL_THE(E[q],it) {
if(it->rem == -1) mult[it->v] +=mult[q]*(it->mult);
else ans[it->rem] +=mult[q];}
ans[N] +=mult[0];
for(int i =N; i >= 1; i--) ans[i-1] +=ans[i];
for(int i =1; i <= N; i++) cout << ans[i] << "\n";
return 0;}

// look at my code
// my code is amazing
```

#### Submission Info

Submission Time 2016-08-21 22:45:37+0900 E - Sequential operations on Sequence xellos C++14 (GCC 5.4.1) 1400 2252 Byte AC 352 ms 43504 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 352 ms 42992 KB
02.txt AC 345 ms 43376 KB
03.txt AC 339 ms 41584 KB
04.txt AC 341 ms 42224 KB
05.txt AC 345 ms 42608 KB
06.txt AC 207 ms 30704 KB
07.txt AC 232 ms 35440 KB
08.txt AC 221 ms 32496 KB
09.txt AC 235 ms 35440 KB
10.txt AC 210 ms 31472 KB
11.txt AC 212 ms 30704 KB
12.txt AC 242 ms 35440 KB
13.txt AC 231 ms 35440 KB
14.txt AC 213 ms 30960 KB
15.txt AC 205 ms 30576 KB
16.txt AC 225 ms 32496 KB
17.txt AC 225 ms 32624 KB
18.txt AC 215 ms 31088 KB
19.txt AC 210 ms 30576 KB
20.txt AC 221 ms 32880 KB
21.txt AC 295 ms 43504 KB
22.txt AC 209 ms 30320 KB
23.txt AC 257 ms 36720 KB
24.txt AC 170 ms 25840 KB
25.txt AC 169 ms 25712 KB
26.txt AC 161 ms 24688 KB
27.txt AC 117 ms 21616 KB
28.txt AC 123 ms 21616 KB
29.txt AC 126 ms 21616 KB
30.txt AC 127 ms 21616 KB
31.txt AC 4 ms 256 KB
32.txt AC 17 ms 1280 KB
33.txt AC 4 ms 256 KB
34.txt AC 24 ms 2560 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