Submission #634282

# Submission time Handle Problem Language Result Execution time Memory
634282 2022-08-24T08:29:43 Z Mahdi ZIGZAG (INOI20_zigzag) C++17
0 / 100
2000 ms 48512 KB
#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 time Memory Grader output
1 Incorrect 13 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2074 ms 48512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -