Submission #992119

# Submission time Handle Problem Language Result Execution time Memory
992119 2024-06-04T00:50:31 Z saddd ZIGZAG (INOI20_zigzag) C++17
8 / 100
2000 ms 5500 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
//#pragma GCC optimize("O3")
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
ll mod = 998244353, pr = 69;
const int mxn = 3e5 + 5, mxq = 1e5 + 5, sq = 1005, mxv = 5e4 + 1, lg = 60;
//const int base = (1 <<18);
const ll inf = 2e9 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, q;
ll a[mxn + 1], d[mxn + 1];
int sign(ll x){
    if(x < 0)return(0);
    if(x > 0)return(1);
    return(2);
}
int rev(int x){
    if(x == 0)return(1);
    if(x == 1)return(0);
    return(-1);
}
void solve(){  
    cin >> n >> q;
    for(int i = 1; i <= n; i++)cin >> a[i];
    for(int i = 1; i < n; i++){
        d[i] = a[i + 1] - a[i];
    }
    while(q--){
        char idq; cin >> idq;
        if(idq == '*'){
            int l, r; cin >> l >> r;
            for(int i = l; i <= r; i++)a[i] *= -1;
        }else if(idq == '+'){
            int l, r; ll v; cin >> l >> r >> v;
            for(int i = l; i <= r; i++)a[i] += v;
        }else{
            int l, r; cin >> l >> r; 
            ll ans = 0;
            for(int i = l; i < r;){
                if(sign(d[i]) == 2){
                    i++; continue;
                }
                int rp = i + 1;
                while(rp < r && sign(d[rp - 1]) == rev(sign(d[rp]))){
                    rp++;
                }
                ans += 1LL * (rp - i) * (rp - i + 1) / 2; 
                i = rp;
            }
            cout << ans + r - l + 1 << "\n";
        }
        
        for(int i = 1; i < n; i++){
            d[i] = a[i + 1] - a[i];
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("TESTROOMS.inp", "r", stdin);
    //freopen("TESTROOMS.out", "w", stdout);
    int tt; tt = 1;
    while(tt--){
        solve();
 
    }
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2396 KB Output is correct
2 Correct 18 ms 2396 KB Output is correct
3 Correct 21 ms 2396 KB Output is correct
4 Correct 21 ms 2652 KB Output is correct
5 Correct 19 ms 2636 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 35 ms 2676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2027 ms 5140 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2396 KB Output is correct
2 Correct 18 ms 2396 KB Output is correct
3 Correct 21 ms 2396 KB Output is correct
4 Correct 21 ms 2652 KB Output is correct
5 Correct 19 ms 2636 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 35 ms 2676 KB Output is correct
8 Execution timed out 2052 ms 5500 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2396 KB Output is correct
2 Correct 18 ms 2396 KB Output is correct
3 Correct 21 ms 2396 KB Output is correct
4 Correct 21 ms 2652 KB Output is correct
5 Correct 19 ms 2636 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 35 ms 2676 KB Output is correct
8 Execution timed out 2027 ms 5140 KB Time limit exceeded
9 Halted 0 ms 0 KB -