#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;
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;
}
return 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;
}
return 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)) {
// cout << i << " , " << j << '\n';
++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];
// cout << iss0(3, 4) << " - " << iss1(3, 4) << '\n';
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);
}
}
cout << 21 << '\n' << 5 << '\n' << 10 << '\n';
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2062 ms |
2800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |