Submission #848092


Source Code Expand

Copy
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<ll, ll> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;

int main() {
  int n, Q;
  scanf("%d%d", &n, &Q);
  vl q(1, n);
  for (int i = 0; i < Q; ++i) {
    ll x;
    scanf("%lld", &x);
    while (!q.empty() && q.back() >= x) q.pop_back();
    q.push_back(x);
  }
//  vii v(q.back(), 1);
  map<ll, ll> v; v[q.back()] = 1;
  vii add;
  for (int i = q.size() - 2; i >= 0; --i) {
//    for (const auto & p : v) cerr << p.first << ' ' << p.second << endl;
    add.clear();
    ll m = q[i];
//    int it = lower_bound(v.begin(), v.end(), pii(m + 1, 0)) - v.begin();
    ll sm = 0;
    auto it = v.end(); --it;
    while (true) {
      if (it->first <= m) {
        ++it;
        v.erase(it, v.end());
        break;
      }
      sm += it->first / m * it->second;
      ll r = it->first % m;
      if (r) add.emplace_back(r, it->second);
      if (it == v.begin()) {
        v.clear(); break;
      }
      --it;
    }
    v[m] += sm;
    if (add.empty()) continue;
    sort(add.begin(), add.end());
    pii td(0, 0);
    for (const auto& p : add) {
      if (p.first == td.first) td.second += p.second;
      else {
        if (td.second) v[td.first] += td.second;
        td = p;
      }
    }
    v[td.first] += td.second;
  }
  vl d(n);
//  for (const auto & p : v) cerr << p.first << ' ' << p.second << endl;
  for (const auto & p : v) {
    d[p.first - 1] += p.second;
  }
  vl res(n);
  ll s = 0;
  for (int i = n-1; i >= 0; --i) {
    s += d[i];
    res[i] = s;
  }
  for (int i = 0; i < n; ++i) {
    printf("%lld\n", res[i]);
  }
  return 0;
}

Submission Info

Submission Time
Task E - Sequential operations on Sequence
User ariacas
Language C++14 (GCC 5.4.1)
Score 1400
Code Size 2173 Byte
Status AC
Exec Time 294 ms
Memory 11376 KB

Compile Error

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

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 62 ms 3072 KB
02.txt AC 60 ms 3200 KB
03.txt AC 61 ms 3200 KB
04.txt AC 61 ms 3200 KB
05.txt AC 61 ms 3200 KB
06.txt AC 193 ms 9968 KB
07.txt AC 252 ms 10096 KB
08.txt AC 215 ms 9968 KB
09.txt AC 246 ms 9844 KB
10.txt AC 211 ms 9968 KB
11.txt AC 195 ms 10096 KB
12.txt AC 221 ms 9840 KB
13.txt AC 251 ms 9968 KB
14.txt AC 192 ms 9968 KB
15.txt AC 193 ms 9968 KB
16.txt AC 220 ms 9968 KB
17.txt AC 208 ms 10096 KB
18.txt AC 213 ms 9968 KB
19.txt AC 198 ms 9972 KB
20.txt AC 225 ms 9968 KB
21.txt AC 294 ms 7412 KB
22.txt AC 282 ms 11376 KB
23.txt AC 202 ms 8692 KB
24.txt AC 74 ms 3956 KB
25.txt AC 72 ms 3828 KB
26.txt AC 64 ms 2932 KB
27.txt AC 36 ms 2048 KB
28.txt AC 37 ms 2048 KB
29.txt AC 37 ms 2048 KB
30.txt AC 38 ms 2048 KB
31.txt AC 4 ms 256 KB
32.txt AC 22 ms 2048 KB
33.txt AC 4 ms 256 KB
34.txt AC 30 ms 3328 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