Submission #847951


Source Code Expand

Copy
// tested by Hightail: https://github.com/dj3500/hightail
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

const int N = 200200;
ll add[N], res[N];

int main () {
   IOS
   ll n, _q;
   cin >> n >> _q;
   vector<ll> queries = {n};
   ll start = n;
   FOR(i,_q) {
      ll query;
      cin >> query;
      while (!queries.empty() && queries.back() >= query) queries.pop_back();
      queries.pb(query);
   }
   n = queries[0];
   map<ll,ll,greater<ll>> m;
   m[queries.back()] = 1;
   while (!m.empty() && m.begin()->fi > n) {
      ll x = m.begin()->fi;
      ll krot = m.begin()->se;
      m.erase(m.begin());
      assert(!queries.empty());
      while (queries.back() >= x) queries.pop_back();
      assert(!queries.empty());
      ll y = queries.back();
      assert(x > y);
      m[y] += krot * (x / y);
      ll r = x % y;
      if (r > 0) {
         m[r] += krot;
      }
   }
   for (auto it : m) {
      ll x = it.fi, krot = it.se;
      assert(x <= n);
      assert(x > 0);
      add[x] += krot;
   }
   REPD(x,n,1) {
      res[x] = res[x+1] + add[x];
   }
   REP(x,1,start) cout << res[x] << '\n';
}

Submission Info

Submission Time
Task E - Sequential operations on Sequence
User dj3500
Language C++14 (GCC 5.4.1)
Score 1400
Code Size 2618 Byte
Status AC
Exec Time 271 ms
Memory 9844 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 56 ms 2304 KB
02.txt AC 57 ms 2432 KB
03.txt AC 56 ms 2432 KB
04.txt AC 57 ms 2432 KB
05.txt AC 56 ms 2432 KB
06.txt AC 187 ms 8820 KB
07.txt AC 220 ms 8948 KB
08.txt AC 200 ms 8948 KB
09.txt AC 204 ms 8820 KB
10.txt AC 185 ms 8820 KB
11.txt AC 176 ms 8948 KB
12.txt AC 206 ms 8820 KB
13.txt AC 210 ms 8948 KB
14.txt AC 184 ms 8820 KB
15.txt AC 178 ms 8820 KB
16.txt AC 190 ms 8820 KB
17.txt AC 198 ms 8948 KB
18.txt AC 192 ms 8820 KB
19.txt AC 170 ms 8820 KB
20.txt AC 194 ms 8948 KB
21.txt AC 271 ms 7412 KB
22.txt AC 270 ms 9844 KB
23.txt AC 204 ms 9460 KB
24.txt AC 62 ms 3444 KB
25.txt AC 60 ms 3316 KB
26.txt AC 50 ms 1400 KB
27.txt AC 30 ms 512 KB
28.txt AC 32 ms 1280 KB
29.txt AC 32 ms 1280 KB
30.txt AC 32 ms 1280 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 26 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