Submission #3420448
Source Code Expand
#include<bits/stdc++.h> #define fi first #define se second #define LL long long #define mp make_pair #define pb push_back #define pii pair<LL, LL> using namespace std; const int N = 1e5 + 10; int n, m, top; LL a[N], st[N], tr[N]; map<LL, LL, greater<LL> > Map; void init() { cin >> n >> m; a[1] = n; for (int i = 2; i <= m + 1; ++i) scanf("%lld", &a[i]); st[top = 1] = a[1]; for (int i = 2; i <= m + 1; ++i) { while (st[top] >= a[i] && top) --top; st[++top] = a[i]; } m = top; for (int i = top; i >= 1; --i) { a[top - i + 1] = st[i]; } } void Updata(int x, LL del) { for (int i = x; i <= n; i += i & -i) { tr[i] += del; } } LL Query(int x) { LL ans = 0; for (int i = x; i; i -= i & -i) { ans += tr[i]; } return ans; } void Solve() { vector<pii> vec; map<LL,LL>::iterator it; Map[a[1]] = 1; for (int i = 2; i <= m; ++i) { vec.clear(); for (it = Map.begin(); it != Map.end();) { if (it -> fi <= a[i]) break; vec.pb(mp(a[i], it -> fi / a[i] * it -> se)); if (it -> fi % a[i]) vec.pb(mp(it -> fi % a[i], it -> se)); Map.erase(it++); } for (int j = 0; j < vec.size(); ++j) { Map[vec[j].fi] += vec[j].se; } } for (it = Map.begin(); it != Map.end(); ++it) { Updata(1, it -> se); Updata(it -> fi + 1, -it -> se); } for (int i = 1; i <= n; ++i) { LL tmp = Query(i); printf("%lld\n", tmp); } } int main() { init(); Solve(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Sequential operations on Sequence |
User | Vexoben |
Language | C++14 (GCC 5.4.1) |
Score | 1400 |
Code Size | 1484 Byte |
Status | AC |
Exec Time | 157 ms |
Memory | 13036 KB |
Compile Error
./Main.cpp: In function ‘void init()’: ./Main.cpp:19:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld", &a[i]); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1400 / 1400 | ||||
Status |
|
|
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 | 30 ms | 2432 KB |
02.txt | AC | 30 ms | 2560 KB |
03.txt | AC | 30 ms | 2560 KB |
04.txt | AC | 31 ms | 2560 KB |
05.txt | AC | 31 ms | 2560 KB |
06.txt | AC | 122 ms | 12396 KB |
07.txt | AC | 138 ms | 11756 KB |
08.txt | AC | 130 ms | 11884 KB |
09.txt | AC | 128 ms | 10864 KB |
10.txt | AC | 119 ms | 11376 KB |
11.txt | AC | 115 ms | 13036 KB |
12.txt | AC | 133 ms | 12908 KB |
13.txt | AC | 132 ms | 12524 KB |
14.txt | AC | 119 ms | 12396 KB |
15.txt | AC | 115 ms | 11500 KB |
16.txt | AC | 126 ms | 11244 KB |
17.txt | AC | 132 ms | 12140 KB |
18.txt | AC | 126 ms | 12268 KB |
19.txt | AC | 110 ms | 12012 KB |
20.txt | AC | 125 ms | 11884 KB |
21.txt | AC | 157 ms | 8320 KB |
22.txt | AC | 150 ms | 13036 KB |
23.txt | AC | 102 ms | 9472 KB |
24.txt | AC | 35 ms | 3584 KB |
25.txt | AC | 34 ms | 3328 KB |
26.txt | AC | 31 ms | 2048 KB |
27.txt | AC | 19 ms | 1280 KB |
28.txt | AC | 19 ms | 1280 KB |
29.txt | AC | 19 ms | 1280 KB |
30.txt | AC | 20 ms | 1280 KB |
31.txt | AC | 1 ms | 256 KB |
32.txt | AC | 10 ms | 512 KB |
33.txt | AC | 1 ms | 256 KB |
34.txt | AC | 13 ms | 1792 KB |
35.txt | AC | 1 ms | 256 KB |
36.txt | AC | 1 ms | 256 KB |
s1.txt | AC | 1 ms | 256 KB |
s2.txt | AC | 1 ms | 256 KB |