Submission #634327

# Submission time Handle Problem Language Result Execution time Memory
634327 2022-08-24T09:00:06 Z Mahdi ZIGZAG (INOI20_zigzag) C++17
8 / 100
2000 ms 72444 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;
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 time Memory Grader output
1 Correct 19 ms 404 KB Output is correct
2 Correct 13 ms 412 KB Output is correct
3 Correct 22 ms 340 KB Output is correct
4 Correct 19 ms 340 KB Output is correct
5 Correct 17 ms 408 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 54 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2080 ms 72444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 404 KB Output is correct
2 Correct 13 ms 412 KB Output is correct
3 Correct 22 ms 340 KB Output is correct
4 Correct 19 ms 340 KB Output is correct
5 Correct 17 ms 408 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 54 ms 340 KB Output is correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 404 KB Output is correct
2 Correct 13 ms 412 KB Output is correct
3 Correct 22 ms 340 KB Output is correct
4 Correct 19 ms 340 KB Output is correct
5 Correct 17 ms 408 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 54 ms 340 KB Output is correct
8 Execution timed out 2080 ms 72444 KB Time limit exceeded
9 Halted 0 ms 0 KB -