# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
349886 |
2021-01-18T15:43:41 Z |
YJU |
Fire (JOI20_ho_t5) |
C++14 |
|
963 ms |
93752 KB |
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=(1LL<<20);
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
struct Segment_Tree{
ll sum[4*N],tag[4*N];
void push(ll id,ll l,ll r){
if(tag[id]){
ll mid=(l+r)>>1;
sum[id*2]+=(mid-l)*tag[id];
sum[id*2+1]+=(r-mid)*tag[id];
tag[id*2]+=tag[id];
tag[id*2+1]+=tag[id];
tag[id]=0;
}
}
void add(ll id,ll l,ll r,ll ql,ll qr,ll val){
if(l>=qr||r<=ql)return ;
if(l>=ql&&r<=qr){tag[id]+=val;sum[id]+=val*(r-l);return;}
push(id,l,r);
ll mid=(l+r)>>1;
add(id*2,l,mid,ql,qr,val);
add(id*2+1,mid,r,ql,qr,val);
sum[id]=sum[id*2]+sum[id*2+1];
}
ll ask(ll id,ll l,ll r,ll ql,ll qr){
if(l>=qr||r<=ql)return 0;
if(l>=ql&&r<=qr)return sum[id];
push(id,l,r);
ll mid=(l+r)>>1;
return ask(id*2,l,mid,ql,qr)+ask(id*2+1,mid,r,ql,qr);
}
}seg1,seg2;
ll n,q,a[N],sz=0,stk[N],L[N],R[N],ans[N];
vector<pair<ll,pll> > query[N];
vector<pair<pll,ll> > work[N];
ll Q(ll t,ll r){
return seg1.ask(1,0,N,1,r-t+1+N/2)+seg2.ask(1,0,N,1,r+1+N/2);
}
void update(ll ql,ll qr,ll val){
seg1.add(1,0,N,ql+N/2,N,val);
seg2.add(1,0,N,qr+1+N/2,N,-val);
}
void build(ll ql,ll qr,ll val){
if(ql>qr)return ;
work[0].pb(mp(mp(ql,qr),val));
work[qr-ql+1].pb(mp(mp(ql,qr),-val));
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>q;
REP1(i,n){
cin>>a[i];
while(sz&&a[stk[sz]]<=a[i]){
L[i]=stk[sz];
R[stk[sz]]=i;
--sz;
}
L[i]=(a[L[i]]==a[i]?L[i]:(sz==0?i-n:stk[sz]));
R[i]=n+1;
stk[++sz]=i;
}
REP1(i,q){
ll t,x,y;
cin>>t>>x>>y;
query[t].pb(mp(i,mp(x,y)));
}
REP1(i,n){
build(L[i]+1,i-1,-a[i]);
build(i+1,R[i]-1,-a[i]);
build(L[i]+1,R[i]-1,a[i]);
}
REP(i,n+1){
//cout<<i<<"\n";
for(auto k:work[i]){
//cout<<k.X.X<<" "<<k.X.Y<<" "<<k.Y<<"\n";
update(k.X.X,k.X.Y,k.Y);
}
for(auto k:query[i]){
ans[k.X]=Q(i,k.Y.Y)-Q(i,k.Y.X-1);
}
}
REP1(i,q)cout<<ans[i]<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
49900 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
49900 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
49900 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
963 ms |
93752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
49900 KB |
Output isn't correct |