# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
480106 |
2021-10-14T16:11:02 Z |
HynDuf |
Fire (JOI20_ho_t5) |
C++11 |
|
263 ms |
24340 KB |
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
const int MAX_N = 200000;
int N, Q;
int S[MAX_N+1];
struct ST{
int t, l, r, idx;
bool operator <(const ST &a)const{
return t<a.t;
}
};
vector<ST> vt;
struct SEG{
struct NODE{
int l, r;
int mx;
};
vector<NODE> seg;
int SZ;
void add(){
seg.pb({-1, -1, 0});
}
void Init(int x){
SZ = x;
add(); init(0, 1, SZ);
}
void init(int idx, int s, int e){
if(s==e) {
seg[idx].mx = S[s];
return;
}
seg[idx].l = seg.size(); add();
seg[idx].r = seg.size(); add();
init(seg[idx].l, s, (s+e)/2);
init(seg[idx].r, (s+e)/2+1, e);
seg[idx].mx = max(seg[seg[idx].l].mx, seg[seg[idx].r].mx);
}
int Mx(int x, int y){
return mx(0, 1, SZ, x, y);
}
int mx(int idx, int s, int e, int x, int y){
if(x>e || y<s) return 0;
if(x<=s && e<=y) return seg[idx].mx;
return max(mx(seg[idx].l, s, (s+e)/2, x, y), mx(seg[idx].r, (s+e)/2+1, e, x, y));
}
}Seg;
void solve1(){
Seg.Init(N);
for(int i=0; i<vt.size(); i++){
ST now = vt[i];
ll answer = 0;
for(int j=now.l; j<=now.r; j++){
answer += (ll)Seg.Mx(j-now.t, j);
}
printf("%lld\n", answer);
}
}
ll tree[MAX_N+1];
void upd(int x, ll y){
while(x<=N){
tree[x]+=y;
x+=(x&-x);
}
}
ll Sum(int x){
ll ret = 0;
while(x>0){
ret+=tree[x];
x-=(x&-x);
}
return ret;
}
void solve2(){
Seg.Init(N);
int T = vt[0].t;
for(int i=1; i<=N; i++){
upd(i, (ll)Seg.Mx(i-T, i));
}
for(int i=0; i<vt.size(); i++){
ST now = vt[i];
printf("%lld\n", Sum(now.r) - Sum(now.l-1));
}
}
void solve3(){
Seg.Init(N);
for(int i=0; i<vt.size(); i++){
ST now = vt[i];
printf("%lld\n", (ll)Seg.Mx(now.l-now.t, now.l));
}
}
ll ans[MAX_N+1];
vector<pii> v, v2;
void solve4(){
Seg.Init(N);
sort(vt.begin(), vt.end());
int T = 0;
for(int i=1; i<=N; i++){
upd(i, S[i]);
if(S[i]!=0){
v.pb({i, S[i]});
}
}
for(int i=0; i<vt.size(); i++){
ST now = vt[i];
while(T<now.t){
T++;
while(!v.empty()){
pii n = v.back(); v.pop_back();
if(n.first==N) continue;
if(S[n.first+1]<n.second){
upd(n.first+1, (ll)(n.second-S[n.first+1]));
S[n.first+1] = n.second;
v2.pb({n.first+1, n.second});
}
}
while(!v2.empty()){
v.pb(v2.back()); v2.pop_back();
}
}
ans[now.idx] = Sum(now.r) - Sum(now.l-1);
}
for(int i=1; i<=Q; i++){
printf("%lld\n", ans[i]);
}
}
int main(){
scanf("%d%d", &N, &Q);
for(int i=1; i<=N; i++){
scanf("%d", &S[i]);
}
bool tf2 = true, tf3 = true;
for(int i=1; i<=Q; i++){
int t, l, r; scanf("%d%d%d", &t, &l, &r);
vt.pb({t, l, r, i});
if(t!=vt[0].t) tf2 = false;
if(l!=r) tf3 = false;
}
if(N<=200 && Q<=200){
solve1();
}else if(tf2){
solve2();
}else if(tf3){
solve3();
}else{
solve4();
}
return 0;
}
Compilation message
ho_t5.cpp: In function 'void solve1()':
ho_t5.cpp:63:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ST>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i=0; i<vt.size(); i++){
| ~^~~~~~~~~~
ho_t5.cpp: In function 'void solve2()':
ho_t5.cpp:97:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ST>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for(int i=0; i<vt.size(); i++){
| ~^~~~~~~~~~
ho_t5.cpp: In function 'void solve3()':
ho_t5.cpp:105:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ST>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for(int i=0; i<vt.size(); i++){
| ~^~~~~~~~~~
ho_t5.cpp: In function 'void solve4()':
ho_t5.cpp:125:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ST>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
125 | for(int i=0; i<vt.size(); i++){
| ~^~~~~~~~~~
ho_t5.cpp: In function 'int main()':
ho_t5.cpp:149:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
149 | scanf("%d%d", &N, &Q);
| ~~~~~^~~~~~~~~~~~~~~~
ho_t5.cpp:151:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
151 | scanf("%d", &S[i]);
| ~~~~~^~~~~~~~~~~~~
ho_t5.cpp:155:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
155 | int t, l, r; scanf("%d%d%d", &t, &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
2 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
312 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
204 KB |
Output is correct |
26 |
Correct |
2 ms |
204 KB |
Output is correct |
27 |
Correct |
2 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
2 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
163 ms |
21788 KB |
Output is correct |
3 |
Correct |
162 ms |
21740 KB |
Output is correct |
4 |
Correct |
186 ms |
21892 KB |
Output is correct |
5 |
Correct |
185 ms |
21952 KB |
Output is correct |
6 |
Correct |
176 ms |
21532 KB |
Output is correct |
7 |
Correct |
181 ms |
21932 KB |
Output is correct |
8 |
Correct |
169 ms |
21916 KB |
Output is correct |
9 |
Correct |
178 ms |
22016 KB |
Output is correct |
10 |
Correct |
164 ms |
21800 KB |
Output is correct |
11 |
Correct |
179 ms |
22160 KB |
Output is correct |
12 |
Correct |
181 ms |
21564 KB |
Output is correct |
13 |
Correct |
187 ms |
21660 KB |
Output is correct |
14 |
Correct |
171 ms |
21780 KB |
Output is correct |
15 |
Correct |
165 ms |
21724 KB |
Output is correct |
16 |
Correct |
165 ms |
21660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
234 ms |
19496 KB |
Output is correct |
3 |
Correct |
197 ms |
19112 KB |
Output is correct |
4 |
Correct |
208 ms |
19692 KB |
Output is correct |
5 |
Correct |
181 ms |
19088 KB |
Output is correct |
6 |
Correct |
208 ms |
19228 KB |
Output is correct |
7 |
Correct |
191 ms |
19400 KB |
Output is correct |
8 |
Correct |
196 ms |
19332 KB |
Output is correct |
9 |
Correct |
198 ms |
19264 KB |
Output is correct |
10 |
Correct |
200 ms |
18956 KB |
Output is correct |
11 |
Correct |
205 ms |
19712 KB |
Output is correct |
12 |
Correct |
193 ms |
19260 KB |
Output is correct |
13 |
Correct |
190 ms |
19448 KB |
Output is correct |
14 |
Correct |
187 ms |
19184 KB |
Output is correct |
15 |
Correct |
195 ms |
19404 KB |
Output is correct |
16 |
Correct |
199 ms |
19200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
20428 KB |
Output is correct |
2 |
Correct |
148 ms |
20404 KB |
Output is correct |
3 |
Correct |
142 ms |
20840 KB |
Output is correct |
4 |
Correct |
177 ms |
20716 KB |
Output is correct |
5 |
Correct |
152 ms |
20816 KB |
Output is correct |
6 |
Correct |
147 ms |
20440 KB |
Output is correct |
7 |
Correct |
179 ms |
20636 KB |
Output is correct |
8 |
Correct |
144 ms |
20868 KB |
Output is correct |
9 |
Correct |
143 ms |
20632 KB |
Output is correct |
10 |
Correct |
152 ms |
20636 KB |
Output is correct |
11 |
Correct |
156 ms |
20868 KB |
Output is correct |
12 |
Correct |
154 ms |
20892 KB |
Output is correct |
13 |
Correct |
147 ms |
20612 KB |
Output is correct |
14 |
Correct |
149 ms |
20764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
2 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
312 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
204 KB |
Output is correct |
26 |
Correct |
2 ms |
204 KB |
Output is correct |
27 |
Correct |
2 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
2 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
163 ms |
21788 KB |
Output is correct |
34 |
Correct |
162 ms |
21740 KB |
Output is correct |
35 |
Correct |
186 ms |
21892 KB |
Output is correct |
36 |
Correct |
185 ms |
21952 KB |
Output is correct |
37 |
Correct |
176 ms |
21532 KB |
Output is correct |
38 |
Correct |
181 ms |
21932 KB |
Output is correct |
39 |
Correct |
169 ms |
21916 KB |
Output is correct |
40 |
Correct |
178 ms |
22016 KB |
Output is correct |
41 |
Correct |
164 ms |
21800 KB |
Output is correct |
42 |
Correct |
179 ms |
22160 KB |
Output is correct |
43 |
Correct |
181 ms |
21564 KB |
Output is correct |
44 |
Correct |
187 ms |
21660 KB |
Output is correct |
45 |
Correct |
171 ms |
21780 KB |
Output is correct |
46 |
Correct |
165 ms |
21724 KB |
Output is correct |
47 |
Correct |
165 ms |
21660 KB |
Output is correct |
48 |
Correct |
234 ms |
19496 KB |
Output is correct |
49 |
Correct |
197 ms |
19112 KB |
Output is correct |
50 |
Correct |
208 ms |
19692 KB |
Output is correct |
51 |
Correct |
181 ms |
19088 KB |
Output is correct |
52 |
Correct |
208 ms |
19228 KB |
Output is correct |
53 |
Correct |
191 ms |
19400 KB |
Output is correct |
54 |
Correct |
196 ms |
19332 KB |
Output is correct |
55 |
Correct |
198 ms |
19264 KB |
Output is correct |
56 |
Correct |
200 ms |
18956 KB |
Output is correct |
57 |
Correct |
205 ms |
19712 KB |
Output is correct |
58 |
Correct |
193 ms |
19260 KB |
Output is correct |
59 |
Correct |
190 ms |
19448 KB |
Output is correct |
60 |
Correct |
187 ms |
19184 KB |
Output is correct |
61 |
Correct |
195 ms |
19404 KB |
Output is correct |
62 |
Correct |
199 ms |
19200 KB |
Output is correct |
63 |
Correct |
185 ms |
20428 KB |
Output is correct |
64 |
Correct |
148 ms |
20404 KB |
Output is correct |
65 |
Correct |
142 ms |
20840 KB |
Output is correct |
66 |
Correct |
177 ms |
20716 KB |
Output is correct |
67 |
Correct |
152 ms |
20816 KB |
Output is correct |
68 |
Correct |
147 ms |
20440 KB |
Output is correct |
69 |
Correct |
179 ms |
20636 KB |
Output is correct |
70 |
Correct |
144 ms |
20868 KB |
Output is correct |
71 |
Correct |
143 ms |
20632 KB |
Output is correct |
72 |
Correct |
152 ms |
20636 KB |
Output is correct |
73 |
Correct |
156 ms |
20868 KB |
Output is correct |
74 |
Correct |
154 ms |
20892 KB |
Output is correct |
75 |
Correct |
147 ms |
20612 KB |
Output is correct |
76 |
Correct |
149 ms |
20764 KB |
Output is correct |
77 |
Correct |
226 ms |
23792 KB |
Output is correct |
78 |
Correct |
240 ms |
24192 KB |
Output is correct |
79 |
Correct |
234 ms |
23936 KB |
Output is correct |
80 |
Correct |
214 ms |
23824 KB |
Output is correct |
81 |
Correct |
248 ms |
23828 KB |
Output is correct |
82 |
Correct |
229 ms |
23916 KB |
Output is correct |
83 |
Correct |
218 ms |
23796 KB |
Output is correct |
84 |
Correct |
263 ms |
23840 KB |
Output is correct |
85 |
Correct |
227 ms |
23812 KB |
Output is correct |
86 |
Correct |
233 ms |
23988 KB |
Output is correct |
87 |
Correct |
218 ms |
24284 KB |
Output is correct |
88 |
Correct |
227 ms |
24048 KB |
Output is correct |
89 |
Correct |
208 ms |
23756 KB |
Output is correct |
90 |
Correct |
230 ms |
24020 KB |
Output is correct |
91 |
Correct |
221 ms |
23640 KB |
Output is correct |
92 |
Correct |
242 ms |
23604 KB |
Output is correct |
93 |
Correct |
224 ms |
23704 KB |
Output is correct |
94 |
Correct |
210 ms |
24340 KB |
Output is correct |
95 |
Correct |
224 ms |
24248 KB |
Output is correct |
96 |
Correct |
216 ms |
23964 KB |
Output is correct |
97 |
Correct |
211 ms |
23916 KB |
Output is correct |
98 |
Correct |
202 ms |
23420 KB |
Output is correct |
99 |
Correct |
213 ms |
23448 KB |
Output is correct |
100 |
Correct |
204 ms |
23632 KB |
Output is correct |
101 |
Correct |
220 ms |
23380 KB |
Output is correct |
102 |
Correct |
206 ms |
24048 KB |
Output is correct |