Submission #532832

# Submission time Handle Problem Language Result Execution time Memory
532832 2022-03-04T03:26:44 Z amunduzbaev Fire (JOI20_ho_t5) C++17
100 / 100
380 ms 46024 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
#define int long long

const int N = 2e5 + 5;
struct ST{
	int tree[N];
	
	void add(int i, int v){
		i++;
		for(;i<N;i+=(i&-i)) tree[i] += v;
	}
	
	void add(int l, int r, int v){
		add(l, v);
		add(r + 1, -v);
	}
	
	int get(int i){
		i++;
		int r=0;
		for(;i>0;i-=(i&-i)) r += tree[i];
		return r;
	}
}tree, cnt;

int s[N], t[N], L[N], R[N];
int l[N], r[N], res[N];
vector<int> par[N], qq[N], q2[N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, q; cin>>n>>q;
	for(int i=1;i<=n;i++) cin>>s[i];
	for(int i=1;i<=q;i++){
		cin>>t[i]>>L[i]>>R[i];
		qq[R[i]].push_back(i);
		qq[L[i] - 1].push_back(-i);
	}
	
	vector<int> ss;
	for(int i=n;i>0;i--){
		while(!ss.empty() && s[ss.back()] <= s[i]) ss.pop_back();
		if(!ss.empty()) r[i] = ss.back() - 1; //, par[ss.back()].push_back(i);
		else r[i] = n;
		ss.push_back(i);
	} ss.clear();
	
	for(int i=1;i<=n;i++){
		while(!ss.empty() && s[ss.back()] < s[i]) ss.pop_back();
		if(!ss.empty()) l[i] = ss.back() + 1;
		else l[i] = 1;
		ss.push_back(i);
		for(auto j : qq[i]){
			int p = *lower_bound(ss.begin(), ss.end(), i - t[abs(j)]);
			int add = s[p] * (i - max(p, (l[p] > 1 ? l[p] + t[abs(j)] : 0)) + 1);
			if(j < 0) res[-j] -= add;
			else res[j] += add;
			q2[p - 1].push_back(j);
		}
	}
	
	for(int i=1;i<=n;i++){
		int MX = r[i] - (l[i] > 1 ? l[i] : -N + r[i]);
		tree.add(1, r[i] - i - 1, i * s[i]);
		cnt.add(1, r[i] - i - 1, s[i]);
		tree.add(r[i] - i, MX, r[i] * s[i]);
		if(l[i] > 1){
			tree.add(1, i - l[i], -i * s[i]);
			tree.add(i - l[i] + 1, MX, -l[i] * s[i]);
			cnt.add(i - l[i] + 1, MX, -s[i]);
		} else {
			tree.add(1, MX, -i * s[i]);
		} tree.add(1, MX, s[i]);
		
		for(auto j : q2[i]){
			if(j > 0){
				res[j] += (tree.get(t[j]) + cnt.get(t[j]) * t[j]);
			}
			else {
				j = -j, res[j] -= (tree.get(t[j]) + cnt.get(t[j]) * t[j]);
			}
		}
	}
	
	for(int i=1;i<=q;i++) cout<<res[i]<<"\n";
}

/*

10 1
3 1 4 1 5 9 2 6 5 3
4 2 7

*/
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14540 KB Output is correct
2 Correct 9 ms 14480 KB Output is correct
3 Correct 8 ms 14544 KB Output is correct
4 Correct 8 ms 14540 KB Output is correct
5 Correct 8 ms 14544 KB Output is correct
6 Correct 8 ms 14548 KB Output is correct
7 Correct 8 ms 14548 KB Output is correct
8 Correct 8 ms 14540 KB Output is correct
9 Correct 9 ms 14568 KB Output is correct
10 Correct 8 ms 14540 KB Output is correct
11 Correct 8 ms 14540 KB Output is correct
12 Correct 8 ms 14540 KB Output is correct
13 Correct 8 ms 14548 KB Output is correct
14 Correct 8 ms 14540 KB Output is correct
15 Correct 8 ms 14540 KB Output is correct
16 Correct 8 ms 14548 KB Output is correct
17 Correct 8 ms 14540 KB Output is correct
18 Correct 9 ms 14556 KB Output is correct
19 Correct 10 ms 14544 KB Output is correct
20 Correct 10 ms 14540 KB Output is correct
21 Correct 9 ms 14512 KB Output is correct
22 Correct 8 ms 14508 KB Output is correct
23 Correct 9 ms 14460 KB Output is correct
24 Correct 8 ms 14496 KB Output is correct
25 Correct 8 ms 14540 KB Output is correct
26 Correct 8 ms 14540 KB Output is correct
27 Correct 8 ms 14536 KB Output is correct
28 Correct 8 ms 14540 KB Output is correct
29 Correct 8 ms 14548 KB Output is correct
30 Correct 8 ms 14544 KB Output is correct
31 Correct 8 ms 14540 KB Output is correct
32 Correct 8 ms 14544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14540 KB Output is correct
2 Correct 289 ms 43788 KB Output is correct
3 Correct 290 ms 43884 KB Output is correct
4 Correct 289 ms 44924 KB Output is correct
5 Correct 283 ms 44524 KB Output is correct
6 Correct 276 ms 44168 KB Output is correct
7 Correct 282 ms 45176 KB Output is correct
8 Correct 291 ms 44540 KB Output is correct
9 Correct 287 ms 45028 KB Output is correct
10 Correct 286 ms 43992 KB Output is correct
11 Correct 290 ms 44204 KB Output is correct
12 Correct 278 ms 43468 KB Output is correct
13 Correct 280 ms 44044 KB Output is correct
14 Correct 286 ms 43996 KB Output is correct
15 Correct 287 ms 44400 KB Output is correct
16 Correct 268 ms 44500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14540 KB Output is correct
2 Correct 278 ms 43792 KB Output is correct
3 Correct 271 ms 43200 KB Output is correct
4 Correct 277 ms 43964 KB Output is correct
5 Correct 269 ms 43252 KB Output is correct
6 Correct 274 ms 43832 KB Output is correct
7 Correct 269 ms 43460 KB Output is correct
8 Correct 284 ms 43620 KB Output is correct
9 Correct 275 ms 43412 KB Output is correct
10 Correct 279 ms 43312 KB Output is correct
11 Correct 276 ms 43540 KB Output is correct
12 Correct 284 ms 43036 KB Output is correct
13 Correct 274 ms 43864 KB Output is correct
14 Correct 271 ms 43468 KB Output is correct
15 Correct 268 ms 43232 KB Output is correct
16 Correct 274 ms 42996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 355 ms 41324 KB Output is correct
2 Correct 377 ms 45264 KB Output is correct
3 Correct 376 ms 46024 KB Output is correct
4 Correct 368 ms 45748 KB Output is correct
5 Correct 355 ms 45712 KB Output is correct
6 Correct 352 ms 45216 KB Output is correct
7 Correct 362 ms 45656 KB Output is correct
8 Correct 380 ms 45744 KB Output is correct
9 Correct 371 ms 45592 KB Output is correct
10 Correct 368 ms 45612 KB Output is correct
11 Correct 376 ms 46004 KB Output is correct
12 Correct 377 ms 45836 KB Output is correct
13 Correct 351 ms 45660 KB Output is correct
14 Correct 377 ms 45820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14540 KB Output is correct
2 Correct 9 ms 14480 KB Output is correct
3 Correct 8 ms 14544 KB Output is correct
4 Correct 8 ms 14540 KB Output is correct
5 Correct 8 ms 14544 KB Output is correct
6 Correct 8 ms 14548 KB Output is correct
7 Correct 8 ms 14548 KB Output is correct
8 Correct 8 ms 14540 KB Output is correct
9 Correct 9 ms 14568 KB Output is correct
10 Correct 8 ms 14540 KB Output is correct
11 Correct 8 ms 14540 KB Output is correct
12 Correct 8 ms 14540 KB Output is correct
13 Correct 8 ms 14548 KB Output is correct
14 Correct 8 ms 14540 KB Output is correct
15 Correct 8 ms 14540 KB Output is correct
16 Correct 8 ms 14548 KB Output is correct
17 Correct 8 ms 14540 KB Output is correct
18 Correct 9 ms 14556 KB Output is correct
19 Correct 10 ms 14544 KB Output is correct
20 Correct 10 ms 14540 KB Output is correct
21 Correct 9 ms 14512 KB Output is correct
22 Correct 8 ms 14508 KB Output is correct
23 Correct 9 ms 14460 KB Output is correct
24 Correct 8 ms 14496 KB Output is correct
25 Correct 8 ms 14540 KB Output is correct
26 Correct 8 ms 14540 KB Output is correct
27 Correct 8 ms 14536 KB Output is correct
28 Correct 8 ms 14540 KB Output is correct
29 Correct 8 ms 14548 KB Output is correct
30 Correct 8 ms 14544 KB Output is correct
31 Correct 8 ms 14540 KB Output is correct
32 Correct 8 ms 14544 KB Output is correct
33 Correct 289 ms 43788 KB Output is correct
34 Correct 290 ms 43884 KB Output is correct
35 Correct 289 ms 44924 KB Output is correct
36 Correct 283 ms 44524 KB Output is correct
37 Correct 276 ms 44168 KB Output is correct
38 Correct 282 ms 45176 KB Output is correct
39 Correct 291 ms 44540 KB Output is correct
40 Correct 287 ms 45028 KB Output is correct
41 Correct 286 ms 43992 KB Output is correct
42 Correct 290 ms 44204 KB Output is correct
43 Correct 278 ms 43468 KB Output is correct
44 Correct 280 ms 44044 KB Output is correct
45 Correct 286 ms 43996 KB Output is correct
46 Correct 287 ms 44400 KB Output is correct
47 Correct 268 ms 44500 KB Output is correct
48 Correct 278 ms 43792 KB Output is correct
49 Correct 271 ms 43200 KB Output is correct
50 Correct 277 ms 43964 KB Output is correct
51 Correct 269 ms 43252 KB Output is correct
52 Correct 274 ms 43832 KB Output is correct
53 Correct 269 ms 43460 KB Output is correct
54 Correct 284 ms 43620 KB Output is correct
55 Correct 275 ms 43412 KB Output is correct
56 Correct 279 ms 43312 KB Output is correct
57 Correct 276 ms 43540 KB Output is correct
58 Correct 284 ms 43036 KB Output is correct
59 Correct 274 ms 43864 KB Output is correct
60 Correct 271 ms 43468 KB Output is correct
61 Correct 268 ms 43232 KB Output is correct
62 Correct 274 ms 42996 KB Output is correct
63 Correct 355 ms 41324 KB Output is correct
64 Correct 377 ms 45264 KB Output is correct
65 Correct 376 ms 46024 KB Output is correct
66 Correct 368 ms 45748 KB Output is correct
67 Correct 355 ms 45712 KB Output is correct
68 Correct 352 ms 45216 KB Output is correct
69 Correct 362 ms 45656 KB Output is correct
70 Correct 380 ms 45744 KB Output is correct
71 Correct 371 ms 45592 KB Output is correct
72 Correct 368 ms 45612 KB Output is correct
73 Correct 376 ms 46004 KB Output is correct
74 Correct 377 ms 45836 KB Output is correct
75 Correct 351 ms 45660 KB Output is correct
76 Correct 377 ms 45820 KB Output is correct
77 Correct 288 ms 43620 KB Output is correct
78 Correct 301 ms 43584 KB Output is correct
79 Correct 290 ms 43220 KB Output is correct
80 Correct 340 ms 43284 KB Output is correct
81 Correct 301 ms 43328 KB Output is correct
82 Correct 287 ms 43436 KB Output is correct
83 Correct 291 ms 42520 KB Output is correct
84 Correct 294 ms 42544 KB Output is correct
85 Correct 283 ms 42676 KB Output is correct
86 Correct 295 ms 43124 KB Output is correct
87 Correct 289 ms 42556 KB Output is correct
88 Correct 285 ms 43124 KB Output is correct
89 Correct 294 ms 43904 KB Output is correct
90 Correct 288 ms 42140 KB Output is correct
91 Correct 281 ms 41668 KB Output is correct
92 Correct 281 ms 41584 KB Output is correct
93 Correct 284 ms 41888 KB Output is correct
94 Correct 290 ms 43776 KB Output is correct
95 Correct 293 ms 41940 KB Output is correct
96 Correct 285 ms 41932 KB Output is correct
97 Correct 296 ms 41836 KB Output is correct
98 Correct 277 ms 41512 KB Output is correct
99 Correct 298 ms 41316 KB Output is correct
100 Correct 297 ms 41676 KB Output is correct
101 Correct 297 ms 41496 KB Output is correct
102 Correct 312 ms 41848 KB Output is correct