# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
205385 | 2020-02-28T18:05:56 Z | TadijaSebez | Fire (JOI20_ho_t5) | C++11 | 409 ms | 22008 KB |
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long const int N=200050; struct BIT{ ll sum[N]; void init(){for(int i=0;i<N;i++)sum[i]=0;} BIT(){init();} void Set(int i,ll f){for(i++;i<N;i+=i&-i)sum[i]+=f;} ll Get(int i){ll ans=0;for(i++;i;i-=i&-i)ans+=sum[i];return ans;} }SUM,MUL,STK; int a[N]; vector<pair<int,int>> Qs[N]; int stk[N],top; ll ans[N]; void AddD(int t,ll f){ //printf("AddD %i %lld\n",t,f); SUM.Set(t,-(ll)t*f); MUL.Set(t,f); } ll Get(int t){ //printf("t:%i mul:%lld sum:%lld\n",t,MUL.Get(t),SUM.Get(t)); return (t+1)*MUL.Get(t)+SUM.Get(t); } int main(){ int n,q; scanf("%i %i",&n,&q); for(int i=1;i<=n;i++)scanf("%i",&a[i]); for(int i=1,t,l,r;i<=q;i++)scanf("%i %i %i",&t,&l,&r),Qs[r].pb({i,t}),Qs[l-1].pb({-i,t}); for(int i=1;i<=n;i++){ while(top && a[stk[top]]<=a[i]){ AddD(i-stk[top],-a[stk[top]]); if(top>1)AddD(i-stk[top-1],a[stk[top]]); if(top>1)STK.Set(top,-(ll)(stk[top]-stk[top-1])*a[stk[top]]); top--; } AddD(0,a[i]); if(top>0)AddD(i-stk[top],-a[i]); stk[++top]=i; if(top>1)STK.Set(top,(ll)(stk[top]-stk[top-1])*a[stk[top]]); for(auto Q:Qs[i]){ int t=Q.second; ll now=Get(t); //printf("Get: %lld ",now); int hi=top,lo=1,mid,pos=top; while(hi>=lo){ mid=hi+lo>>1; if(i-stk[mid]<=t)pos=mid,hi=mid-1; else lo=mid+1; } now-=STK.Get(top)-STK.Get(pos); //printf("%lld ",now); now-=(ll)a[stk[pos]]*(t-(i-stk[pos])); int id=abs(Q.first); //printf("i:%i t:%i now:%lld\n",i,t,now); if(Q.first<0)ans[id]-=now; else ans[id]+=now; } } for(int i=1;i<=q;i++)printf("%lld\n",ans[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9720 KB | Output is correct |
2 | Correct | 10 ms | 9720 KB | Output is correct |
3 | Correct | 10 ms | 9720 KB | Output is correct |
4 | Correct | 11 ms | 9720 KB | Output is correct |
5 | Correct | 10 ms | 9724 KB | Output is correct |
6 | Correct | 12 ms | 9720 KB | Output is correct |
7 | Correct | 11 ms | 9720 KB | Output is correct |
8 | Correct | 10 ms | 9720 KB | Output is correct |
9 | Correct | 10 ms | 9720 KB | Output is correct |
10 | Correct | 10 ms | 9720 KB | Output is correct |
11 | Correct | 11 ms | 9720 KB | Output is correct |
12 | Correct | 10 ms | 9720 KB | Output is correct |
13 | Correct | 10 ms | 9720 KB | Output is correct |
14 | Correct | 10 ms | 9720 KB | Output is correct |
15 | Correct | 11 ms | 9720 KB | Output is correct |
16 | Correct | 11 ms | 9720 KB | Output is correct |
17 | Correct | 11 ms | 9724 KB | Output is correct |
18 | Correct | 10 ms | 9720 KB | Output is correct |
19 | Correct | 10 ms | 9720 KB | Output is correct |
20 | Correct | 10 ms | 9720 KB | Output is correct |
21 | Correct | 11 ms | 9724 KB | Output is correct |
22 | Correct | 10 ms | 9720 KB | Output is correct |
23 | Correct | 12 ms | 9720 KB | Output is correct |
24 | Correct | 12 ms | 9720 KB | Output is correct |
25 | Correct | 10 ms | 9720 KB | Output is correct |
26 | Correct | 11 ms | 9848 KB | Output is correct |
27 | Correct | 10 ms | 9720 KB | Output is correct |
28 | Correct | 10 ms | 9720 KB | Output is correct |
29 | Correct | 10 ms | 9720 KB | Output is correct |
30 | Correct | 12 ms | 9848 KB | Output is correct |
31 | Correct | 11 ms | 9720 KB | Output is correct |
32 | Correct | 10 ms | 9720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9720 KB | Output is correct |
2 | Correct | 327 ms | 21624 KB | Output is correct |
3 | Correct | 371 ms | 21752 KB | Output is correct |
4 | Correct | 331 ms | 21780 KB | Output is correct |
5 | Correct | 346 ms | 21496 KB | Output is correct |
6 | Correct | 344 ms | 21368 KB | Output is correct |
7 | Correct | 339 ms | 21884 KB | Output is correct |
8 | Correct | 348 ms | 21624 KB | Output is correct |
9 | Correct | 345 ms | 21816 KB | Output is correct |
10 | Correct | 352 ms | 21624 KB | Output is correct |
11 | Correct | 330 ms | 21752 KB | Output is correct |
12 | Correct | 326 ms | 21368 KB | Output is correct |
13 | Correct | 341 ms | 21496 KB | Output is correct |
14 | Correct | 317 ms | 21368 KB | Output is correct |
15 | Correct | 331 ms | 21544 KB | Output is correct |
16 | Correct | 353 ms | 21592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9720 KB | Output is correct |
2 | Correct | 337 ms | 21184 KB | Output is correct |
3 | Correct | 354 ms | 20728 KB | Output is correct |
4 | Correct | 353 ms | 21112 KB | Output is correct |
5 | Correct | 339 ms | 20728 KB | Output is correct |
6 | Correct | 373 ms | 20728 KB | Output is correct |
7 | Correct | 364 ms | 20856 KB | Output is correct |
8 | Correct | 356 ms | 21088 KB | Output is correct |
9 | Correct | 372 ms | 20988 KB | Output is correct |
10 | Correct | 339 ms | 20728 KB | Output is correct |
11 | Correct | 376 ms | 20984 KB | Output is correct |
12 | Correct | 347 ms | 20728 KB | Output is correct |
13 | Correct | 342 ms | 20984 KB | Output is correct |
14 | Correct | 356 ms | 20856 KB | Output is correct |
15 | Correct | 356 ms | 20860 KB | Output is correct |
16 | Correct | 354 ms | 20600 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 337 ms | 19768 KB | Output is correct |
2 | Correct | 331 ms | 19832 KB | Output is correct |
3 | Correct | 338 ms | 19936 KB | Output is correct |
4 | Correct | 320 ms | 19960 KB | Output is correct |
5 | Correct | 314 ms | 19960 KB | Output is correct |
6 | Correct | 302 ms | 19768 KB | Output is correct |
7 | Correct | 315 ms | 19960 KB | Output is correct |
8 | Correct | 299 ms | 19960 KB | Output is correct |
9 | Correct | 341 ms | 20088 KB | Output is correct |
10 | Correct | 346 ms | 19704 KB | Output is correct |
11 | Correct | 335 ms | 20088 KB | Output is correct |
12 | Correct | 331 ms | 20088 KB | Output is correct |
13 | Correct | 317 ms | 19960 KB | Output is correct |
14 | Correct | 316 ms | 20088 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9720 KB | Output is correct |
2 | Correct | 10 ms | 9720 KB | Output is correct |
3 | Correct | 10 ms | 9720 KB | Output is correct |
4 | Correct | 11 ms | 9720 KB | Output is correct |
5 | Correct | 10 ms | 9724 KB | Output is correct |
6 | Correct | 12 ms | 9720 KB | Output is correct |
7 | Correct | 11 ms | 9720 KB | Output is correct |
8 | Correct | 10 ms | 9720 KB | Output is correct |
9 | Correct | 10 ms | 9720 KB | Output is correct |
10 | Correct | 10 ms | 9720 KB | Output is correct |
11 | Correct | 11 ms | 9720 KB | Output is correct |
12 | Correct | 10 ms | 9720 KB | Output is correct |
13 | Correct | 10 ms | 9720 KB | Output is correct |
14 | Correct | 10 ms | 9720 KB | Output is correct |
15 | Correct | 11 ms | 9720 KB | Output is correct |
16 | Correct | 11 ms | 9720 KB | Output is correct |
17 | Correct | 11 ms | 9724 KB | Output is correct |
18 | Correct | 10 ms | 9720 KB | Output is correct |
19 | Correct | 10 ms | 9720 KB | Output is correct |
20 | Correct | 10 ms | 9720 KB | Output is correct |
21 | Correct | 11 ms | 9724 KB | Output is correct |
22 | Correct | 10 ms | 9720 KB | Output is correct |
23 | Correct | 12 ms | 9720 KB | Output is correct |
24 | Correct | 12 ms | 9720 KB | Output is correct |
25 | Correct | 10 ms | 9720 KB | Output is correct |
26 | Correct | 11 ms | 9848 KB | Output is correct |
27 | Correct | 10 ms | 9720 KB | Output is correct |
28 | Correct | 10 ms | 9720 KB | Output is correct |
29 | Correct | 10 ms | 9720 KB | Output is correct |
30 | Correct | 12 ms | 9848 KB | Output is correct |
31 | Correct | 11 ms | 9720 KB | Output is correct |
32 | Correct | 10 ms | 9720 KB | Output is correct |
33 | Correct | 403 ms | 21708 KB | Output is correct |
34 | Correct | 409 ms | 22008 KB | Output is correct |
35 | Correct | 377 ms | 21496 KB | Output is correct |
36 | Correct | 354 ms | 21764 KB | Output is correct |
37 | Correct | 360 ms | 21444 KB | Output is correct |
38 | Correct | 368 ms | 21576 KB | Output is correct |
39 | Correct | 357 ms | 21500 KB | Output is correct |
40 | Correct | 358 ms | 21812 KB | Output is correct |
41 | Correct | 359 ms | 21496 KB | Output is correct |
42 | Correct | 389 ms | 21624 KB | Output is correct |
43 | Correct | 339 ms | 21752 KB | Output is correct |
44 | Correct | 373 ms | 21496 KB | Output is correct |
45 | Correct | 367 ms | 21524 KB | Output is correct |
46 | Correct | 348 ms | 21476 KB | Output is correct |
47 | Correct | 321 ms | 21368 KB | Output is correct |
48 | Correct | 330 ms | 21368 KB | Output is correct |
49 | Correct | 334 ms | 21500 KB | Output is correct |
50 | Correct | 337 ms | 21880 KB | Output is correct |
51 | Correct | 342 ms | 21780 KB | Output is correct |
52 | Correct | 344 ms | 21624 KB | Output is correct |
53 | Correct | 341 ms | 21624 KB | Output is correct |
54 | Correct | 323 ms | 21372 KB | Output is correct |
55 | Correct | 330 ms | 21368 KB | Output is correct |
56 | Correct | 338 ms | 21624 KB | Output is correct |
57 | Correct | 337 ms | 21484 KB | Output is correct |
58 | Correct | 338 ms | 21752 KB | Output is correct |
59 | Correct | 327 ms | 21624 KB | Output is correct |
60 | Correct | 371 ms | 21752 KB | Output is correct |
61 | Correct | 331 ms | 21780 KB | Output is correct |
62 | Correct | 346 ms | 21496 KB | Output is correct |
63 | Correct | 344 ms | 21368 KB | Output is correct |
64 | Correct | 339 ms | 21884 KB | Output is correct |
65 | Correct | 348 ms | 21624 KB | Output is correct |
66 | Correct | 345 ms | 21816 KB | Output is correct |
67 | Correct | 352 ms | 21624 KB | Output is correct |
68 | Correct | 330 ms | 21752 KB | Output is correct |
69 | Correct | 326 ms | 21368 KB | Output is correct |
70 | Correct | 341 ms | 21496 KB | Output is correct |
71 | Correct | 317 ms | 21368 KB | Output is correct |
72 | Correct | 331 ms | 21544 KB | Output is correct |
73 | Correct | 353 ms | 21592 KB | Output is correct |
74 | Correct | 337 ms | 21184 KB | Output is correct |
75 | Correct | 354 ms | 20728 KB | Output is correct |
76 | Correct | 353 ms | 21112 KB | Output is correct |
77 | Correct | 339 ms | 20728 KB | Output is correct |
78 | Correct | 373 ms | 20728 KB | Output is correct |
79 | Correct | 364 ms | 20856 KB | Output is correct |
80 | Correct | 356 ms | 21088 KB | Output is correct |
81 | Correct | 372 ms | 20988 KB | Output is correct |
82 | Correct | 339 ms | 20728 KB | Output is correct |
83 | Correct | 376 ms | 20984 KB | Output is correct |
84 | Correct | 347 ms | 20728 KB | Output is correct |
85 | Correct | 342 ms | 20984 KB | Output is correct |
86 | Correct | 356 ms | 20856 KB | Output is correct |
87 | Correct | 356 ms | 20860 KB | Output is correct |
88 | Correct | 354 ms | 20600 KB | Output is correct |
89 | Correct | 337 ms | 19768 KB | Output is correct |
90 | Correct | 331 ms | 19832 KB | Output is correct |
91 | Correct | 338 ms | 19936 KB | Output is correct |
92 | Correct | 320 ms | 19960 KB | Output is correct |
93 | Correct | 314 ms | 19960 KB | Output is correct |
94 | Correct | 302 ms | 19768 KB | Output is correct |
95 | Correct | 315 ms | 19960 KB | Output is correct |
96 | Correct | 299 ms | 19960 KB | Output is correct |
97 | Correct | 341 ms | 20088 KB | Output is correct |
98 | Correct | 346 ms | 19704 KB | Output is correct |
99 | Correct | 335 ms | 20088 KB | Output is correct |
100 | Correct | 331 ms | 20088 KB | Output is correct |
101 | Correct | 317 ms | 19960 KB | Output is correct |
102 | Correct | 316 ms | 20088 KB | Output is correct |