# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1024621 |
2024-07-16T08:42:19 Z |
manizare |
Fire (JOI20_ho_t5) |
C++14 |
|
224 ms |
118600 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define ld long double
#define int long long
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= b;i++)
#define per(i, a , b) for(int i=a;i >= b;i--)
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 6e5 + 10 , sq = 550, inf = 1e18+10 , mod = 10007 , lg = 20 ;
int a[maxn] , n , q ;
struct fen{
int f1[maxn] , f2[maxn] ;
void upd(int id ,int x ,int y ){
id += n+1 ;
while(id <= 2*n+q+1){
f1[id] += x*y ;
f2[id] += y ;
id += id&-id;
}
}
int que(int x ,int w){
int s1 =0 , s2 =0 ;
x += n+1 ;
while(x){
s1 += f1[x] ;
s2 += f2[x] ;
x -= x&-x ;
}
return s2*w - s1 ;
}
int bz(int l , int r , int x){
return (que(r, x) - que(l-1 , x)) ;
}
};
fen f1 , f2 , f3 ;
int d1[maxn] , d2[maxn] , ans[maxn] ;
vector <int> u1[maxn];
vector <pii> up[maxn] ;
vector <pair<pii,int> > q1[maxn] ;
void add(int x , int w ,int t){
up[t].pb({x,w}) ;
}
void c1(){
vector <int> vec ;
rep(i ,1 ,n){
while(sz(vec) && a[vec.back()] <= a[i])vec.pop_back() ;
if(sz(vec) == 0)d1[i] = 0 ;
else d1[i] = vec.back() ;
vec.pb(i) ;
}
vec.clear() ;
per(i , n , 1){
while(sz(vec) && a[vec.back()] < a[i])vec.pop_back() ;
if(sz(vec) == 0)d2[i] = n+1 ;
else d2[i] = vec.back() ;
vec.pb(i) ;
}
rep(i ,1 ,n)u1[d1[i]].pb(i) ;
rep(i ,1 ,n){
vector <pii> f;
f.pb({i,a[i]}) ;
for(int x : u1[i]){
f.pb({x , a[i]-a[x]}) ;
}
f.pb({d2[i] , 0}) ;
rep(j , 0, sz(f)-2){
int ti = f[j].F - i ;
add(f[j].F, f[j].S , ti);
add(f[j+1].F , -f[j].S , ti+f[j+1].F-f[j].F) ;
}
}
}
void upd(int x ,int w , int ti){
if(x==n+1)return ;
f1.upd(x , ti , w) ;
f2.upd(ti-x+1 , ti-x+1 ,w) ;
f3.upd(x , ti-x+1 , w) ;
}
int sl(int x , int ti){
int ans = 0 ;
ans += f1.bz(1 , x , ti);
ans -= f2.bz(-n , ti-x , ti-x) ;
ans += f3.bz(x+1 , n , ti-x) ;
return ans ;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
rep(i , 1, n){
cin >> a[i] ;
}
c1() ;
rep(i ,1 ,q){
int l, r , ti ;
cin >> ti >> l >> r ;
q1[ti].pb({{l,r} , i}) ;
}
rep(i , 0, n){
for(auto [x,w] : up[i]){
upd(x , w , i-1) ;
}
for(auto [b,j] : q1[i]){
ans[j] += sl(b.S,i) ;
ans[j] -= sl(b.F-1 ,i) ;
}
}
rep(i ,1 , q){
cout << ans[i] << "\n" ;
}
}
/*
*/
Compilation message
ho_t5.cpp: In function 'int main()':
ho_t5.cpp:113:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
113 | for(auto [x,w] : up[i]){
| ^
ho_t5.cpp:116:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
116 | for(auto [b,j] : q1[i]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
62040 KB |
Output is correct |
2 |
Correct |
8 ms |
62044 KB |
Output is correct |
3 |
Correct |
8 ms |
62236 KB |
Output is correct |
4 |
Correct |
8 ms |
62044 KB |
Output is correct |
5 |
Correct |
8 ms |
62044 KB |
Output is correct |
6 |
Correct |
8 ms |
62044 KB |
Output is correct |
7 |
Correct |
8 ms |
62044 KB |
Output is correct |
8 |
Correct |
8 ms |
62044 KB |
Output is correct |
9 |
Correct |
9 ms |
62044 KB |
Output is correct |
10 |
Correct |
8 ms |
62132 KB |
Output is correct |
11 |
Correct |
8 ms |
62044 KB |
Output is correct |
12 |
Correct |
10 ms |
62300 KB |
Output is correct |
13 |
Correct |
9 ms |
62128 KB |
Output is correct |
14 |
Correct |
8 ms |
62180 KB |
Output is correct |
15 |
Correct |
8 ms |
62044 KB |
Output is correct |
16 |
Correct |
8 ms |
62040 KB |
Output is correct |
17 |
Correct |
9 ms |
62044 KB |
Output is correct |
18 |
Correct |
8 ms |
62184 KB |
Output is correct |
19 |
Correct |
9 ms |
62044 KB |
Output is correct |
20 |
Correct |
8 ms |
62244 KB |
Output is correct |
21 |
Correct |
8 ms |
62044 KB |
Output is correct |
22 |
Correct |
8 ms |
62120 KB |
Output is correct |
23 |
Correct |
9 ms |
62152 KB |
Output is correct |
24 |
Correct |
8 ms |
62044 KB |
Output is correct |
25 |
Correct |
8 ms |
62144 KB |
Output is correct |
26 |
Correct |
8 ms |
62044 KB |
Output is correct |
27 |
Correct |
8 ms |
62244 KB |
Output is correct |
28 |
Correct |
9 ms |
62236 KB |
Output is correct |
29 |
Correct |
8 ms |
62044 KB |
Output is correct |
30 |
Correct |
8 ms |
62112 KB |
Output is correct |
31 |
Correct |
8 ms |
62044 KB |
Output is correct |
32 |
Correct |
8 ms |
62044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
62040 KB |
Output is correct |
2 |
Correct |
171 ms |
117500 KB |
Output is correct |
3 |
Correct |
167 ms |
116196 KB |
Output is correct |
4 |
Correct |
173 ms |
118020 KB |
Output is correct |
5 |
Correct |
165 ms |
117168 KB |
Output is correct |
6 |
Correct |
175 ms |
117580 KB |
Output is correct |
7 |
Correct |
177 ms |
117580 KB |
Output is correct |
8 |
Correct |
165 ms |
118068 KB |
Output is correct |
9 |
Correct |
180 ms |
118552 KB |
Output is correct |
10 |
Correct |
168 ms |
116932 KB |
Output is correct |
11 |
Correct |
169 ms |
117508 KB |
Output is correct |
12 |
Correct |
169 ms |
117296 KB |
Output is correct |
13 |
Correct |
163 ms |
116492 KB |
Output is correct |
14 |
Correct |
171 ms |
118600 KB |
Output is correct |
15 |
Correct |
165 ms |
116796 KB |
Output is correct |
16 |
Correct |
171 ms |
116500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
62040 KB |
Output is correct |
2 |
Correct |
202 ms |
109956 KB |
Output is correct |
3 |
Correct |
185 ms |
111572 KB |
Output is correct |
4 |
Correct |
224 ms |
111068 KB |
Output is correct |
5 |
Correct |
186 ms |
111620 KB |
Output is correct |
6 |
Correct |
196 ms |
109820 KB |
Output is correct |
7 |
Correct |
193 ms |
111744 KB |
Output is correct |
8 |
Correct |
212 ms |
111364 KB |
Output is correct |
9 |
Correct |
191 ms |
110512 KB |
Output is correct |
10 |
Correct |
193 ms |
109712 KB |
Output is correct |
11 |
Correct |
183 ms |
110964 KB |
Output is correct |
12 |
Correct |
180 ms |
111260 KB |
Output is correct |
13 |
Correct |
192 ms |
110748 KB |
Output is correct |
14 |
Correct |
196 ms |
111120 KB |
Output is correct |
15 |
Correct |
189 ms |
112020 KB |
Output is correct |
16 |
Correct |
194 ms |
111640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
103180 KB |
Output is correct |
2 |
Correct |
179 ms |
102264 KB |
Output is correct |
3 |
Correct |
170 ms |
103700 KB |
Output is correct |
4 |
Correct |
180 ms |
103560 KB |
Output is correct |
5 |
Correct |
184 ms |
103012 KB |
Output is correct |
6 |
Correct |
210 ms |
103424 KB |
Output is correct |
7 |
Correct |
165 ms |
103492 KB |
Output is correct |
8 |
Correct |
183 ms |
103400 KB |
Output is correct |
9 |
Correct |
193 ms |
103184 KB |
Output is correct |
10 |
Correct |
188 ms |
104456 KB |
Output is correct |
11 |
Correct |
171 ms |
103312 KB |
Output is correct |
12 |
Correct |
176 ms |
103344 KB |
Output is correct |
13 |
Correct |
182 ms |
103468 KB |
Output is correct |
14 |
Correct |
174 ms |
102932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
62040 KB |
Output is correct |
2 |
Correct |
8 ms |
62044 KB |
Output is correct |
3 |
Correct |
8 ms |
62236 KB |
Output is correct |
4 |
Correct |
8 ms |
62044 KB |
Output is correct |
5 |
Correct |
8 ms |
62044 KB |
Output is correct |
6 |
Correct |
8 ms |
62044 KB |
Output is correct |
7 |
Correct |
8 ms |
62044 KB |
Output is correct |
8 |
Correct |
8 ms |
62044 KB |
Output is correct |
9 |
Correct |
9 ms |
62044 KB |
Output is correct |
10 |
Correct |
8 ms |
62132 KB |
Output is correct |
11 |
Correct |
8 ms |
62044 KB |
Output is correct |
12 |
Correct |
10 ms |
62300 KB |
Output is correct |
13 |
Correct |
9 ms |
62128 KB |
Output is correct |
14 |
Correct |
8 ms |
62180 KB |
Output is correct |
15 |
Correct |
8 ms |
62044 KB |
Output is correct |
16 |
Correct |
8 ms |
62040 KB |
Output is correct |
17 |
Correct |
9 ms |
62044 KB |
Output is correct |
18 |
Correct |
8 ms |
62184 KB |
Output is correct |
19 |
Correct |
9 ms |
62044 KB |
Output is correct |
20 |
Correct |
8 ms |
62244 KB |
Output is correct |
21 |
Correct |
8 ms |
62044 KB |
Output is correct |
22 |
Correct |
8 ms |
62120 KB |
Output is correct |
23 |
Correct |
9 ms |
62152 KB |
Output is correct |
24 |
Correct |
8 ms |
62044 KB |
Output is correct |
25 |
Correct |
8 ms |
62144 KB |
Output is correct |
26 |
Correct |
8 ms |
62044 KB |
Output is correct |
27 |
Correct |
8 ms |
62244 KB |
Output is correct |
28 |
Correct |
9 ms |
62236 KB |
Output is correct |
29 |
Correct |
8 ms |
62044 KB |
Output is correct |
30 |
Correct |
8 ms |
62112 KB |
Output is correct |
31 |
Correct |
8 ms |
62044 KB |
Output is correct |
32 |
Correct |
8 ms |
62044 KB |
Output is correct |
33 |
Correct |
171 ms |
117500 KB |
Output is correct |
34 |
Correct |
167 ms |
116196 KB |
Output is correct |
35 |
Correct |
173 ms |
118020 KB |
Output is correct |
36 |
Correct |
165 ms |
117168 KB |
Output is correct |
37 |
Correct |
175 ms |
117580 KB |
Output is correct |
38 |
Correct |
177 ms |
117580 KB |
Output is correct |
39 |
Correct |
165 ms |
118068 KB |
Output is correct |
40 |
Correct |
180 ms |
118552 KB |
Output is correct |
41 |
Correct |
168 ms |
116932 KB |
Output is correct |
42 |
Correct |
169 ms |
117508 KB |
Output is correct |
43 |
Correct |
169 ms |
117296 KB |
Output is correct |
44 |
Correct |
163 ms |
116492 KB |
Output is correct |
45 |
Correct |
171 ms |
118600 KB |
Output is correct |
46 |
Correct |
165 ms |
116796 KB |
Output is correct |
47 |
Correct |
171 ms |
116500 KB |
Output is correct |
48 |
Correct |
202 ms |
109956 KB |
Output is correct |
49 |
Correct |
185 ms |
111572 KB |
Output is correct |
50 |
Correct |
224 ms |
111068 KB |
Output is correct |
51 |
Correct |
186 ms |
111620 KB |
Output is correct |
52 |
Correct |
196 ms |
109820 KB |
Output is correct |
53 |
Correct |
193 ms |
111744 KB |
Output is correct |
54 |
Correct |
212 ms |
111364 KB |
Output is correct |
55 |
Correct |
191 ms |
110512 KB |
Output is correct |
56 |
Correct |
193 ms |
109712 KB |
Output is correct |
57 |
Correct |
183 ms |
110964 KB |
Output is correct |
58 |
Correct |
180 ms |
111260 KB |
Output is correct |
59 |
Correct |
192 ms |
110748 KB |
Output is correct |
60 |
Correct |
196 ms |
111120 KB |
Output is correct |
61 |
Correct |
189 ms |
112020 KB |
Output is correct |
62 |
Correct |
194 ms |
111640 KB |
Output is correct |
63 |
Correct |
193 ms |
103180 KB |
Output is correct |
64 |
Correct |
179 ms |
102264 KB |
Output is correct |
65 |
Correct |
170 ms |
103700 KB |
Output is correct |
66 |
Correct |
180 ms |
103560 KB |
Output is correct |
67 |
Correct |
184 ms |
103012 KB |
Output is correct |
68 |
Correct |
210 ms |
103424 KB |
Output is correct |
69 |
Correct |
165 ms |
103492 KB |
Output is correct |
70 |
Correct |
183 ms |
103400 KB |
Output is correct |
71 |
Correct |
193 ms |
103184 KB |
Output is correct |
72 |
Correct |
188 ms |
104456 KB |
Output is correct |
73 |
Correct |
171 ms |
103312 KB |
Output is correct |
74 |
Correct |
176 ms |
103344 KB |
Output is correct |
75 |
Correct |
182 ms |
103468 KB |
Output is correct |
76 |
Correct |
174 ms |
102932 KB |
Output is correct |
77 |
Correct |
217 ms |
112392 KB |
Output is correct |
78 |
Correct |
195 ms |
113172 KB |
Output is correct |
79 |
Correct |
179 ms |
112524 KB |
Output is correct |
80 |
Correct |
209 ms |
111528 KB |
Output is correct |
81 |
Correct |
193 ms |
111884 KB |
Output is correct |
82 |
Correct |
220 ms |
110864 KB |
Output is correct |
83 |
Correct |
206 ms |
112388 KB |
Output is correct |
84 |
Correct |
203 ms |
111240 KB |
Output is correct |
85 |
Correct |
203 ms |
112184 KB |
Output is correct |
86 |
Correct |
205 ms |
112484 KB |
Output is correct |
87 |
Correct |
180 ms |
113280 KB |
Output is correct |
88 |
Correct |
179 ms |
112456 KB |
Output is correct |
89 |
Correct |
187 ms |
112068 KB |
Output is correct |
90 |
Correct |
185 ms |
112436 KB |
Output is correct |
91 |
Correct |
187 ms |
111888 KB |
Output is correct |
92 |
Correct |
182 ms |
111660 KB |
Output is correct |
93 |
Correct |
187 ms |
113688 KB |
Output is correct |
94 |
Correct |
197 ms |
113552 KB |
Output is correct |
95 |
Correct |
200 ms |
113196 KB |
Output is correct |
96 |
Correct |
184 ms |
113540 KB |
Output is correct |
97 |
Correct |
187 ms |
113892 KB |
Output is correct |
98 |
Correct |
210 ms |
111380 KB |
Output is correct |
99 |
Correct |
188 ms |
112392 KB |
Output is correct |
100 |
Correct |
206 ms |
112896 KB |
Output is correct |
101 |
Correct |
192 ms |
112264 KB |
Output is correct |
102 |
Correct |
196 ms |
114456 KB |
Output is correct |