#include<iostream>
#include<vector>
#define int long long
using namespace std;
int t[800000];
int lewo[800000];
int prawo[800000];
pair<int,int> drzewo[4000000][2];
int pot=1;
int wynik[800000];
vector<pair<int,pair<int,int> > > zapp[800000];
vector<pair<int,int> > zmiana[800000];
void add(int x,int l,int r,int a,int b,int co,int gdzie)
{
if(b<l || a>r)
return;
//cout<<"jestem w "<<x<<"\n";
if(a<=l && r<=b)
{
drzewo[x][gdzie].second+=co;
return;
}
int mid=(l+r)/2;
add(x*2,l,mid,a,b,co,gdzie);
add(x*2+1,mid+1,r,a,b,co,gdzie);
drzewo[x][gdzie].first=drzewo[x*2][gdzie].first+drzewo[x*2][gdzie].second*(mid-l+1)+drzewo[x*2+1][gdzie].first+drzewo[x*2+1][gdzie].second*(r-mid);
}
int zap(int x,int l,int r,int a,int b,int gdzie)
{
if(a>r || b<l)
return 0;
if(a<=l && r<=b)
return drzewo[x][gdzie].first+drzewo[x][gdzie].second*(r-l+1);
int mid=(l+r)/2;
return zap(x*2,l,mid,a,b,gdzie)+zap(x*2+1,mid+1,r,a,b,gdzie)+drzewo[x][gdzie].second*(min(b,r)-max(a,l)+1);
}
void dodaj(int x,int l,int r)
{
//cout<<x<<": "<<l<<" "<<r<<"\n";
zmiana[0].push_back({x,t[x]});
zmiana[l].push_back({x,-t[x]});
zmiana[r].push_back({r+x,-t[x]});
zmiana[l+r].push_back({x+r,t[x]});
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
while(pot<=800000)
pot*=2;
pot--;
for(int i=1;i<=n;i++)
cin>>t[i];
vector<int> Q;
t[0]=1e18;
t[n+1]=1e18;
Q.push_back(0);
for(int i=1;i<=n;i++)
{
while(Q.size() && t[Q.back()]<=t[i])
Q.pop_back();
lewo[i]=Q.back();
Q.push_back(i);
}
Q.clear();
Q.push_back(n+1);
for(int i=n;i>=1;i--)
{
while(Q.size() && t[Q.back()]<t[i])
Q.pop_back();
prawo[i]=Q.back();
Q.push_back(i);
}
for(int i=1;i<=n;i++)
{
if(lewo[i]==0)
lewo[i]=n+1;
else lewo[i]=i-lewo[i];
prawo[i]-=i;
dodaj(i,lewo[i],prawo[i]);
}
for(int i=1;i<=m;i++)
{
int x,y,z;
cin>>x>>y>>z;
zapp[x].push_back({i,{y,z}});
}
int stala=400000;
for(int i=0;i<=n;i++)
{
for(int j=0;j<zmiana[i].size();j++)
{
int gdzie=zmiana[i][j].first;
int ile=zmiana[i][j].second;
add(1,pot+1,pot*2+1,gdzie+pot,pot*2+1,ile,0);
add(1,pot+1,pot*2+1,stala+pot+1+gdzie,pot*2+1,-ile,1);
}
for(int j=0;j<zapp[i].size();j++)
{
int x=zapp[i][j].first;
int l=zapp[i][j].second.first;
int r=zapp[i][j].second.second;
wynik[x]=zap(1,pot+1,pot*2+1,l+pot,r+pot,0)+zap(1,pot+1,pot*2+1,stala+l+pot,stala+r+pot,1);
}
stala--;
}
for(int i=1;i<=m;i++)
cout<<wynik[i]<<"\n";
return 0;
}
Compilation message
ho_t5.cpp: In function 'int32_t main()':
ho_t5.cpp:94:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int j=0;j<zmiana[i].size();j++)
| ~^~~~~~~~~~~~~~~~~
ho_t5.cpp:101:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(int j=0;j<zapp[i].size();j++)
| ~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
38012 KB |
Output is correct |
2 |
Correct |
21 ms |
38132 KB |
Output is correct |
3 |
Correct |
20 ms |
38136 KB |
Output is correct |
4 |
Correct |
20 ms |
38148 KB |
Output is correct |
5 |
Correct |
21 ms |
38144 KB |
Output is correct |
6 |
Correct |
22 ms |
38080 KB |
Output is correct |
7 |
Correct |
22 ms |
38100 KB |
Output is correct |
8 |
Correct |
20 ms |
38124 KB |
Output is correct |
9 |
Correct |
20 ms |
38100 KB |
Output is correct |
10 |
Correct |
20 ms |
38132 KB |
Output is correct |
11 |
Correct |
20 ms |
38076 KB |
Output is correct |
12 |
Correct |
20 ms |
38084 KB |
Output is correct |
13 |
Correct |
20 ms |
38048 KB |
Output is correct |
14 |
Correct |
20 ms |
38100 KB |
Output is correct |
15 |
Correct |
21 ms |
38148 KB |
Output is correct |
16 |
Correct |
21 ms |
38092 KB |
Output is correct |
17 |
Correct |
23 ms |
38036 KB |
Output is correct |
18 |
Correct |
22 ms |
38100 KB |
Output is correct |
19 |
Correct |
20 ms |
38096 KB |
Output is correct |
20 |
Correct |
22 ms |
38100 KB |
Output is correct |
21 |
Correct |
19 ms |
38032 KB |
Output is correct |
22 |
Correct |
19 ms |
38052 KB |
Output is correct |
23 |
Correct |
19 ms |
38072 KB |
Output is correct |
24 |
Correct |
20 ms |
38112 KB |
Output is correct |
25 |
Correct |
19 ms |
38060 KB |
Output is correct |
26 |
Correct |
23 ms |
38100 KB |
Output is correct |
27 |
Correct |
25 ms |
38028 KB |
Output is correct |
28 |
Correct |
22 ms |
38136 KB |
Output is correct |
29 |
Correct |
20 ms |
38152 KB |
Output is correct |
30 |
Correct |
25 ms |
38140 KB |
Output is correct |
31 |
Correct |
20 ms |
38100 KB |
Output is correct |
32 |
Correct |
20 ms |
38044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
38012 KB |
Output is correct |
2 |
Correct |
812 ms |
92272 KB |
Output is correct |
3 |
Correct |
779 ms |
91872 KB |
Output is correct |
4 |
Correct |
807 ms |
98008 KB |
Output is correct |
5 |
Correct |
834 ms |
98896 KB |
Output is correct |
6 |
Correct |
825 ms |
98036 KB |
Output is correct |
7 |
Correct |
814 ms |
98404 KB |
Output is correct |
8 |
Correct |
829 ms |
99316 KB |
Output is correct |
9 |
Correct |
833 ms |
98888 KB |
Output is correct |
10 |
Correct |
787 ms |
97336 KB |
Output is correct |
11 |
Correct |
825 ms |
99132 KB |
Output is correct |
12 |
Correct |
808 ms |
97216 KB |
Output is correct |
13 |
Correct |
863 ms |
98716 KB |
Output is correct |
14 |
Correct |
815 ms |
98536 KB |
Output is correct |
15 |
Correct |
851 ms |
98732 KB |
Output is correct |
16 |
Correct |
825 ms |
97836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
38012 KB |
Output is correct |
2 |
Correct |
747 ms |
90060 KB |
Output is correct |
3 |
Correct |
797 ms |
94556 KB |
Output is correct |
4 |
Correct |
791 ms |
96700 KB |
Output is correct |
5 |
Correct |
744 ms |
94968 KB |
Output is correct |
6 |
Correct |
748 ms |
95600 KB |
Output is correct |
7 |
Correct |
739 ms |
95792 KB |
Output is correct |
8 |
Correct |
798 ms |
95384 KB |
Output is correct |
9 |
Correct |
782 ms |
94756 KB |
Output is correct |
10 |
Correct |
739 ms |
94344 KB |
Output is correct |
11 |
Correct |
753 ms |
96508 KB |
Output is correct |
12 |
Correct |
770 ms |
95928 KB |
Output is correct |
13 |
Correct |
811 ms |
96268 KB |
Output is correct |
14 |
Correct |
743 ms |
94888 KB |
Output is correct |
15 |
Correct |
750 ms |
96332 KB |
Output is correct |
16 |
Correct |
798 ms |
95824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
697 ms |
88960 KB |
Output is correct |
2 |
Correct |
716 ms |
89100 KB |
Output is correct |
3 |
Correct |
773 ms |
90376 KB |
Output is correct |
4 |
Correct |
696 ms |
88860 KB |
Output is correct |
5 |
Correct |
746 ms |
88920 KB |
Output is correct |
6 |
Correct |
693 ms |
89592 KB |
Output is correct |
7 |
Correct |
748 ms |
90484 KB |
Output is correct |
8 |
Correct |
771 ms |
89732 KB |
Output is correct |
9 |
Correct |
764 ms |
89408 KB |
Output is correct |
10 |
Correct |
753 ms |
89904 KB |
Output is correct |
11 |
Correct |
781 ms |
89716 KB |
Output is correct |
12 |
Correct |
737 ms |
89876 KB |
Output is correct |
13 |
Correct |
771 ms |
89588 KB |
Output is correct |
14 |
Correct |
719 ms |
89452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
38012 KB |
Output is correct |
2 |
Correct |
21 ms |
38132 KB |
Output is correct |
3 |
Correct |
20 ms |
38136 KB |
Output is correct |
4 |
Correct |
20 ms |
38148 KB |
Output is correct |
5 |
Correct |
21 ms |
38144 KB |
Output is correct |
6 |
Correct |
22 ms |
38080 KB |
Output is correct |
7 |
Correct |
22 ms |
38100 KB |
Output is correct |
8 |
Correct |
20 ms |
38124 KB |
Output is correct |
9 |
Correct |
20 ms |
38100 KB |
Output is correct |
10 |
Correct |
20 ms |
38132 KB |
Output is correct |
11 |
Correct |
20 ms |
38076 KB |
Output is correct |
12 |
Correct |
20 ms |
38084 KB |
Output is correct |
13 |
Correct |
20 ms |
38048 KB |
Output is correct |
14 |
Correct |
20 ms |
38100 KB |
Output is correct |
15 |
Correct |
21 ms |
38148 KB |
Output is correct |
16 |
Correct |
21 ms |
38092 KB |
Output is correct |
17 |
Correct |
23 ms |
38036 KB |
Output is correct |
18 |
Correct |
22 ms |
38100 KB |
Output is correct |
19 |
Correct |
20 ms |
38096 KB |
Output is correct |
20 |
Correct |
22 ms |
38100 KB |
Output is correct |
21 |
Correct |
19 ms |
38032 KB |
Output is correct |
22 |
Correct |
19 ms |
38052 KB |
Output is correct |
23 |
Correct |
19 ms |
38072 KB |
Output is correct |
24 |
Correct |
20 ms |
38112 KB |
Output is correct |
25 |
Correct |
19 ms |
38060 KB |
Output is correct |
26 |
Correct |
23 ms |
38100 KB |
Output is correct |
27 |
Correct |
25 ms |
38028 KB |
Output is correct |
28 |
Correct |
22 ms |
38136 KB |
Output is correct |
29 |
Correct |
20 ms |
38152 KB |
Output is correct |
30 |
Correct |
25 ms |
38140 KB |
Output is correct |
31 |
Correct |
20 ms |
38100 KB |
Output is correct |
32 |
Correct |
20 ms |
38044 KB |
Output is correct |
33 |
Correct |
812 ms |
92272 KB |
Output is correct |
34 |
Correct |
779 ms |
91872 KB |
Output is correct |
35 |
Correct |
807 ms |
98008 KB |
Output is correct |
36 |
Correct |
834 ms |
98896 KB |
Output is correct |
37 |
Correct |
825 ms |
98036 KB |
Output is correct |
38 |
Correct |
814 ms |
98404 KB |
Output is correct |
39 |
Correct |
829 ms |
99316 KB |
Output is correct |
40 |
Correct |
833 ms |
98888 KB |
Output is correct |
41 |
Correct |
787 ms |
97336 KB |
Output is correct |
42 |
Correct |
825 ms |
99132 KB |
Output is correct |
43 |
Correct |
808 ms |
97216 KB |
Output is correct |
44 |
Correct |
863 ms |
98716 KB |
Output is correct |
45 |
Correct |
815 ms |
98536 KB |
Output is correct |
46 |
Correct |
851 ms |
98732 KB |
Output is correct |
47 |
Correct |
825 ms |
97836 KB |
Output is correct |
48 |
Correct |
747 ms |
90060 KB |
Output is correct |
49 |
Correct |
797 ms |
94556 KB |
Output is correct |
50 |
Correct |
791 ms |
96700 KB |
Output is correct |
51 |
Correct |
744 ms |
94968 KB |
Output is correct |
52 |
Correct |
748 ms |
95600 KB |
Output is correct |
53 |
Correct |
739 ms |
95792 KB |
Output is correct |
54 |
Correct |
798 ms |
95384 KB |
Output is correct |
55 |
Correct |
782 ms |
94756 KB |
Output is correct |
56 |
Correct |
739 ms |
94344 KB |
Output is correct |
57 |
Correct |
753 ms |
96508 KB |
Output is correct |
58 |
Correct |
770 ms |
95928 KB |
Output is correct |
59 |
Correct |
811 ms |
96268 KB |
Output is correct |
60 |
Correct |
743 ms |
94888 KB |
Output is correct |
61 |
Correct |
750 ms |
96332 KB |
Output is correct |
62 |
Correct |
798 ms |
95824 KB |
Output is correct |
63 |
Correct |
697 ms |
88960 KB |
Output is correct |
64 |
Correct |
716 ms |
89100 KB |
Output is correct |
65 |
Correct |
773 ms |
90376 KB |
Output is correct |
66 |
Correct |
696 ms |
88860 KB |
Output is correct |
67 |
Correct |
746 ms |
88920 KB |
Output is correct |
68 |
Correct |
693 ms |
89592 KB |
Output is correct |
69 |
Correct |
748 ms |
90484 KB |
Output is correct |
70 |
Correct |
771 ms |
89732 KB |
Output is correct |
71 |
Correct |
764 ms |
89408 KB |
Output is correct |
72 |
Correct |
753 ms |
89904 KB |
Output is correct |
73 |
Correct |
781 ms |
89716 KB |
Output is correct |
74 |
Correct |
737 ms |
89876 KB |
Output is correct |
75 |
Correct |
771 ms |
89588 KB |
Output is correct |
76 |
Correct |
719 ms |
89452 KB |
Output is correct |
77 |
Correct |
877 ms |
96148 KB |
Output is correct |
78 |
Correct |
909 ms |
97292 KB |
Output is correct |
79 |
Correct |
917 ms |
97224 KB |
Output is correct |
80 |
Correct |
894 ms |
96300 KB |
Output is correct |
81 |
Correct |
842 ms |
95836 KB |
Output is correct |
82 |
Correct |
929 ms |
96700 KB |
Output is correct |
83 |
Correct |
878 ms |
96648 KB |
Output is correct |
84 |
Correct |
850 ms |
95852 KB |
Output is correct |
85 |
Correct |
849 ms |
97108 KB |
Output is correct |
86 |
Correct |
880 ms |
96208 KB |
Output is correct |
87 |
Correct |
774 ms |
98464 KB |
Output is correct |
88 |
Correct |
828 ms |
98540 KB |
Output is correct |
89 |
Correct |
805 ms |
96780 KB |
Output is correct |
90 |
Correct |
787 ms |
98048 KB |
Output is correct |
91 |
Correct |
780 ms |
97180 KB |
Output is correct |
92 |
Correct |
806 ms |
96580 KB |
Output is correct |
93 |
Correct |
781 ms |
97596 KB |
Output is correct |
94 |
Correct |
816 ms |
99036 KB |
Output is correct |
95 |
Correct |
801 ms |
98692 KB |
Output is correct |
96 |
Correct |
771 ms |
97628 KB |
Output is correct |
97 |
Correct |
764 ms |
97752 KB |
Output is correct |
98 |
Correct |
798 ms |
96688 KB |
Output is correct |
99 |
Correct |
831 ms |
97572 KB |
Output is correct |
100 |
Correct |
832 ms |
97792 KB |
Output is correct |
101 |
Correct |
827 ms |
97032 KB |
Output is correct |
102 |
Correct |
822 ms |
98236 KB |
Output is correct |