Submission #634327

#TimeUsernameProblemLanguageResultExecution timeMemory
634327MahdiZIGZAG (INOI20_zigzag)C++17
8 / 100
2080 ms72444 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; ll 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=r-l+1, h=1, z=0; for(int i=l;i<r;++i){ if(b[i]==0){ ans+=h*(h-1)/2; h=1; } else{ if(z!=b[i]) ++h; else{ ans+=h*(h-1)/2; h=2; } } z=b[i]; } 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...