답안 #795777

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795777 2023-07-27T14:46:17 Z MISM06 ZIGZAG (INOI20_zigzag) C++14
0 / 100
2000 ms 2664 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < int , pii > piii;
typedef pair < ll , ll > pll;
typedef pair < ll , pll > plll;
#define pb  push_back
#define all(x)  x.begin(), x.end()
#define sze     size()
#define F first
#define S second
#define kids    int mid = (tl + tr) >> 1, cl = v << 1, cr = v << 1 | 1;
#define wall__ cout << "________________________________________\n";

const ll N = 3e5 + 10, mod = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int rand (int l, int r) {
 
    return rng() % (r - l + 1) + l;
 
}

int n, q;
ll ar[N];

bool iss0 (int l, int r) {
    if (r - l + 1 == 1) return 1;
    int t = 0;
    for (int i = l + 1; i <= r; i++) {
        int s = -1;
        if (ar[i - 1] > ar[i]) s = 0;
        if (ar[i - 1] < ar[i]) s = 1;
        if (s != t) return 0;
        t ^= 1;
    }
}
bool iss1 (int l, int r) {
    if (r - l + 1 == 1) return 1;
    int t = 1;
    for (int i = l + 1; i <= r; i++) {
        int s = -1;
        if (ar[i - 1] > ar[i]) s = 0;
        if (ar[i - 1] < ar[i]) s = 1;
        if (s != t) return 0;
        t ^= 1;
    }
}
bool iss (int l, int r) {
    return iss0(l, r) | iss1(l, r);
}

ll calc (int l, int r) {
    ll res = 0;
    for (int i = l; i <= r; i++) {
        for (int j = i; j <= r; j++) if (iss(i, j)) ++res;
    }
    return res;
}
void mul (int l, int r) {
    for (int i = l; i <= r; i++) ar[i] *= -1ll;
}
void sum (ll x, int l, int r) {
    for (int i = l; i <= r; i++) ar[i] += x;
}

void solve () {
    cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> ar[i];
    while(q--) {
        char t; int l, r; cin >> t >> l >> r;
        if (t == '+') {
            int x; cin >> x;
            sum(x, l, r);
        } else if (t == '?') {
            cout << calc(l, r) << '\n';
        } else {
            mul(l, r);
        }
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int ts = 1; //cin >> ts;
    while(ts--) {
        solve();
    }
    return 0;
}

Compilation message

Main.cpp: In function 'bool iss0(int, int)':
Main.cpp:40:1: warning: control reaches end of non-void function [-Wreturn-type]
   40 | }
      | ^
Main.cpp: In function 'bool iss1(int, int)':
Main.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
   51 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2055 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2068 ms 2664 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2055 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2055 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -