#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define int long long
///#define ll long long
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void phongbeo();
const int mod2=998244353;
const int mod1=998244353;
struct icd
{
int a,b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c, d,e,f;
};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int i,s10,s12;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
///fin(task),fou(task);
#endif
NHP
/// cin>>s1;
/// modwwe
phongbeo();
}
vector<ic> v[400005];
vector<ic> v2[400005];
vector<ic> v3[400005];
int ans[200001];
int a[200001];
int b[200001];
int c[200001];
int o;
struct IT
{
int t[2000001],lazy[2000001],sz[2000001];
void ff(int x)
{
for(int i=x*2;i<=x*2+1;i++)
t[i]+=lazy[x]*sz[i],
lazy[i]+=lazy[x];
lazy[x]=0;
}
void build(int node,int l,int r)
{ sz[node]=r-l+1;
if(l==r){return;}
int mid=l+r>>1;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
}
void update(int node,int l,int r,int l1,int r1,int f)
{
if(l>r1||r<l1) return ;
if(l>=l1&&r<=r1)
{
t[node]+=f*sz[node];
lazy[node]+=f;
return;
}
ff(node);
int mid=l+r>>1;
update(node<<1,l,mid,l1,r1,f);
update(node<<1|1,mid+1,r,l1,r1,f);
t[node]=t[node<<1]+t[node<<1|1];
}
int gett(int node,int l,int r,int l1,int r1)
{
if(l>r1||r<l1) return 0;
if(l>=l1&&r<=r1) return t[node];
ff(node);
int mid=l+r>>1;
return gett(node<<1,l,mid,l1,r1)+gett(node<<1|1,mid+1,r,l1,r1);
}
void upd(int l,int r,int f)
{
l+=o;
r+=o;
update(1,0,o+o,l,r,f);
}
int get(int l,int r)
{
l+=o;
r+=o;
return gett(1,0,o+o,l,r);
}
}st1,st2;
void cf(int x,int y,int z)
{
v2[0].pb({-o,y,a[y]});
v3[0].pb({-o,y-1,-a[y]});
s2=y-1-x;
v2[s2].pb({-o,x,-a[y]});
v3[s2].pb({-o,y-1,a[y]});
s3=z-1-y;
v2[s3].pb({-o,y,-a[y]});
v3[s3].pb({-o,z-1,a[y]});
s4=z-1-x;
v2[s4].pb({-o,x,a[y]});
v3[s4].pb({-o,z-1,-a[y]});
}
void phongbeo()
{
cin>>n>>m;
o=n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=m;i++)
{
cin>>s2>>s3>>s4;
v[s2].pb({s3,s4,i});
}
vector<int> stk;
for(int i=n;i>=1;i--) {
while(!stk.empty() && a[stk.back()]<=a[i]) stk.pop_back();
if(stk.size()) {
c[i]=stk.back();
} else {
c[i]=n+1;
}
stk.push_back(i);
}
stk.clear();
for(int i=1;i<=n;i++) {
while(!stk.empty() && a[stk.back()]<a[i]) stk.pop_back();
if(stk.size()) {
b[i]=stk.back();
} else {
b[i]=-o;
}
stk.push_back(i);
}
for(int i=1;i<=n;i++)
{ //cout<<b[i]<<" "<<i<<" "<<c[i],down
cf(b[i],i,c[i]);
}
st1.build(1,0,o+o);
st2.build(1,0,o+o);
for(int i=0;i<=n;i++)
{
for(auto x:v2[i]){
st1.upd(x.a,x.b,x.c);
}
for(auto x:v3[i]){
st2.upd(x.a,x.b,x.c);
}
for(auto x:v[i])
ans[x.c]=st1.get(x.a-i,x.b-i)+st2.get(x.a,x.b);
}
for(int i=1;i<=m;i++)
{
cout<<ans[i],down
}
}
Compilation message
ho_t5.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main()
| ^~~~
ho_t5.cpp: In member function 'void IT::build(long long int, long long int, long long int)':
ho_t5.cpp:76:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
76 | int mid=l+r>>1;
| ~^~
ho_t5.cpp: In member function 'void IT::update(long long int, long long int, long long int, long long int, long long int, long long int)':
ho_t5.cpp:90:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
90 | int mid=l+r>>1;
| ~^~
ho_t5.cpp: In member function 'long long int IT::gett(long long int, long long int, long long int, long long int, long long int)':
ho_t5.cpp:100:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
100 | int mid=l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
42332 KB |
Output is correct |
2 |
Correct |
13 ms |
40576 KB |
Output is correct |
3 |
Correct |
10 ms |
40536 KB |
Output is correct |
4 |
Correct |
13 ms |
40572 KB |
Output is correct |
5 |
Correct |
9 ms |
40540 KB |
Output is correct |
6 |
Correct |
9 ms |
40540 KB |
Output is correct |
7 |
Correct |
9 ms |
40540 KB |
Output is correct |
8 |
Correct |
10 ms |
40444 KB |
Output is correct |
9 |
Correct |
9 ms |
40540 KB |
Output is correct |
10 |
Correct |
10 ms |
40540 KB |
Output is correct |
11 |
Correct |
12 ms |
40540 KB |
Output is correct |
12 |
Correct |
10 ms |
40540 KB |
Output is correct |
13 |
Correct |
9 ms |
40540 KB |
Output is correct |
14 |
Correct |
10 ms |
40540 KB |
Output is correct |
15 |
Correct |
11 ms |
40376 KB |
Output is correct |
16 |
Correct |
13 ms |
40372 KB |
Output is correct |
17 |
Correct |
9 ms |
40540 KB |
Output is correct |
18 |
Correct |
13 ms |
40384 KB |
Output is correct |
19 |
Correct |
9 ms |
40540 KB |
Output is correct |
20 |
Correct |
9 ms |
40396 KB |
Output is correct |
21 |
Correct |
9 ms |
40536 KB |
Output is correct |
22 |
Correct |
10 ms |
40576 KB |
Output is correct |
23 |
Correct |
10 ms |
40540 KB |
Output is correct |
24 |
Correct |
12 ms |
40540 KB |
Output is correct |
25 |
Correct |
10 ms |
40540 KB |
Output is correct |
26 |
Correct |
10 ms |
40540 KB |
Output is correct |
27 |
Correct |
10 ms |
40376 KB |
Output is correct |
28 |
Correct |
9 ms |
40540 KB |
Output is correct |
29 |
Correct |
10 ms |
40536 KB |
Output is correct |
30 |
Correct |
10 ms |
40536 KB |
Output is correct |
31 |
Correct |
10 ms |
40536 KB |
Output is correct |
32 |
Correct |
10 ms |
40540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
42332 KB |
Output is correct |
2 |
Correct |
474 ms |
138664 KB |
Output is correct |
3 |
Correct |
430 ms |
144552 KB |
Output is correct |
4 |
Correct |
476 ms |
142392 KB |
Output is correct |
5 |
Correct |
430 ms |
149296 KB |
Output is correct |
6 |
Correct |
415 ms |
141736 KB |
Output is correct |
7 |
Correct |
469 ms |
145104 KB |
Output is correct |
8 |
Correct |
410 ms |
155788 KB |
Output is correct |
9 |
Correct |
467 ms |
150456 KB |
Output is correct |
10 |
Correct |
464 ms |
144808 KB |
Output is correct |
11 |
Correct |
491 ms |
151300 KB |
Output is correct |
12 |
Correct |
474 ms |
144808 KB |
Output is correct |
13 |
Correct |
431 ms |
155564 KB |
Output is correct |
14 |
Correct |
429 ms |
157100 KB |
Output is correct |
15 |
Correct |
425 ms |
150700 KB |
Output is correct |
16 |
Correct |
451 ms |
143272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
42332 KB |
Output is correct |
2 |
Correct |
448 ms |
139660 KB |
Output is correct |
3 |
Correct |
390 ms |
144524 KB |
Output is correct |
4 |
Correct |
399 ms |
152712 KB |
Output is correct |
5 |
Correct |
432 ms |
142216 KB |
Output is correct |
6 |
Correct |
424 ms |
142808 KB |
Output is correct |
7 |
Correct |
402 ms |
150916 KB |
Output is correct |
8 |
Correct |
406 ms |
146312 KB |
Output is correct |
9 |
Correct |
395 ms |
145292 KB |
Output is correct |
10 |
Correct |
400 ms |
144524 KB |
Output is correct |
11 |
Correct |
400 ms |
153836 KB |
Output is correct |
12 |
Correct |
379 ms |
154000 KB |
Output is correct |
13 |
Correct |
426 ms |
154760 KB |
Output is correct |
14 |
Correct |
390 ms |
144780 KB |
Output is correct |
15 |
Correct |
406 ms |
152512 KB |
Output is correct |
16 |
Correct |
417 ms |
150916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
457 ms |
140704 KB |
Output is correct |
2 |
Correct |
502 ms |
142896 KB |
Output is correct |
3 |
Correct |
512 ms |
146008 KB |
Output is correct |
4 |
Correct |
462 ms |
143224 KB |
Output is correct |
5 |
Correct |
507 ms |
144828 KB |
Output is correct |
6 |
Correct |
494 ms |
144356 KB |
Output is correct |
7 |
Correct |
514 ms |
145968 KB |
Output is correct |
8 |
Correct |
502 ms |
145812 KB |
Output is correct |
9 |
Correct |
536 ms |
141836 KB |
Output is correct |
10 |
Correct |
480 ms |
143488 KB |
Output is correct |
11 |
Correct |
510 ms |
142764 KB |
Output is correct |
12 |
Correct |
527 ms |
144492 KB |
Output is correct |
13 |
Correct |
511 ms |
142636 KB |
Output is correct |
14 |
Correct |
559 ms |
144076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
42332 KB |
Output is correct |
2 |
Correct |
13 ms |
40576 KB |
Output is correct |
3 |
Correct |
10 ms |
40536 KB |
Output is correct |
4 |
Correct |
13 ms |
40572 KB |
Output is correct |
5 |
Correct |
9 ms |
40540 KB |
Output is correct |
6 |
Correct |
9 ms |
40540 KB |
Output is correct |
7 |
Correct |
9 ms |
40540 KB |
Output is correct |
8 |
Correct |
10 ms |
40444 KB |
Output is correct |
9 |
Correct |
9 ms |
40540 KB |
Output is correct |
10 |
Correct |
10 ms |
40540 KB |
Output is correct |
11 |
Correct |
12 ms |
40540 KB |
Output is correct |
12 |
Correct |
10 ms |
40540 KB |
Output is correct |
13 |
Correct |
9 ms |
40540 KB |
Output is correct |
14 |
Correct |
10 ms |
40540 KB |
Output is correct |
15 |
Correct |
11 ms |
40376 KB |
Output is correct |
16 |
Correct |
13 ms |
40372 KB |
Output is correct |
17 |
Correct |
9 ms |
40540 KB |
Output is correct |
18 |
Correct |
13 ms |
40384 KB |
Output is correct |
19 |
Correct |
9 ms |
40540 KB |
Output is correct |
20 |
Correct |
9 ms |
40396 KB |
Output is correct |
21 |
Correct |
9 ms |
40536 KB |
Output is correct |
22 |
Correct |
10 ms |
40576 KB |
Output is correct |
23 |
Correct |
10 ms |
40540 KB |
Output is correct |
24 |
Correct |
12 ms |
40540 KB |
Output is correct |
25 |
Correct |
10 ms |
40540 KB |
Output is correct |
26 |
Correct |
10 ms |
40540 KB |
Output is correct |
27 |
Correct |
10 ms |
40376 KB |
Output is correct |
28 |
Correct |
9 ms |
40540 KB |
Output is correct |
29 |
Correct |
10 ms |
40536 KB |
Output is correct |
30 |
Correct |
10 ms |
40536 KB |
Output is correct |
31 |
Correct |
10 ms |
40536 KB |
Output is correct |
32 |
Correct |
10 ms |
40540 KB |
Output is correct |
33 |
Correct |
474 ms |
138664 KB |
Output is correct |
34 |
Correct |
430 ms |
144552 KB |
Output is correct |
35 |
Correct |
476 ms |
142392 KB |
Output is correct |
36 |
Correct |
430 ms |
149296 KB |
Output is correct |
37 |
Correct |
415 ms |
141736 KB |
Output is correct |
38 |
Correct |
469 ms |
145104 KB |
Output is correct |
39 |
Correct |
410 ms |
155788 KB |
Output is correct |
40 |
Correct |
467 ms |
150456 KB |
Output is correct |
41 |
Correct |
464 ms |
144808 KB |
Output is correct |
42 |
Correct |
491 ms |
151300 KB |
Output is correct |
43 |
Correct |
474 ms |
144808 KB |
Output is correct |
44 |
Correct |
431 ms |
155564 KB |
Output is correct |
45 |
Correct |
429 ms |
157100 KB |
Output is correct |
46 |
Correct |
425 ms |
150700 KB |
Output is correct |
47 |
Correct |
451 ms |
143272 KB |
Output is correct |
48 |
Correct |
448 ms |
139660 KB |
Output is correct |
49 |
Correct |
390 ms |
144524 KB |
Output is correct |
50 |
Correct |
399 ms |
152712 KB |
Output is correct |
51 |
Correct |
432 ms |
142216 KB |
Output is correct |
52 |
Correct |
424 ms |
142808 KB |
Output is correct |
53 |
Correct |
402 ms |
150916 KB |
Output is correct |
54 |
Correct |
406 ms |
146312 KB |
Output is correct |
55 |
Correct |
395 ms |
145292 KB |
Output is correct |
56 |
Correct |
400 ms |
144524 KB |
Output is correct |
57 |
Correct |
400 ms |
153836 KB |
Output is correct |
58 |
Correct |
379 ms |
154000 KB |
Output is correct |
59 |
Correct |
426 ms |
154760 KB |
Output is correct |
60 |
Correct |
390 ms |
144780 KB |
Output is correct |
61 |
Correct |
406 ms |
152512 KB |
Output is correct |
62 |
Correct |
417 ms |
150916 KB |
Output is correct |
63 |
Correct |
457 ms |
140704 KB |
Output is correct |
64 |
Correct |
502 ms |
142896 KB |
Output is correct |
65 |
Correct |
512 ms |
146008 KB |
Output is correct |
66 |
Correct |
462 ms |
143224 KB |
Output is correct |
67 |
Correct |
507 ms |
144828 KB |
Output is correct |
68 |
Correct |
494 ms |
144356 KB |
Output is correct |
69 |
Correct |
514 ms |
145968 KB |
Output is correct |
70 |
Correct |
502 ms |
145812 KB |
Output is correct |
71 |
Correct |
536 ms |
141836 KB |
Output is correct |
72 |
Correct |
480 ms |
143488 KB |
Output is correct |
73 |
Correct |
510 ms |
142764 KB |
Output is correct |
74 |
Correct |
527 ms |
144492 KB |
Output is correct |
75 |
Correct |
511 ms |
142636 KB |
Output is correct |
76 |
Correct |
559 ms |
144076 KB |
Output is correct |
77 |
Correct |
506 ms |
146412 KB |
Output is correct |
78 |
Correct |
502 ms |
146488 KB |
Output is correct |
79 |
Correct |
525 ms |
152708 KB |
Output is correct |
80 |
Correct |
495 ms |
144428 KB |
Output is correct |
81 |
Correct |
505 ms |
146924 KB |
Output is correct |
82 |
Correct |
492 ms |
149964 KB |
Output is correct |
83 |
Correct |
480 ms |
145028 KB |
Output is correct |
84 |
Correct |
457 ms |
144052 KB |
Output is correct |
85 |
Correct |
459 ms |
151800 KB |
Output is correct |
86 |
Correct |
443 ms |
143752 KB |
Output is correct |
87 |
Correct |
428 ms |
153756 KB |
Output is correct |
88 |
Correct |
445 ms |
155488 KB |
Output is correct |
89 |
Correct |
421 ms |
147300 KB |
Output is correct |
90 |
Correct |
435 ms |
156484 KB |
Output is correct |
91 |
Correct |
422 ms |
145796 KB |
Output is correct |
92 |
Correct |
400 ms |
146036 KB |
Output is correct |
93 |
Correct |
404 ms |
146828 KB |
Output is correct |
94 |
Correct |
415 ms |
154244 KB |
Output is correct |
95 |
Correct |
426 ms |
155524 KB |
Output is correct |
96 |
Correct |
434 ms |
145440 KB |
Output is correct |
97 |
Correct |
425 ms |
147592 KB |
Output is correct |
98 |
Correct |
413 ms |
141964 KB |
Output is correct |
99 |
Correct |
405 ms |
146564 KB |
Output is correct |
100 |
Correct |
447 ms |
148972 KB |
Output is correct |
101 |
Correct |
410 ms |
142468 KB |
Output is correct |
102 |
Correct |
420 ms |
154240 KB |
Output is correct |