Submission #848222


Source Code Expand

Copy
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;


int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,q;
  cin>>n>>q;
  vector<ll> qs={n};
  rep(i,q){
    ll x;
    cin>>x;
    while(qs.size() && qs.back()>=x) qs.pop_back();
    qs.pb(x);
  }
  //cout<<qs;
  map<ll,ll> cnt;
  ll sum=qs.back();
  cnt[qs.back()]=1;
  rrep(i,qs.size()-1){
    map<ll,ll> tmp;
    for(auto it=cnt.lower_bound(qs[i]);it!=cnt.end();++it){
      tmp[it->X%qs[i]]+=it->Y;
      //cout<<*it<<"->"<<it->X%qs[i]<<endl;
      //cout<<sum<<"=>";
      sum-=it->X*it->Y;
      sum+=(it->X%qs[i])*it->Y;
      //cout<<sum<<endl;
    }
    cnt.erase(cnt.lower_bound(qs[i]),cnt.end());
    for(auto p:tmp) cnt[p.X]+=p.Y;
    cnt[qs[i]]+=(qs.back()-sum)/qs[i];
    //cout<<qs.back()-sum<<","<<qs[i]<<","<<(qs.back()-sum)%qs[i]<<endl;
    sum=qs.back();
    //  for(auto p:cnt) cout<<p;cout<<endl;
  }
  vector<ll> re(n+1);
  for(auto p:cnt) re[p.X]=p.Y;
  //cout<<re;
  ll s=accumulate(all(re),0ll);
  ll ast=0;
  rep(i,n){
    s-=re[i];
    cout<<s<<endl;
    ast+=s;
  }
  assert(ast==qs.back());
  return 0;
}

Submission Info

Submission Time
Task E - Sequential operations on Sequence
User nuip
Language C++14 (GCC 5.4.1)
Score 1400
Code Size 2580 Byte
Status AC
Exec Time 1001 ms
Memory 11636 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 618 ms 2304 KB
02.txt AC 629 ms 2432 KB
03.txt AC 617 ms 2432 KB
04.txt AC 677 ms 2432 KB
05.txt AC 726 ms 2432 KB
06.txt AC 866 ms 10612 KB
07.txt AC 954 ms 11636 KB
08.txt AC 973 ms 10996 KB
09.txt AC 842 ms 9076 KB
10.txt AC 805 ms 9844 KB
11.txt AC 791 ms 10740 KB
12.txt AC 943 ms 10356 KB
13.txt AC 858 ms 9588 KB
14.txt AC 892 ms 10612 KB
15.txt AC 801 ms 10484 KB
16.txt AC 822 ms 9844 KB
17.txt AC 844 ms 10484 KB
18.txt AC 826 ms 10740 KB
19.txt AC 786 ms 10612 KB
20.txt AC 1001 ms 10100 KB
21.txt AC 905 ms 7412 KB
22.txt AC 991 ms 11380 KB
23.txt AC 961 ms 8692 KB
24.txt AC 726 ms 3188 KB
25.txt AC 639 ms 3188 KB
26.txt AC 724 ms 2164 KB
27.txt AC 722 ms 1280 KB
28.txt AC 590 ms 1280 KB
29.txt AC 588 ms 1280 KB
30.txt AC 591 ms 1280 KB
31.txt AC 4 ms 256 KB
32.txt AC 570 ms 1280 KB
33.txt AC 4 ms 256 KB
34.txt AC 583 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