# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
204046 |
2020-02-24T01:41:56 Z |
savacska |
Fire (JOI20_ho_t5) |
C++14 |
|
974 ms |
21320 KB |
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
const int CS = 550;
ll summa[200005], pref[200005], answer[200005], smallsum[200005];
int mas[200005], maxim[200005];
vector <pair <int, int> > zapr[200005];
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0);
int n, quer;
cin >> n >> quer;
for (int i = 1; i <= n; i++) cin >> mas[i];
for (int i = 1; i <= quer; i++)
{
int tim, lef, rig;
cin >> tim >> lef >> rig;
zapr[rig].pb(mp(tim, i));
zapr[lef - 1].pb(mp(tim, -i));
}
for (int i = 1; i <= (n - 1) / CS + 1; i++)
{
int lef = (i - 1) * CS + 1, rig = min(n, i * CS);
for (int j = 0; j <= n; j++) summa[j] = 0;
for (int j = 0; j <= CS; j++) smallsum[j] = 0;
int uk = lef, tekmax = mas[lef], cur = mas[lef - 1];
for (int j = lef - 1; j >= 1; j--)
{
cur = max(cur, mas[j]);
maxim[j] = cur;
while (uk <= rig && tekmax < cur)
{
uk++;
tekmax = max(tekmax, mas[uk]);
}
summa[lef - j] += (ll) cur, summa[uk - j] -= (ll) cur;
}
for (int j = 0; j >= lef - n; j--)
{
summa[lef - j] += (ll) cur;
summa[min(uk - j, n + 1)] -= (ll) cur;
}
uk = lef - 1, tekmax = mas[lef - 1], cur = mas[lef];
for (int j = lef; j <= rig; j++)
{
cur = max(cur, mas[j]);
maxim[j] = cur;
while (uk > 0 && tekmax <= cur)
{
uk--;
tekmax = max(tekmax, mas[uk]);
}
if (uk == 0) summa[j - uk] += (ll) cur, summa[n + 1] -= (ll) cur;
summa[j - lef + 1] += (ll) cur, summa[j - uk] -= (ll) cur;
}
for (int j = 1; j <= n; j++) summa[j] += summa[j - 1];
for (int j = lef; j <= rig; j++)
{
int mx = mas[j];
for (int z = j; z >= lef; z--)
{
mx = max(mx, mas[z]);
smallsum[j - z] += (ll) mx;
summa[j - z] += (ll) mx;
}
for (int z = 0; z < (int) zapr[j].size(); z++)
{
int tim = zapr[j][z].x, num = zapr[j][z].y;
if (num > 0) answer[num] += pref[tim];
else answer[-num] -= pref[tim];
ll ans = 0;
if (tim <= CS)
{
for (int k = lef; k <= min (j, lef + tim - 1); k++) ans += (ll) max(maxim[k], maxim[max(k - tim, 1)]);
if (j - tim >= lef) ans += smallsum[tim];
}
else
{
for (int k = lef; k <= j; k++) ans += (ll) max(maxim[k], maxim[max(k - tim, 1)]);
}
if (num > 0) answer[num] += ans;
else answer[-num] -= ans;
}
}
for (int j = 0; j <= n; j++) pref[j] += summa[j];
}
for (int i = 1; i <= quer; i++) cout << answer[i] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5112 KB |
Output is correct |
2 |
Correct |
7 ms |
5112 KB |
Output is correct |
3 |
Correct |
8 ms |
5112 KB |
Output is correct |
4 |
Correct |
7 ms |
5112 KB |
Output is correct |
5 |
Correct |
7 ms |
5112 KB |
Output is correct |
6 |
Correct |
7 ms |
5112 KB |
Output is correct |
7 |
Correct |
8 ms |
5112 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
7 ms |
5112 KB |
Output is correct |
10 |
Correct |
7 ms |
5112 KB |
Output is correct |
11 |
Correct |
8 ms |
5112 KB |
Output is correct |
12 |
Correct |
8 ms |
5112 KB |
Output is correct |
13 |
Correct |
8 ms |
5112 KB |
Output is correct |
14 |
Correct |
8 ms |
5092 KB |
Output is correct |
15 |
Correct |
8 ms |
5112 KB |
Output is correct |
16 |
Correct |
8 ms |
5112 KB |
Output is correct |
17 |
Correct |
8 ms |
5112 KB |
Output is correct |
18 |
Correct |
8 ms |
5112 KB |
Output is correct |
19 |
Correct |
8 ms |
5112 KB |
Output is correct |
20 |
Correct |
7 ms |
5112 KB |
Output is correct |
21 |
Correct |
7 ms |
5112 KB |
Output is correct |
22 |
Correct |
7 ms |
5112 KB |
Output is correct |
23 |
Correct |
8 ms |
5112 KB |
Output is correct |
24 |
Correct |
8 ms |
5112 KB |
Output is correct |
25 |
Correct |
8 ms |
5116 KB |
Output is correct |
26 |
Correct |
8 ms |
5112 KB |
Output is correct |
27 |
Correct |
8 ms |
5112 KB |
Output is correct |
28 |
Correct |
8 ms |
5112 KB |
Output is correct |
29 |
Correct |
7 ms |
5116 KB |
Output is correct |
30 |
Correct |
8 ms |
5112 KB |
Output is correct |
31 |
Correct |
7 ms |
5112 KB |
Output is correct |
32 |
Correct |
9 ms |
5240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5112 KB |
Output is correct |
2 |
Correct |
911 ms |
20676 KB |
Output is correct |
3 |
Correct |
909 ms |
20600 KB |
Output is correct |
4 |
Correct |
911 ms |
20856 KB |
Output is correct |
5 |
Correct |
930 ms |
20756 KB |
Output is correct |
6 |
Correct |
919 ms |
20856 KB |
Output is correct |
7 |
Correct |
922 ms |
20984 KB |
Output is correct |
8 |
Correct |
934 ms |
20856 KB |
Output is correct |
9 |
Correct |
931 ms |
21164 KB |
Output is correct |
10 |
Correct |
893 ms |
20856 KB |
Output is correct |
11 |
Correct |
939 ms |
21320 KB |
Output is correct |
12 |
Correct |
911 ms |
20552 KB |
Output is correct |
13 |
Correct |
925 ms |
21024 KB |
Output is correct |
14 |
Correct |
924 ms |
20648 KB |
Output is correct |
15 |
Correct |
913 ms |
20804 KB |
Output is correct |
16 |
Correct |
901 ms |
20960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5112 KB |
Output is correct |
2 |
Correct |
903 ms |
20228 KB |
Output is correct |
3 |
Correct |
875 ms |
19964 KB |
Output is correct |
4 |
Correct |
903 ms |
20344 KB |
Output is correct |
5 |
Correct |
883 ms |
19832 KB |
Output is correct |
6 |
Correct |
878 ms |
20300 KB |
Output is correct |
7 |
Correct |
866 ms |
19960 KB |
Output is correct |
8 |
Correct |
892 ms |
20084 KB |
Output is correct |
9 |
Correct |
879 ms |
19960 KB |
Output is correct |
10 |
Correct |
858 ms |
19832 KB |
Output is correct |
11 |
Correct |
906 ms |
20404 KB |
Output is correct |
12 |
Correct |
894 ms |
19900 KB |
Output is correct |
13 |
Correct |
896 ms |
20268 KB |
Output is correct |
14 |
Correct |
868 ms |
19992 KB |
Output is correct |
15 |
Correct |
897 ms |
20100 KB |
Output is correct |
16 |
Correct |
889 ms |
19816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
916 ms |
19064 KB |
Output is correct |
2 |
Correct |
952 ms |
18936 KB |
Output is correct |
3 |
Correct |
974 ms |
19192 KB |
Output is correct |
4 |
Correct |
914 ms |
19064 KB |
Output is correct |
5 |
Correct |
933 ms |
19068 KB |
Output is correct |
6 |
Correct |
922 ms |
18920 KB |
Output is correct |
7 |
Correct |
952 ms |
19192 KB |
Output is correct |
8 |
Correct |
944 ms |
19236 KB |
Output is correct |
9 |
Correct |
911 ms |
19064 KB |
Output is correct |
10 |
Correct |
950 ms |
18936 KB |
Output is correct |
11 |
Correct |
946 ms |
19320 KB |
Output is correct |
12 |
Correct |
941 ms |
19320 KB |
Output is correct |
13 |
Correct |
928 ms |
19276 KB |
Output is correct |
14 |
Correct |
921 ms |
19332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5112 KB |
Output is correct |
2 |
Correct |
7 ms |
5112 KB |
Output is correct |
3 |
Correct |
8 ms |
5112 KB |
Output is correct |
4 |
Correct |
7 ms |
5112 KB |
Output is correct |
5 |
Correct |
7 ms |
5112 KB |
Output is correct |
6 |
Correct |
7 ms |
5112 KB |
Output is correct |
7 |
Correct |
8 ms |
5112 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
7 ms |
5112 KB |
Output is correct |
10 |
Correct |
7 ms |
5112 KB |
Output is correct |
11 |
Correct |
8 ms |
5112 KB |
Output is correct |
12 |
Correct |
8 ms |
5112 KB |
Output is correct |
13 |
Correct |
8 ms |
5112 KB |
Output is correct |
14 |
Correct |
8 ms |
5092 KB |
Output is correct |
15 |
Correct |
8 ms |
5112 KB |
Output is correct |
16 |
Correct |
8 ms |
5112 KB |
Output is correct |
17 |
Correct |
8 ms |
5112 KB |
Output is correct |
18 |
Correct |
8 ms |
5112 KB |
Output is correct |
19 |
Correct |
8 ms |
5112 KB |
Output is correct |
20 |
Correct |
7 ms |
5112 KB |
Output is correct |
21 |
Correct |
7 ms |
5112 KB |
Output is correct |
22 |
Correct |
7 ms |
5112 KB |
Output is correct |
23 |
Correct |
8 ms |
5112 KB |
Output is correct |
24 |
Correct |
8 ms |
5112 KB |
Output is correct |
25 |
Correct |
8 ms |
5116 KB |
Output is correct |
26 |
Correct |
8 ms |
5112 KB |
Output is correct |
27 |
Correct |
8 ms |
5112 KB |
Output is correct |
28 |
Correct |
8 ms |
5112 KB |
Output is correct |
29 |
Correct |
7 ms |
5116 KB |
Output is correct |
30 |
Correct |
8 ms |
5112 KB |
Output is correct |
31 |
Correct |
7 ms |
5112 KB |
Output is correct |
32 |
Correct |
9 ms |
5240 KB |
Output is correct |
33 |
Correct |
902 ms |
20768 KB |
Output is correct |
34 |
Correct |
914 ms |
21112 KB |
Output is correct |
35 |
Correct |
932 ms |
20872 KB |
Output is correct |
36 |
Correct |
907 ms |
20888 KB |
Output is correct |
37 |
Correct |
885 ms |
20604 KB |
Output is correct |
38 |
Correct |
918 ms |
20796 KB |
Output is correct |
39 |
Correct |
901 ms |
20728 KB |
Output is correct |
40 |
Correct |
895 ms |
20856 KB |
Output is correct |
41 |
Correct |
915 ms |
20728 KB |
Output is correct |
42 |
Correct |
903 ms |
20856 KB |
Output is correct |
43 |
Correct |
935 ms |
21112 KB |
Output is correct |
44 |
Correct |
941 ms |
20980 KB |
Output is correct |
45 |
Correct |
888 ms |
20564 KB |
Output is correct |
46 |
Correct |
921 ms |
20856 KB |
Output is correct |
47 |
Correct |
893 ms |
20728 KB |
Output is correct |
48 |
Correct |
876 ms |
20572 KB |
Output is correct |
49 |
Correct |
911 ms |
20728 KB |
Output is correct |
50 |
Correct |
937 ms |
21112 KB |
Output is correct |
51 |
Correct |
909 ms |
20908 KB |
Output is correct |
52 |
Correct |
896 ms |
20856 KB |
Output is correct |
53 |
Correct |
907 ms |
20856 KB |
Output is correct |
54 |
Correct |
909 ms |
20600 KB |
Output is correct |
55 |
Correct |
897 ms |
20564 KB |
Output is correct |
56 |
Correct |
927 ms |
20868 KB |
Output is correct |
57 |
Correct |
898 ms |
20728 KB |
Output is correct |
58 |
Correct |
928 ms |
20984 KB |
Output is correct |
59 |
Correct |
911 ms |
20676 KB |
Output is correct |
60 |
Correct |
909 ms |
20600 KB |
Output is correct |
61 |
Correct |
911 ms |
20856 KB |
Output is correct |
62 |
Correct |
930 ms |
20756 KB |
Output is correct |
63 |
Correct |
919 ms |
20856 KB |
Output is correct |
64 |
Correct |
922 ms |
20984 KB |
Output is correct |
65 |
Correct |
934 ms |
20856 KB |
Output is correct |
66 |
Correct |
931 ms |
21164 KB |
Output is correct |
67 |
Correct |
893 ms |
20856 KB |
Output is correct |
68 |
Correct |
939 ms |
21320 KB |
Output is correct |
69 |
Correct |
911 ms |
20552 KB |
Output is correct |
70 |
Correct |
925 ms |
21024 KB |
Output is correct |
71 |
Correct |
924 ms |
20648 KB |
Output is correct |
72 |
Correct |
913 ms |
20804 KB |
Output is correct |
73 |
Correct |
901 ms |
20960 KB |
Output is correct |
74 |
Correct |
903 ms |
20228 KB |
Output is correct |
75 |
Correct |
875 ms |
19964 KB |
Output is correct |
76 |
Correct |
903 ms |
20344 KB |
Output is correct |
77 |
Correct |
883 ms |
19832 KB |
Output is correct |
78 |
Correct |
878 ms |
20300 KB |
Output is correct |
79 |
Correct |
866 ms |
19960 KB |
Output is correct |
80 |
Correct |
892 ms |
20084 KB |
Output is correct |
81 |
Correct |
879 ms |
19960 KB |
Output is correct |
82 |
Correct |
858 ms |
19832 KB |
Output is correct |
83 |
Correct |
906 ms |
20404 KB |
Output is correct |
84 |
Correct |
894 ms |
19900 KB |
Output is correct |
85 |
Correct |
896 ms |
20268 KB |
Output is correct |
86 |
Correct |
868 ms |
19992 KB |
Output is correct |
87 |
Correct |
897 ms |
20100 KB |
Output is correct |
88 |
Correct |
889 ms |
19816 KB |
Output is correct |
89 |
Correct |
916 ms |
19064 KB |
Output is correct |
90 |
Correct |
952 ms |
18936 KB |
Output is correct |
91 |
Correct |
974 ms |
19192 KB |
Output is correct |
92 |
Correct |
914 ms |
19064 KB |
Output is correct |
93 |
Correct |
933 ms |
19068 KB |
Output is correct |
94 |
Correct |
922 ms |
18920 KB |
Output is correct |
95 |
Correct |
952 ms |
19192 KB |
Output is correct |
96 |
Correct |
944 ms |
19236 KB |
Output is correct |
97 |
Correct |
911 ms |
19064 KB |
Output is correct |
98 |
Correct |
950 ms |
18936 KB |
Output is correct |
99 |
Correct |
946 ms |
19320 KB |
Output is correct |
100 |
Correct |
941 ms |
19320 KB |
Output is correct |
101 |
Correct |
928 ms |
19276 KB |
Output is correct |
102 |
Correct |
921 ms |
19332 KB |
Output is correct |