#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << H;
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
#define F first
#define S second
const int maxn = 3e5 + 10;
int n, q, dp[maxn];
ll a[maxn];
vector<ll> num;
ll solve(){
ll ans = 1;
dp[0] = 1;
for (int i = 1; i < num.size(); i++){
dp[i] = 1;
if (num[i] != num[i-1]) dp[i] = 2;
if (i > 1 && ((num[i] > num[i-1] && num[i-2] > num[i-1]) || (num[i] < num[i-1] && num[i-2] < num[i-1]))) dp[i] = dp[i-1] + 1;
ans += dp[i];
}
return ans;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; i++) cin >> a[i];
while(q--){
char t; int l, r; cin >> t >> l >> r;
if (t == '*'){
for (int i = l; i <= r; i++) a[i] = -a[i];
}
if (t == '+'){
int x; cin >> x;
for (int i = l; i <= r; i++) a[i] += x;
}
if (t == '?'){
num.clear();
for (int i = l; i <= r; i++) num.push_back(a[i]);
cout << solve() << '\n';
}
}
return 0;
}
Compilation message
Main.cpp: In function 'll solve()':
Main.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 1; i < num.size(); i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
500 KB |
Output is correct |
2 |
Correct |
19 ms |
628 KB |
Output is correct |
3 |
Correct |
24 ms |
464 KB |
Output is correct |
4 |
Correct |
22 ms |
596 KB |
Output is correct |
5 |
Correct |
21 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
63 ms |
608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2088 ms |
6856 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
500 KB |
Output is correct |
2 |
Correct |
19 ms |
628 KB |
Output is correct |
3 |
Correct |
24 ms |
464 KB |
Output is correct |
4 |
Correct |
22 ms |
596 KB |
Output is correct |
5 |
Correct |
21 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
63 ms |
608 KB |
Output is correct |
8 |
Execution timed out |
2084 ms |
3296 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
500 KB |
Output is correct |
2 |
Correct |
19 ms |
628 KB |
Output is correct |
3 |
Correct |
24 ms |
464 KB |
Output is correct |
4 |
Correct |
22 ms |
596 KB |
Output is correct |
5 |
Correct |
21 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
63 ms |
608 KB |
Output is correct |
8 |
Execution timed out |
2088 ms |
6856 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |