Submission #634282

#TimeUsernameProblemLanguageResultExecution timeMemory
634282MahdiZIGZAG (INOI20_zigzag)C++17
0 / 100
2074 ms48512 KiB
#include<bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() #define F first #define S second typedef long long ll; typedef pair<int, int> pii; const int N=5e3+5; int n, q, a[N], b[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>q; for(int i=1;i<=n;++i) cin>>a[i]; for(int i=1;i<n;++i){ b[i]=a[i+1]-a[i]; if(b[i]>0) b[i]=1; else if(b[i]<0) b[i]=-1; } while(q--){ char c; int l, r; cin>>c>>l>>r; if(c=='*'){ for(int i=l;i<=r;++i) a[i]=-a[i]; } else if(c=='+'){ int v; cin>>v; for(int i=l;i<=r;++i) a[i]+=v; } else{ for(int i=l;i<r;++i){ b[i]=a[i+1]-a[i]; if(b[i]>0) b[i]=1; else if(b[i]<0) b[i]=-1; } int ans=0, h=1, z=0; for(int i=l;i<r;++i){ if(b[i]==0){ ans+=h*(h+1)/2; h=1; z=0; } else{ if(z!=b[i]) ++h; else{ ans+=h*(h+1); h=2; } } } ans+=h*(h+1)/2; cout<<ans<<'\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...